sleep.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "includes.h"
  2. //进入低功耗会死机,暂时使用以下操作模拟。20mA~30mA左右
  3. unsigned char g_bRTCAlarm=0;
  4. #if 0
  5. void Sleeping(void)
  6. {
  7. SlwTrace(INF, "Sleeping",1);
  8. MODEM_LED1_LOW;
  9. MODEM_LED2_LOW;
  10. KEYBOARD_BACKLIGHT_LOW;
  11. SpeakerDisable();
  12. MicDisable();
  13. LCD_BL_LOW;
  14. MODEM_RESET_HIGH;
  15. MODEM_PWRKEY_LOW;
  16. GPS_PWREN_LOW;
  17. IWDG_Configuration(3000);
  18. RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, DISABLE);
  19. RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 | RCC_APB1Periph_USART3, DISABLE);
  20. ADC_Cmd (ADC1,DISABLE);//使能或者失能指定的ADC
  21. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, DISABLE);
  22. os_tsk_delete(idModemUartTask);
  23. os_tsk_delete(idModemTask);
  24. ADCInit();//ADC Init
  25. while(1)
  26. {
  27. Vbat=GetVbat();
  28. if(Vbat>375){
  29. while(1);
  30. }
  31. os_dly_wait(1000);
  32. IWDG_ReloadCounter();
  33. }
  34. }
  35. #else
  36. void Sleeping(void)
  37. {
  38. SlwTrace(INF, "Sleeping",1);
  39. KEYBOARD_BACKLIGHT_LOW;
  40. SpeakerDisable();MicDisable();
  41. LCD_BL_LOW;
  42. MODEM_RESET_HIGH;
  43. MODEM_PWRKEY_LOW;
  44. GPS_PWREN_LOW;
  45. MODEM_LED1_HIGH;
  46. MODEM_LED2_LOW;
  47. OnOff_Init2();
  48. IWDG_Configuration(3000);//////////////
  49. SetLedStatus(NotBright);
  50. PWR_EN_LOW;
  51. ENTERSTOPMODE:
  52. //设置闹铃时间
  53. dev_rtc_setAlarm(10);
  54. // 进入停机模式
  55. printf("time go go step1\r\n");
  56. MODEM_LED1_LOW;//均不亮 HIGH
  57. EXTI_ClearITPendingBit(EXTI_Line17); // 清//EXTI_Line9 |
  58. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //使能PWR外设时钟
  59. PWR_WakeUpPinCmd(ENABLE); //使能唤醒管脚功能
  60. if((GPIO_ReadInputDataBit(CHARGEChek_PORT,CHARGEChek_PIN)==SET))
  61. {
  62. CHARGE_IC_LOW; //之后需要改LOW //开始充电
  63. }else {
  64. // CHARGE_IC_HIGH;
  65. }
  66. PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
  67. // RTC时间到达
  68. if(dev_rtc_isAlarm())
  69. {
  70. IWDG_ReloadCounter();
  71. SystemInit();
  72. ADCInit();
  73. ADC_Cmd (ADC1,ENABLE);
  74. DelayMs(1000);
  75. printf("Vbat====%d\r\n",GetOneceVbat());
  76. // if(GetOneceVbat()>53){
  77. // printf("Wake Up\r\n");
  78. // while(1);
  79. // }
  80. goto ENTERSTOPMODE;
  81. SlwTrace(INF,"time coming333\r\n",1);
  82. }
  83. }
  84. #endif
  85. void SleepMethod2()
  86. {
  87. SlwTrace(INF, "Sleeping",1);
  88. KEYBOARD_BACKLIGHT_LOW;
  89. SpeakerDisable();MicDisable();
  90. LCD_BL_LOW;
  91. MODEM_RESET_HIGH;
  92. MODEM_PWRKEY_LOW;
  93. GPS_PWREN_LOW;
  94. MODEM_LED1_HIGH;
  95. MODEM_LED2_LOW;
  96. PWR_EN_LOW;
  97. if((GPIO_ReadInputDataBit(CHARGEChek_PORT,CHARGEChek_PIN)==SET))
  98. {
  99. CHARGE_IC_LOW; //之后需要改LOW //开始充电
  100. }else {
  101. // CHARGE_IC_HIGH;
  102. }
  103. PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
  104. }
  105. void dev_rtc_setAlarm(int AlarmValue)
  106. {
  107. RTC_ITConfig(RTC_IT_ALR, ENABLE);
  108. /* Clear the RTC SEC flag */
  109. RTC_ClearFlag(RTC_FLAG_SEC);
  110. /* Wait clear RTC flag sccess */
  111. while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);
  112. /* Wait until last write operation on RTC registers has finished */
  113. RTC_WaitForLastTask();
  114. /* Sets the RTC alarm value */
  115. RTC_SetAlarm(RTC_GetCounter() + AlarmValue);
  116. /* Wait until last write operation on RTC registers has finished */
  117. RTC_WaitForLastTask();
  118. }
  119. unsigned char dev_rtc_isAlarm(void)
  120. {
  121. if(g_bRTCAlarm)
  122. {
  123. /* Clear the RTC alarm flag */
  124. g_bRTCAlarm = 0;
  125. return 1;
  126. }
  127. return 0;
  128. }