luat_rtc_air101.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "luat_rtc.h"
  2. #include "luat_msgbus.h"
  3. #include "wm_rtc.h"
  4. #define LUAT_LOG_TAG "rtc"
  5. #include "luat_log.h"
  6. extern int Base_year;
  7. static int luat_rtc_handler(lua_State *L, void* ptr) {
  8. lua_getglobal(L, "sys_pub");
  9. if (lua_isfunction(L, -1)) {
  10. lua_pushstring(L, "RTC_IRQ");
  11. lua_call(L, 1, 0);
  12. }
  13. return 0;
  14. }
  15. static void luat_rtc_cb(void *arg) {
  16. //LLOGI("rtc irq");
  17. rtos_msg_t msg;
  18. msg.handler = luat_rtc_handler;
  19. luat_msgbus_put(&msg, 0);
  20. }
  21. int luat_rtc_set(struct tm *tblock) {
  22. if (tblock == NULL)
  23. return -1;
  24. tblock->tm_year -= Base_year;
  25. tblock->tm_mon--;
  26. tls_set_rtc(tblock);
  27. return 0;
  28. }
  29. int luat_rtc_get(struct tm *tblock) {
  30. if (tblock == NULL)
  31. return -1;
  32. tls_get_rtc(tblock);
  33. tblock->tm_year += Base_year;
  34. tblock->tm_mon++;
  35. return 0;
  36. }
  37. int luat_rtc_timer_start(int id, struct tm *tblock) {
  38. if (id || tblock == NULL)
  39. return -1;
  40. tblock->tm_year -= Base_year;
  41. tblock->tm_mon--;
  42. tls_rtc_isr_register(luat_rtc_cb, NULL);
  43. tls_rtc_timer_start(tblock);
  44. }
  45. int luat_rtc_timer_stop(int id) {
  46. if (id)
  47. return -1;
  48. tls_rtc_timer_stop();
  49. }