luat_pm_air101.c 2.4 KB

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