luat_pm_air101.c 3.2 KB

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