sleep.c 2.2 KB

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