luat_rtc_air101.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "luat_rtc.h"
  2. #include "luat_msgbus.h"
  3. #include "wm_rtc.h"
  4. #include "time.h"
  5. #define LUAT_LOG_TAG "rtc"
  6. #include "luat_log.h"
  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. tls_set_rtc(tblock);
  25. return 0;
  26. }
  27. int luat_rtc_get(struct tm *tblock) {
  28. if (tblock == NULL)
  29. return -1;
  30. tls_get_rtc(tblock);
  31. return 0;
  32. }
  33. int luat_rtc_timer_start(int id, struct tm *tblock) {
  34. if (id || tblock == NULL)
  35. return -1;
  36. tls_rtc_isr_register(luat_rtc_cb, NULL);
  37. tls_rtc_timer_start(tblock);
  38. return 0;
  39. }
  40. int luat_rtc_timer_stop(int id) {
  41. if (id)
  42. return -1;
  43. tls_rtc_timer_stop();
  44. return 0;
  45. }
  46. int luat_rtc_timezone(int* timezone) {
  47. return 32; // 暂不支持
  48. }
  49. void luat_rtc_set_tamp32(uint32_t tamp) {
  50. time_t t;
  51. t = tamp + (8*3600); // 固定东八区
  52. struct tm *tblock = gmtime(&t);
  53. luat_rtc_set(tblock);
  54. }