luat_pm_air101.c 3.2 KB

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