sleep.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "includes.h"
  2. //进入低功耗会死机,暂时使用以下操作模拟。20mA~30mA左右
  3. //unsigned char g_bRTCAlarm=0;
  4. #if 1
  5. void Sleeping(void)
  6. {
  7. SlwTrace(INF, "Sleeping",1);
  8. // KEYBOARD_BACKLIGHT_LOW;
  9. // SpeakerDisable();MicDisable();
  10. // LCD_BL_LOW;
  11. // MODEM_RESET_HIGH;
  12. // MODEM_PWRKEY_LOW;
  13. // GPS_PWREN_LOW;
  14. // MODEM_LED1_HIGH;
  15. // MODEM_LED2_LOW;
  16. // PWR_EN_LOW;
  17. PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
  18. }
  19. #else
  20. void Sleeping(void)
  21. {
  22. SlwTrace(INF, "Sleeping",1);
  23. KEYBOARD_BACKLIGHT_LOW;
  24. SpeakerDisable();MicDisable();
  25. LCD_BL_LOW;
  26. MODEM_RESET_HIGH;
  27. MODEM_PWRKEY_LOW;
  28. GPS_PWREN_LOW;
  29. IWDG_Configuration(3000);
  30. ENTERSTOPMODE:
  31. //设置闹铃时间
  32. dev_rtc_setAlarm(15);
  33. // 进入停机模式
  34. printf("time go go step1\r\n");
  35. EXTI_ClearITPendingBit(EXTI_Line17); // 清//EXTI_Line9 |
  36. //printf("Vbat==========%d\r\n",GetOneceVbat());
  37. ADC_Cmd (ADC1,DISABLE);
  38. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //使能PWR外设时钟
  39. PWR_WakeUpPinCmd(ENABLE); //使能唤醒管脚功能
  40. PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
  41. // RTC时间到达
  42. if(dev_rtc_isAlarm())
  43. {
  44. IWDG_ReloadCounter();
  45. SystemInit();
  46. ADCInit();
  47. ADC_Cmd (ADC1,ENABLE);
  48. if(GetOneceVbat()>77){ // 77--345V 由于从停机模式醒来,测试ADC不准 只能打印知晓值。
  49. printf("Wake Up\r\n");
  50. while(1);
  51. }
  52. goto ENTERSTOPMODE;
  53. }
  54. }
  55. #endif
  56. #if 0
  57. void dev_rtc_setAlarm(int AlarmValue)
  58. {
  59. RTC_ITConfig(RTC_IT_ALR, ENABLE);
  60. /* Clear the RTC SEC flag */
  61. RTC_ClearFlag(RTC_FLAG_SEC);
  62. /* Wait clear RTC flag success */
  63. while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); //
  64. /* Wait until last write operation on RTC registers has finished */
  65. RTC_WaitForLastTask();
  66. /* Sets the RTC alarm value */
  67. RTC_SetAlarm(RTC_GetCounter() + AlarmValue);
  68. /* Wait until last write operation on RTC registers has finished */
  69. RTC_WaitForLastTask();
  70. }
  71. unsigned char dev_rtc_isAlarm(void)
  72. {
  73. if(g_bRTCAlarm)
  74. {
  75. /* Clear the RTC alarm flag */
  76. g_bRTCAlarm = 0;
  77. return 1;
  78. }
  79. return 0;
  80. }
  81. #endif