rtc.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. {
  23. RTC_NOT_FOUND, /* No RTC present */
  24. RTC_INVALID, /* RTC present, but contents invalid */
  25. RTC_OK /* RTC present and working */
  26. } rtcstate_t;
  27. struct tm
  28. {
  29. uint8_t tm_sec; // 0..59
  30. uint8_t tm_min; // 0..59
  31. uint8_t tm_hour; // 0..23
  32. uint8_t tm_mday; // 1..[28..31]
  33. uint8_t tm_mon; // 0..11
  34. uint16_t tm_year; // since 0 A.D.
  35. uint8_t tm_wday; // 0 to 6, sunday is 6
  36. // A Unix struct tm has a few more fields we don't need in this application
  37. };
  38. #define RTC_MAGIC (0x43545253L)
  39. extern rtcstate_t rtc_state;
  40. void rtc_init( void );
  41. /* return RTC valid state based on magic token in backup register */
  42. uint8_t rtc_isvalid( void );
  43. /* Return current time in struct tm */
  44. void read_rtc( struct tm *time );
  45. /* Set time from struct tm, also sets RTC valid */
  46. void set_rtc( struct tm *time );
  47. /* Set RTC invalid */
  48. void invalidate_rtc( void );
  49. /* get current time in 60-bit BCD format (WYYYYMMDDHHMMSS) (W=DOW) */
  50. uint64_t get_bcdtime( void );
  51. /* set current time from 56-bit BCD format (YYYYMMDDHHMMSS)
  52. DOW is calculated */
  53. void set_bcdtime( uint64_t btime );
  54. /* print the time to the console */
  55. void printtime( struct tm *time );
  56. void testbattery( void );
  57. #endif