low_pwr_drv.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "board.h"
  2. void debug_stop(void)
  3. {
  4. M0P_DEBUG_ACTIVE->DEBUG_ACTIVE = (1<<12) | // LPTIM1, 0:normal; 1:pause at STOP;
  5. (1<< 9) | // RTC, 0:normal; 1:pause at STOP;
  6. (1<< 8) | // WDT, 0:normal; 1:pause at STOP;
  7. (1<< 3); // LPTIM0, 0:normal; 1:pause at STOP;
  8. }
  9. void EnterLowPower(void)
  10. {
  11. #ifdef SLEEPDEEP_ENABLE
  12. // uint8_t Flag;
  13. // WaitExpireTime();
  14. // rt_hw_interrupt_disable(); // PRIMASK = 0x1u;
  15. if (DMA_Busy() | FinSh_Txbuf_Busy()){
  16. SCB->SCR = (0x0<<SCB_SCR_SEVONPEND_Pos) |
  17. (0x0<<SCB_SCR_SLEEPDEEP_Pos) | // sleep
  18. (0x0<<SCB_SCR_SLEEPONEXIT_Pos);
  19. // Flag = 0x0u;
  20. // rt_hw_interrupt_enable(0x0u); // PRIMASK = 0x0u;
  21. } else {
  22. SCB->SCR = (0x0<<SCB_SCR_SEVONPEND_Pos) |
  23. (0x1<<SCB_SCR_SLEEPDEEP_Pos) | // deepsleep or stop
  24. (0x0<<SCB_SCR_SLEEPONEXIT_Pos);
  25. // Flag = 0x1u;
  26. }
  27. #else
  28. SCB->SCR = (0x0<<SCB_SCR_SEVONPEND_Pos) |
  29. (0x0<<SCB_SCR_SLEEPDEEP_Pos) | // sleep
  30. (0x0<<SCB_SCR_SLEEPONEXIT_Pos);
  31. #endif
  32. #ifdef DEBUG_ENABLE
  33. // LED_Off();
  34. #endif
  35. __WFI();
  36. #ifdef DEBUG_ENABLE
  37. // LED_On();
  38. #endif
  39. #ifdef SLEEPDEEP_ENABLE
  40. // if (Flag){
  41. // CalExpireTime(150); // if awaked up, cant not enter deepsleep until 150us later
  42. // rt_hw_interrupt_enable(0x0u); // PRIMASK = 0x0u;
  43. // }
  44. #endif
  45. }