luat_pm_air101.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include "luat_base.h"
  2. #include "luat_pm.h"
  3. #include "wm_pmu.h"
  4. #include "wm_regs.h"
  5. #include "wm_timer.h"
  6. #include "wm_watchdog.h"
  7. #include "wm_ram_config.h"
  8. #define LUAT_LOG_TAG "pm"
  9. #include "luat_log.h"
  10. int luat_pm_request(int mode) {
  11. if (mode == LUAT_PM_SLEEP_MODE_LIGHT) {
  12. tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_TIMER);
  13. tls_pmu_sleep_start();
  14. tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_TIMER);
  15. return 0;
  16. }
  17. else if (mode == LUAT_PM_SLEEP_MODE_DEEP || mode == LUAT_PM_SLEEP_MODE_STANDBY) {
  18. tls_pmu_standby_start();
  19. return 0;
  20. }
  21. return -1;
  22. }
  23. static void pmu_timer0_irq(uint8_t *arg){
  24. tls_pmu_timer0_stop();
  25. }
  26. static void pmu_timer1_irq(uint8_t *arg){
  27. tls_pmu_timer1_stop();
  28. }
  29. //int luat_pm_release(int mode);
  30. int luat_pm_dtimer_start(int id, size_t timeout) {
  31. tls_pmu_clk_select(1);
  32. if (id == 0 && timeout > 0) {
  33. // 单位秒
  34. tls_pmu_timer0_stop();
  35. tls_pmu_timer0_isr_register((tls_pmu_irq_callback)pmu_timer0_irq, NULL);
  36. tls_pmu_timer0_start((timeout + 999) / 1000);
  37. return 0;
  38. }
  39. else if (id == 1 && timeout > 0) {
  40. // 单位毫妙
  41. tls_pmu_timer1_stop();
  42. tls_pmu_timer1_isr_register((tls_pmu_irq_callback)pmu_timer1_irq, NULL);
  43. tls_pmu_timer1_start(timeout);
  44. return 0;
  45. }
  46. return -1;
  47. }
  48. int luat_pm_dtimer_stop(int id) {
  49. if (id == 0) {
  50. tls_pmu_timer0_stop();
  51. return 0;
  52. }
  53. else if (id == 1) {
  54. tls_pmu_timer1_stop();
  55. return 0;
  56. }
  57. return -1;
  58. }
  59. int luat_pm_dtimer_check(int id) {
  60. return -1;
  61. }
  62. //void luat_pm_cb(int event, int arg, void* args);
  63. #define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
  64. extern int power_bk_reg; // from wm_main.c
  65. // extern int wake_src;
  66. int luat_pm_last_state(int *lastState, int *rtcOrPad) {
  67. int reson = tls_sys_get_reboot_reason();
  68. switch (tls_sys_get_reboot_reason())
  69. {
  70. case REBOOT_REASON_POWER_ON:// 硬件复位开机
  71. *lastState = 0;
  72. *rtcOrPad = 0;
  73. break;
  74. case REBOOT_REASON_STANDBY: // 唤醒重启
  75. *lastState = 3;
  76. *rtcOrPad = 3;
  77. break;
  78. case REBOOT_REASON_EXCEPTION: // 异常重启
  79. *lastState = 0;
  80. *rtcOrPad = 1;
  81. break;
  82. case REBOOT_REASON_WDG_TIMEOUT: // 硬狗超时
  83. *lastState = 0;
  84. *rtcOrPad = 1;
  85. break;
  86. case REBOOT_REASON_ACTIVE: // 用户主动复位
  87. *lastState = 0;
  88. *rtcOrPad = 0;
  89. break;
  90. case REBOOT_REASON_SLEEP: // 不可能出现
  91. *lastState = 0;
  92. *rtcOrPad = 4;
  93. break;
  94. default:
  95. break;
  96. }
  97. return 0;
  98. }
  99. int luat_pm_get_poweron_reason(void)
  100. {
  101. int reson = tls_sys_get_reboot_reason();
  102. switch (tls_sys_get_reboot_reason())
  103. {
  104. case REBOOT_REASON_POWER_ON:// 硬件复位开机
  105. return 0;
  106. case REBOOT_REASON_STANDBY:
  107. return 2;
  108. case REBOOT_REASON_EXCEPTION:
  109. return 6;
  110. case REBOOT_REASON_WDG_TIMEOUT:
  111. return 8;
  112. case REBOOT_REASON_ACTIVE:
  113. return 3;
  114. case REBOOT_REASON_SLEEP:
  115. return 2;
  116. default:
  117. break;
  118. }
  119. return 4;
  120. }
  121. int luat_pm_force(int mode) {
  122. return luat_pm_request(mode);
  123. }
  124. int luat_pm_check(void) {
  125. return 0;
  126. }
  127. int luat_pm_dtimer_wakeup_id(int* id) {
  128. return 0;
  129. }
  130. int luat_pm_dtimer_list(size_t* count, size_t* list) {
  131. *count = 0;
  132. return 0;
  133. }
  134. int luat_pm_power_ctrl(int id, uint8_t onoff) {
  135. LLOGW("not support yet");
  136. return -1;
  137. }
  138. int luat_pm_wakeup_pin(int pin, int val){
  139. LLOGW("not support yet");
  140. return -1;
  141. }