luat_rtc_air105.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. int luat_rtc_set(struct tm *tblock) {
  25. Date_UserDataStruct Date;
  26. Time_UserDataStruct Time;
  27. Time.Sec = tblock->tm_sec;
  28. Time.Min = tblock->tm_min;
  29. Time.Hour = tblock->tm_hour;
  30. //tblock->tm_wday = uTime.Time.Week;
  31. Date.Year = tblock->tm_year;
  32. Date.Mon = tblock->tm_mon;
  33. Date.Day = tblock->tm_mday;
  34. RTC_SetDateTime(&Date, &Time, 1);
  35. return 0;
  36. }
  37. void luat_rtc_set_tamp32(uint32_t tamp) {
  38. RTC_SetUTC(tamp, 1);
  39. }
  40. int luat_rtc_get(struct tm *tblock) {
  41. Date_UserDataStruct Date;
  42. Time_UserDataStruct Time;
  43. RTC_GetDateTime(&Date, &Time);
  44. tblock->tm_sec = Time.Sec;
  45. tblock->tm_min = Time.Min;
  46. tblock->tm_hour = Time.Hour;
  47. tblock->tm_wday = Time.Week;
  48. tblock->tm_year = Date.Year;
  49. tblock->tm_mon = Date.Mon;
  50. tblock->tm_mday = Date.Day;
  51. return 0;
  52. }
  53. int luat_rtc_timer_start(int id, struct tm *tblock) {
  54. return -1; // 暂不支持
  55. }
  56. int luat_rtc_timer_stop(int id) {
  57. return -1; // 暂不支持
  58. }
  59. uint32_t luat_get_utc(uint32_t *tamp)
  60. {
  61. uint32_t sec = RTC_GetUTC();
  62. if (tamp)
  63. {
  64. *tamp = sec;
  65. }
  66. return sec;
  67. }