rtc.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef __RT_HW_SERIAL_H__
  2. #define __RT_HW_SERIAL_H__
  3. #include <rthw.h>
  4. #include <rtthread.h>
  5. #include "s3c24x0.h"
  6. #define RTC_DEBUG
  7. #define RTC_ENABLE() (RTCCON |= 0x01) //RTC read and write enable
  8. #define RTC_DISABLE() (RTCCON &= ~0x01) //RTC read and write disable
  9. #define BCD2BIN(n) (((((n) >> 4) & 0x0F) * 10) + ((n) & 0x0F))
  10. #define BIN2BCD(n) ((((n) / 10) << 4) | ((n) % 10))
  11. #define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
  12. #define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))
  13. #define FEBRUARY 2
  14. #define STARTOFTIME 1970
  15. #define SECDAY 86400L
  16. #define SECYR (SECDAY * 365)
  17. #define days_in_year(a) (LEAP_YEAR(a) ? 366 : 365)
  18. #define days_in_month(a) (month_days[(a) - 1])
  19. static unsigned char month_days[] =
  20. {
  21. 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  22. };
  23. struct rtc_time
  24. {
  25. int tm_sec;
  26. int tm_min;
  27. int tm_hour;
  28. int tm_mday;
  29. int tm_mon;
  30. int tm_year;
  31. int tm_wday;
  32. int tm_yday;
  33. int tm_isdst;
  34. };
  35. void rt_hw_rtc_get (struct rtc_time *tmp);
  36. void rt_hw_rtc_set (struct rtc_time *tmp);
  37. void rt_hw_rtc_reset (void);
  38. void GregorianDay (struct rtc_time *);
  39. void rt_rtc_time_to_tm(rt_uint32_t tim, struct rtc_time *tm);
  40. #endif