luat_pm_air101.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #define LUAT_LOG_TAG "pm"
  7. #include "luat_log.h"
  8. int luat_pm_request(int mode) {
  9. if (mode == LUAT_PM_SLEEP_MODE_LIGHT) {
  10. tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_TIMER);
  11. tls_pmu_sleep_start();
  12. tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_TIMER);
  13. return 0;
  14. }
  15. else if (mode == LUAT_PM_SLEEP_MODE_DEEP || mode == LUAT_PM_SLEEP_MODE_STANDBY) {
  16. tls_pmu_standby_start();
  17. return 0;
  18. }
  19. return -1;
  20. }
  21. //int luat_pm_release(int mode);
  22. int luat_pm_dtimer_start(int id, size_t timeout) {
  23. if (id == 0 && timeout > 0) {
  24. // 单位秒
  25. tls_pmu_timer0_start((timeout + 999) / 1000);
  26. return 0;
  27. }
  28. else if (id == 1 && timeout > 0) {
  29. // 单位毫妙
  30. tls_pmu_timer1_start(timeout);
  31. return 0;
  32. }
  33. return -1;
  34. }
  35. int luat_pm_dtimer_stop(int id) {
  36. if (id == 0) {
  37. tls_pmu_timer0_stop();
  38. return 0;
  39. }
  40. else if (id == 1) {
  41. tls_pmu_timer1_stop();
  42. return 0;
  43. }
  44. return -1;
  45. }
  46. int luat_pm_dtimer_check(int id) {
  47. return -1;
  48. }
  49. //void luat_pm_cb(int event, int arg, void* args);
  50. #define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
  51. extern int power_bk_reg; // from wm_main.c
  52. // extern int wake_src;
  53. int luat_pm_last_state(int *lastState, int *rtcOrPad) {
  54. // 实际情况与寄存器手册的描述不符
  55. // 复位开机, 是 00D90344
  56. // RTC或wakeup 是 00D10240
  57. if (CHECK_BIT(power_bk_reg, 8)) {
  58. *lastState = 0;
  59. *rtcOrPad = 0;
  60. }
  61. else {
  62. *lastState = 1;
  63. *rtcOrPad = 4;
  64. }
  65. // if (CHECK_BIT(power_bk_reg, 8)) {
  66. // if (CHECK_BIT(power_bk_reg, 5)) {
  67. // *lastState = 3;
  68. // *rtcOrPad = 1;
  69. // }
  70. // else if (CHECK_BIT(power_bk_reg, 2)) {
  71. // *lastState = 3;
  72. // *rtcOrPad = 2;
  73. // }
  74. // else {
  75. // *lastState = 99;
  76. // *rtcOrPad = 0;
  77. // }
  78. // }
  79. // else {
  80. // *lastState = 0;
  81. // *rtcOrPad = 0;
  82. // }
  83. return 0;
  84. }
  85. int luat_pm_force(int mode) {
  86. return luat_pm_request(mode);
  87. }
  88. int luat_pm_check(void) {
  89. return 0;
  90. }
  91. int luat_pm_dtimer_wakeup_id(int* id) {
  92. return 0;
  93. }
  94. int luat_pm_dtimer_list(size_t* count, size_t* list) {
  95. *count = 0;
  96. return 0;
  97. }
  98. int luat_pm_power_ctrl(int id, uint8_t onoff) {
  99. LLOGW("not support yet");
  100. return -1;
  101. }
  102. int luat_pm_wakeup_pin(int pin, int val){
  103. LLOGW("not support yet");
  104. return -1;
  105. }