luat_rtc_air105.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "luat_base.h"
  22. #include "luat_rtc.h"
  23. #include "app_interface.h"
  24. extern int Base_year;
  25. int luat_rtc_set(struct tm *tblock) {
  26. Date_UserDataStruct Date;
  27. Time_UserDataStruct Time;
  28. Time.Sec = tblock->tm_sec;
  29. Time.Min = tblock->tm_min;
  30. Time.Hour = tblock->tm_hour;
  31. //tblock->tm_wday = uTime.Time.Week;
  32. Date.Year = tblock->tm_year;
  33. Date.Mon = tblock->tm_mon;
  34. Date.Day = tblock->tm_mday;
  35. Date.Year += Base_year;
  36. Date.Mon += 1;
  37. RTC_SetDateTime(&Date, &Time, 1);
  38. return 0;
  39. }
  40. void luat_rtc_set_tamp32(uint32_t tamp) {
  41. RTC_SetUTC(tamp, 1);
  42. }
  43. int luat_rtc_get(struct tm *tblock) {
  44. Date_UserDataStruct Date;
  45. Time_UserDataStruct Time;
  46. RTC_GetDateTime(&Date, &Time);
  47. tblock->tm_sec = Time.Sec;
  48. tblock->tm_min = Time.Min;
  49. tblock->tm_hour = Time.Hour;
  50. tblock->tm_wday = Time.Week;
  51. tblock->tm_year = Date.Year;
  52. tblock->tm_mon = Date.Mon;
  53. tblock->tm_mday = Date.Day;
  54. tblock->tm_year -= Base_year;
  55. tblock->tm_mon -= 1;
  56. return 0;
  57. }
  58. int luat_rtc_timer_start(int id, struct tm *tblock) {
  59. return -1; // 暂不支持
  60. }
  61. int luat_rtc_timer_stop(int id) {
  62. return -1; // 暂不支持
  63. }
  64. uint32_t luat_get_utc(uint32_t *tamp)
  65. {
  66. uint32_t sec = RTC_GetUTC();
  67. if (tamp)
  68. {
  69. *tamp = sec;
  70. }
  71. return sec;
  72. }
  73. int luat_rtc_timezone(int* timezone) {
  74. return 32; // 暂不支持
  75. }