hal_low_pwoer.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "hal_low_power.h"
  2. #include "hc32_ll_pwc.h"
  3. #include "hc32_ll.h"
  4. #include "FreeRTOS.h"
  5. #include "task.h"
  6. /**
  7. * @brief Whether ready to entry stop mode.
  8. * @param None
  9. * @retval int32_t:
  10. * @note Ensure DMA stops transmit and no flash erase/program operation.
  11. */
  12. int32_t stop_is_ready(void)
  13. {
  14. int32_t i32Ret = LL_OK;
  15. uint8_t tmp1;
  16. uint8_t tmp2;
  17. uint8_t tmp3;
  18. tmp1 = (uint8_t)((READ_REG32(CM_EFM->FSR) & EFM_FSR_RDY) == EFM_FSR_RDY);
  19. tmp2 = (uint8_t)((READ_REG32(CM_DMA1->CHSTAT) & DMA_CHSTAT_DMAACT) == 0x00U);
  20. tmp3 = (uint8_t)((READ_REG32(CM_DMA2->CHSTAT) & DMA_CHSTAT_DMAACT) == 0x00U);
  21. if (0U == (tmp1 & tmp2 & tmp3)) {
  22. i32Ret = LL_ERR_NOT_RDY;
  23. }
  24. return i32Ret;
  25. }
  26. /**
  27. * @brief MCU behavior config for stop mode.
  28. * @param None
  29. * @retval None
  30. */
  31. void sleep_config(void)
  32. {
  33. stc_pwc_stop_mode_config_t stcStopConfig;
  34. (void)PWC_STOP_StructInit(&stcStopConfig);
  35. stcStopConfig.u16ExBusHold = PWC_STOP_EXBUS_HIZ;
  36. stcStopConfig.u16Clock = PWC_STOP_CLK_KEEP;
  37. stcStopConfig.u16FlashWait = PWC_STOP_FLASH_WAIT_ON;
  38. (void)PWC_STOP_Config(&stcStopConfig);
  39. /* Wake-up source config (EXINT Ch.6 here) */
  40. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH0, ENABLE);//唤醒脚配置
  41. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH1, ENABLE);//唤醒脚配置
  42. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH8, ENABLE);//唤醒脚配置
  43. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH9, ENABLE);//唤醒脚配置
  44. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH10, ENABLE);//唤醒脚配置
  45. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH11, ENABLE);//唤醒脚配置
  46. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH12, ENABLE);//唤醒脚配置
  47. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH13, ENABLE);//唤醒脚配置
  48. INTC_WakeupSrcCmd(INTC_STOP_WKUP_EXTINT_CH14, ENABLE);//唤醒脚配置
  49. }
  50. void test_task3(void *pvParameters)
  51. {
  52. uint8_t u8Count;
  53. vTaskDelay(3000);
  54. static uint16_t cnt = 0;
  55. while(1)
  56. {
  57. if (LL_OK == stop_is_ready())
  58. {
  59. u8Count = 10U;
  60. vTaskDelay(5000);
  61. GPIO_TogglePins(GPIO_PORT_A, GPIO_PIN_02);
  62. SysTick_Suspend();
  63. PWC_STOP_Enter(PWC_STOP_WFI);
  64. }
  65. cnt++;
  66. printf("cnt=%d\n",cnt);
  67. SysTick_Resume();
  68. vTaskDelay(5000);
  69. }
  70. }
  71. //进入休眠的时候不允许有flash读写,DMA等操作