Browse Source

update:pm统一深度休眠定时器回调消息

alienwalker 1 year ago
parent
commit
b620487b58
3 changed files with 24 additions and 0 deletions
  1. 4 0
      luat/freertos/luat_msgbus_freertos.c
  2. 1 0
      luat/include/luat_msgbus.h
  3. 19 0
      luat/modules/luat_lib_pm.c

+ 4 - 0
luat/freertos/luat_msgbus_freertos.c

@@ -33,3 +33,7 @@ uint32_t luat_msgbus_freesize(void) {
 uint8_t luat_msgbus_is_empty(void) {
     return uxQueueMessagesWaiting(xQueue) == 0 ? 1 : 0;
 }
+
+uint8_t luat_msgbus_is_ready(void) {
+	return xQueue?1:0;
+}

+ 1 - 0
luat/include/luat_msgbus.h

@@ -26,6 +26,7 @@ uint32_t luat_msgbus_put(rtos_msg_t* msg, size_t timeout);
 uint32_t luat_msgbus_get(rtos_msg_t* msg, size_t timeout);
 uint32_t luat_msgbus_freesize(void);
 uint8_t luat_msgbus_is_empty(void);
+uint8_t luat_msgbus_is_ready(void);
 
 #define luat_msgbug_put2(ABC1,ABC2,ABC3,ABC4,ABC5) {\
     rtos_msg_t _msg = {.handler=ABC1,.ptr=ABC2,.arg1=ABC3,.arg2=ABC4};\

+ 19 - 0
luat/modules/luat_lib_pm.c

@@ -57,6 +57,25 @@ pm.request(pm.IDLE) -- 通过切换不同的值请求进入不同的休眠模式
 #include "luat_log.h"
 
 // static int lua_event_cb = 0;
+/*
+@sys_pub pm
+deep sleep timer定时时间到回调
+DTIMER_WAKEUP
+@usage
+sys.subscribe("DTIMER_WAKEUP", function(timer_id)
+    log.info("deep sleep timer", timer_id)
+end)
+*/
+int luat_dtimer_cb(lua_State *L, void* ptr) {
+    rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
+    lua_getglobal(L, "sys_pub");
+    if (lua_isfunction(L, -1)) {
+        lua_pushstring(L, "DTIMER_WAKEUP");
+        lua_pushinteger(L, msg->arg1);
+        lua_call(L, 2, 0);
+    }
+    return 0;
+}
 
 /**
 请求进入指定的休眠模式