hal_pwr.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "hal_pwr.h"
  2. void Peripheral_UnInit(void)
  3. {
  4. unsigned int err_code;
  5. UART0_UnInit();
  6. //to do twi_UnInit();
  7. //to do spi_UnInit();
  8. //to do saadc_UnInit();
  9. TIME_UnInit();
  10. err_code = ESB_UnInit();
  11. #if DEBUG_PWR_Process
  12. if(err_code==0) SEGGER_RTT_printf(0,"Peripheral_UnInit ok!!\n");
  13. else SEGGER_RTT_printf(0,"Peripheral_UnInit fail!!\n");
  14. #endif
  15. }
  16. void WakeUp_Process(void* p)
  17. {
  18. unsigned int err_code;
  19. SEGGER_RTT_printf(0,"WakeUp_Process start!!\n");
  20. WakeUpDisable();
  21. UART0_Init(115200); //初始化串口
  22. TIME_Init(); //滴答
  23. err_code = ESB_Init();
  24. #if DEBUG_PWR_Process
  25. if(err_code==0) SEGGER_RTT_printf(0,"WakeUp_Process ok!!\n");
  26. else SEGGER_RTT_printf(0,"WakeUp_Process fail!!\n");
  27. #endif
  28. }
  29. void PWR_Process(void)
  30. {
  31. if(GetWakeUpTime() != 0) //如果设置了唤醒时间
  32. {
  33. #if DEBUG_PWR_Process
  34. SEGGER_RTT_printf(0,"PWR_Process call time : %d\r\n",TIME_GetTicks());
  35. #endif
  36. Peripheral_UnInit(); //关闭外设
  37. if(IsWakeUpEnable() == 0){
  38. lfclk_config(); //开启低频时钟
  39. }
  40. WakeUpTask_Regist(WakeUp_Process); //唤醒任务注册
  41. WakeUpEnable(); //使能唤醒中断
  42. PWR_EnterSleep(); //进入睡眠
  43. }
  44. }