drv_pm.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-04-08 wangyq the first version
  9. * 2019-05-06 Zero-Free adapt to the new power management interface
  10. */
  11. #include <rthw.h>
  12. #include <rtdevice.h>
  13. #include "board.h"
  14. #include "drv_pm.h"
  15. #include <ald_pmu.h>
  16. #ifdef RT_USING_PM
  17. static void _drv_pm_enter(struct rt_pm *pm, uint8_t mode)
  18. {
  19. switch (mode)
  20. {
  21. case PM_SLEEP_MODE_NONE:
  22. break;
  23. case PM_SLEEP_MODE_IDLE:
  24. __WFI();
  25. break;
  26. case PM_SLEEP_MODE_LIGHT:
  27. break;
  28. case PM_SLEEP_MODE_DEEP:
  29. pmu_stop2_enter();
  30. break;
  31. case PM_SLEEP_MODE_STANDBY:
  32. pmu_standby_enter(PMU_STANDBY_PORT_NONE);
  33. break;
  34. case PM_SLEEP_MODE_SHUTDOWN:
  35. break;
  36. default:
  37. RT_ASSERT(0);
  38. break;
  39. }
  40. }
  41. static int drv_hw_pm_init(void)
  42. {
  43. static const struct rt_pm_ops _ops =
  44. {
  45. _drv_pm_enter,
  46. RT_NULL,
  47. RT_NULL,
  48. RT_NULL,
  49. RT_NULL
  50. };
  51. rt_uint8_t timer_mask = 0;
  52. /* initialize timer mask(no need tickless) */
  53. // timer_mask = 1UL << PM_SLEEP_MODE_DEEP;
  54. /* initialize system pm module */
  55. rt_system_pm_init(&_ops, timer_mask, RT_NULL);
  56. return 0;
  57. }
  58. INIT_BOARD_EXPORT(drv_hw_pm_init);
  59. #endif