luat_pm_air101.c 2.2 KB

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