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