LPC_Rtc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef __LPC_RTC_H
  2. #define __LPC_RTC_H
  3. /*************************************************************************
  4. *
  5. * Used with ICCARM and AARM.
  6. *
  7. * (c) Copyright IAR Systems 2003
  8. *
  9. * File name : LPC_Rtc.h
  10. * Description : Define RTI structure and relative micro
  11. *
  12. * History :
  13. * 1. Data : August 10, 2004
  14. * Author : Shawn Zhang
  15. * Description : Create
  16. *
  17. * 2. Data : Oct 12, 2004
  18. * Author : Stanimir Bonev
  19. * Description: Modify the interface of some functions
  20. *
  21. * $Revision: 1.1 $
  22. **************************************************************************/
  23. #include "includes.h"
  24. #define RTC_CountPerSec 32768
  25. #define RTC_YEARMIN 1901
  26. #define RTC_YEARMAX 2099
  27. // 1901.1.1 DOW = 2
  28. #define RTC_BASEYEAR 1901
  29. #define RTC_BASEMONTH 1
  30. #define RTC_BASEDAY 1
  31. #define RTC_BASEDOW 2
  32. /* RTC Interrupt location register bit descriptions */
  33. #define ILR_CIF_BIT 0
  34. #define ILR_ALF_BIT 1
  35. /* RTC Clock control register bit descriptions */
  36. #define CCR_CLKEN_BIT 0
  37. #define CCR_CTCRST_BIT 1
  38. /* RTC Increment Interrupt Type */
  39. #define IncIntType_SEC 0x1
  40. #define IncIntType_MIN 0x2
  41. #define IncIntType_HOUR 0x4
  42. #define IncIntType_DAY 0x8
  43. #define IncIntType_MON 0x40
  44. #define IncIntType_YEAR 0x80
  45. #define IncIntType_DOW 0x10
  46. #define IncIntType_DOY 0x20
  47. /* RTC Alarm Interrupt Type */
  48. #define AlarmIntType_SEC 0x1
  49. #define AlarmIntType_MIN 0x2
  50. #define AlarmIntType_HOUR 0x4
  51. #define AlarmIntType_DAY 0x8
  52. #define AlarmIntType_MON 0x40
  53. #define AlarmIntType_YEAR 0x80
  54. #define AlarmIntType_DOW 0x10
  55. #define AlarmIntType_DOY 0x20
  56. /* RTC interrupt type */
  57. #define RTCIncrementInt 0x1
  58. #define RTCAlarmInt 0x2
  59. #define RTCALLInt 0x3
  60. typedef struct {
  61. unsigned short year; // year value
  62. unsigned char month; // month value
  63. unsigned char day; // day value
  64. /* the below member is used in get-operation */
  65. unsigned char DOW; // Day of week
  66. unsigned char DOY; // Day of year
  67. } LPC_Rtc_Date_t;
  68. typedef struct {
  69. unsigned char hour; // hour value
  70. unsigned char minute; // minute value
  71. unsigned char second; // second value
  72. } LPC_Rtc_Time_t;
  73. typedef struct {
  74. unsigned short year; // year value
  75. unsigned char month; // month value
  76. unsigned char day; // day value
  77. unsigned char hour; // hour value
  78. unsigned char minute; // minute value
  79. unsigned char second; // second value
  80. /* the below member is used in get-operation */
  81. unsigned char DOW; // Day of week
  82. unsigned char DOY; // Day of year
  83. } LPC_Rtc_DateTime_t;
  84. static LPC_Rtc_DateTime_t RTC_InitDateTime = {2005, 2, 14, 12, 0, 0};
  85. static char *RTC_DOWTbl[] = {
  86. "Sunday ",
  87. "Monday ",
  88. "Tuesday ",
  89. "Wednesday ",
  90. "Thursday ",
  91. "Friday ",
  92. "Saturday "
  93. };
  94. static char *RTC_MonthTbl[] = {
  95. "",
  96. "January ",
  97. "February ",
  98. "Match ",
  99. "April ",
  100. "May ",
  101. "June ",
  102. "July ",
  103. "August ",
  104. "September ",
  105. "October ",
  106. "November ",
  107. "December "
  108. };
  109. static int RTC_MonthVal[]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  110. /* Declare functions */
  111. void RTC_Enable(void);
  112. void RTC_Disable(void);
  113. int RTC_Init(LPC_BOOL OldComp);
  114. int RTC_SetDate (LPC_Rtc_Date_t *pDate);
  115. int RTC_SetTime (LPC_Rtc_Time_t *pTime);
  116. int RTC_SetDateTime (LPC_Rtc_DateTime_t *pDateTime);
  117. int RTC_GetDate (LPC_Rtc_Date_t *pDate);
  118. int RTC_GetTime (LPC_Rtc_Time_t *pTime);
  119. int RTC_GetDateTime (LPC_Rtc_DateTime_t *pDateTime);
  120. void RTC_SetIncInt (unsigned char IncIntType);
  121. void RTC_DisableIncInt(void);
  122. void RTC_SetAlarmInt (unsigned char AlarmIntType);
  123. void RTC_DisableAlarmInt(void);
  124. int RTC_SetAlarmDateTime (LPC_Rtc_DateTime_t *pDateTime);
  125. int RTC_ClearInt(unsigned long IntType);
  126. unsigned long RTC_CheckIntType(void);
  127. void RTC_ISR (void);
  128. void FormatDate (int Type, LPC_Rtc_Date_t *pDate, char *s);
  129. void FormatTime (int Type, LPC_Rtc_Time_t *pTime, char *s);
  130. void FormatDateTime (int Type, LPC_Rtc_DateTime_t *pDateTime, char *s);
  131. extern void SysTimeUpdate (void);
  132. extern void Alarm (void);
  133. #endif // __LPC_RTC_H