rtc.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  2. Copyright (C) 2007-2010 Ingo Korb <ingo@akana.de>
  3. Inspiration and low-level SD/MMC access based on code from MMC2IEC
  4. by Lars Pontoppidan et al., see sdcard.c|h and config.h.
  5. FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; version 2 of the License only.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. rtc.h: Definitions for RTC support
  17. */
  18. #ifndef RTC_H
  19. #define RTC_H
  20. #include <stdint.h>
  21. typedef enum {
  22. RTC_NOT_FOUND, /* No RTC present */
  23. RTC_INVALID, /* RTC present, but contents invalid */
  24. RTC_OK /* RTC present and working */
  25. } rtcstate_t;
  26. struct tm {
  27. uint8_t tm_sec; // 0..59
  28. uint8_t tm_min; // 0..59
  29. uint8_t tm_hour; // 0..23
  30. uint8_t tm_mday; // 1..[28..31]
  31. uint8_t tm_mon; // 0..11
  32. uint16_t tm_year; // since 0 A.D.
  33. uint8_t tm_wday; // 0 to 6, sunday is 6
  34. // A Unix struct tm has a few more fields we don't need in this application
  35. };
  36. #define RTC_MAGIC (0x43545253L)
  37. extern rtcstate_t rtc_state;
  38. void rtc_init(void);
  39. /* return RTC valid state based on magic token in backup register */
  40. uint8_t rtc_isvalid(void);
  41. /* Return current time in struct tm */
  42. void read_rtc(struct tm *time);
  43. /* Set time from struct tm, also sets RTC valid */
  44. void set_rtc(struct tm *time);
  45. /* Set RTC invalid */
  46. void invalidate_rtc(void);
  47. /* get current time in 60-bit BCD format (WYYYYMMDDHHMMSS) (W=DOW) */
  48. uint64_t get_bcdtime(void);
  49. /* set current time from 56-bit BCD format (YYYYMMDDHHMMSS)
  50. DOW is calculated */
  51. void set_bcdtime(uint64_t btime);
  52. /* print the time to the console */
  53. void printtime(struct tm *time);
  54. void testbattery(void);
  55. #endif