Browse Source

fix: rtc库返回不合理的值 https://gitee.com/openLuat/LuatOS/issues/I6MGWQ

Wendal Chen 3 years ago
parent
commit
d4f2f6bbb5
2 changed files with 18 additions and 13 deletions
  1. 0 13
      app/port/luat_base_air101.c
  2. 18 0
      app/port/luat_rtc_air101.c

+ 0 - 13
app/port/luat_base_air101.c

@@ -13,19 +13,6 @@
 LUAMOD_API int luaopen_gtfont( lua_State *L );
 LUAMOD_API int luaopen_nimble( lua_State *L );
 
-time_t time(time_t* _tm)
-{
-  struct tm tmt = {0};
-  tls_get_rtc(&tmt);
-  time_t t = mktime(&tmt);
-  if (_tm != NULL)
-    memcpy(_tm, &t, sizeof(time_t));
-  return t;
-}
-clock_t clock(void)
-{
-  return (clock_t)time(NULL);
-}
 
 static const luaL_Reg loadedlibs[] = {
   {"_G", luaopen_base}, // _G

+ 18 - 0
app/port/luat_rtc_air101.c

@@ -25,6 +25,7 @@ static void luat_rtc_cb(void *arg) {
 int luat_rtc_set(struct tm *tblock) {
     if (tblock == NULL)
         return -1;
+    tblock->tm_mon ++;
     tls_set_rtc(tblock);
     return 0;
 }
@@ -33,6 +34,7 @@ int luat_rtc_get(struct tm *tblock) {
     if (tblock == NULL)
         return -1;
     tls_get_rtc(tblock);
+    tblock->tm_mon --;
     return 0;
 }
 
@@ -61,3 +63,19 @@ void luat_rtc_set_tamp32(uint32_t tamp) {
     struct tm *tblock = gmtime(&t);
     luat_rtc_set(tblock);
 }
+
+time_t time(time_t* _tm)
+{
+  struct tm tmt = {0};
+  tls_get_rtc(&tmt);
+  tmt.tm_mon --;
+  time_t t = mktime(&tmt);
+  if (_tm != NULL)
+    memcpy(_tm, &t, sizeof(time_t));
+  return t;
+}
+
+clock_t clock(void)
+{
+  return (clock_t)time(NULL);
+}