dal_time.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /******************************************************************************
  2. ** File Name: dal_time.h *
  3. ** Author: Richard.Yang *
  4. ** DATE: 10/11/2004 *
  5. ** Copyright: 2004 Spreatrum, Incoporated. All Rights Reserved. *
  6. ** Description: *
  7. ******************************************************************************
  8. ******************************************************************************
  9. ** Edit History *
  10. ** ------------------------------------------------------------------------- *
  11. ** DATE NAME DESCRIPTION *
  12. ** 10/11/2004 Richard.Yang Create. *
  13. ******************************************************************************/
  14. #ifndef _DAL_TIME_H
  15. #define _DAL_TIME_H
  16. #include "sci_types.h"
  17. //#include "sci_service.h"
  18. //#include "tasks_id.h"
  19. /**---------------------------------------------------------------------------*
  20. ** Compiler Flag *
  21. **---------------------------------------------------------------------------*/
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**---------------------------------------------------------------------------*
  26. ** Constant Variables *
  27. **---------------------------------------------------------------------------*/
  28. // Support time range:
  29. // Start time: 2000-01-01 00:00:00'
  30. // End time: 2049-12-31 23:59:59'
  31. #define TM_MAX_YEARS_SUPPORTED 50
  32. /**---------------------------------------------------------------------------*
  33. ** Data Structures *
  34. **---------------------------------------------------------------------------*/
  35. typedef enum
  36. {
  37. // MISC message.
  38. MISC_MSG_RTC_SEC,
  39. MISC_MSG_RTC_MIN,
  40. MISC_MSG_RTC_HOUR,
  41. MISC_MSG_RTC_DAY,
  42. MISC_MSG_RTC_ALARM,
  43. MISC_MSG_MAX // Reserved, user can't use it.
  44. } MISC_MSG_SERVICE_E;
  45. #define MISC_MSG_MAX_NUM (MISC_MSG_MAX & 0x00FF)
  46. // Time error value.
  47. typedef enum
  48. {
  49. ERR_TM_NONE = SCI_SUCCESS,
  50. ERR_TM_PNULL,
  51. ERR_TM_WRONG_DATE,
  52. ERR_TM_WRONG_TIME,
  53. ERR_TM_ALARM_WRONG_TIME,
  54. ERR_TM_ALARM_TIME_IS_EXPIRED,
  55. ERR_TM_MAX // Reserved, user can't use it.
  56. } ERR_TM_E;
  57. typedef struct
  58. {
  59. uint8 mday; // day of the month - [1,31]
  60. uint8 mon; // months - [1,12]
  61. uint16 year; // years [2000,2049]
  62. uint8 wday; // days since Sunday - [0,6], (Sunday : 0, Monday : 1)
  63. } SCI_DATE_T;
  64. typedef struct
  65. {
  66. uint8 sec; // secondsafter the minute - [0,59]
  67. uint8 min; // minutesafter the hour - [0,59]
  68. uint8 hour; // hours since midnight - [0,23]
  69. } SCI_TIME_T;
  70. typedef struct
  71. {
  72. uint16 msec; // secondsafter the minute - [0,1000]
  73. uint8 sec; // secondsafter the minute - [0,59]
  74. uint8 min; // minutesafter the hour - [0,59]
  75. uint8 hour; // hours since midnight - [0,23]
  76. } SCI_TIMEX_T;
  77. typedef struct
  78. {
  79. uint8 sec; // secondsafter the minute - [0,59]
  80. uint8 min; // minutesafter the hour - [0,59]
  81. uint8 hour; // hours since midnight - [0,23]
  82. uint8 mday; // day of the month - [1,31]
  83. uint8 mon; // months - [1,12]
  84. uint16 year; // years [2000,2049]
  85. } SCI_ALARM_T;
  86. /**---------------------------------------------------------------------------*
  87. ** Function Prototypes *
  88. **---------------------------------------------------------------------------*/
  89. /*****************************************************************************/
  90. // Description : Set system date(year/mon/day)
  91. // Global resource dependence :
  92. // Author:
  93. // Note: The week_day of system date input is ignorled.
  94. /*****************************************************************************/
  95. PUBLIC ERR_TM_E TM_SetSysDate( // If successful, return ERR_TM_NONE;
  96. // else return ERR_TM_WRONG_DATE.
  97. SCI_DATE_T sys_date // Date value to be set
  98. );
  99. /*****************************************************************************/
  100. // Description : Get system date(year/mon/day, week_day)
  101. // Global resource dependence :
  102. // Author:
  103. // Note:
  104. /*****************************************************************************/
  105. PUBLIC ERR_TM_E TM_GetSysDate( // If successful, return ERR_TM_NONE;
  106. // else return ERR_TM_PNULL.
  107. SCI_DATE_T *date_ptr // Save system date gotten.
  108. );
  109. /*****************************************************************************/
  110. // Description : Set system time (hour/min/sec)
  111. // lobal resource dependence :
  112. // Author:
  113. // Note:
  114. /*****************************************************************************/
  115. PUBLIC ERR_TM_E TM_SetSysTime( // If successful, return ERR_TM_NONE;
  116. // else return ERR_TM_WRONG_TIME.
  117. SCI_TIME_T sys_time // Time value to be set.
  118. );
  119. PUBLIC ERR_TM_E TM_GetDefaultSysDate(SCI_DATE_T *date_ptr);
  120. /*****************************************************************************/
  121. // Description : Get system time (hour/min/sec)
  122. // Global resource dependence :
  123. // Author:
  124. // Note:
  125. /*****************************************************************************/
  126. PUBLIC ERR_TM_E TM_GetSysTime( // If successful, return ERR_TM_NONE;
  127. // else return ERR_TM_PNULL.
  128. SCI_TIME_T *time_ptr // Save time value gotten.
  129. );
  130. /*****************************************************************************/
  131. // Description : Get system time (hour/min/sec/msec)
  132. // Global resource dependence :
  133. // Author:
  134. // Note:
  135. /*****************************************************************************/
  136. PUBLIC ERR_TM_E TM_GetSysTimeEx( // If successful, return ERR_TM_NONE;
  137. // else return ERR_TM_PNULL.
  138. SCI_TIMEX_T *time_ptr // Save time value gotten.
  139. );
  140. /*****************************************************************************/
  141. // Description : Set alarm (year/mon/day hour:min:sec)
  142. // Global resource dependence :
  143. // Author:
  144. // Note:
  145. /*****************************************************************************/
  146. PUBLIC ERR_TM_E TM_SetAlarm( // If successful, return ERR_TM_NONE;
  147. // else return ERR_TM_ALARM_TIME_IS_EXPIRED
  148. // or ERR_TM_ALARM_WRONG_TIME.
  149. SCI_ALARM_T alarm_time // Alarm date and time value to be set
  150. );
  151. /*****************************************************************************/
  152. // Description : Disable alarm.
  153. // Global resource dependence :
  154. // Author:
  155. // Note:
  156. /*****************************************************************************/
  157. PUBLIC void TM_DisableAlarm(void);
  158. /*****************************************************************************/
  159. // Description : Get number of seconds escaped from 2000/01/01/ 00:00:00.
  160. // Global resource dependence :
  161. // Author:
  162. // Note:
  163. /*****************************************************************************/
  164. PUBLIC uint32 TM_GetTotalSeconds(void); // Return number of seconds.
  165. /* @Xueliang.Wang modify; CR10641; (2004-07-14) */
  166. // To be deleted
  167. typedef struct
  168. {
  169. uint32 tm_sec; // secondsafter the minute - [0,59]
  170. uint32 tm_min; // minutesafter the hour - [0,59]
  171. uint32 tm_hour; // hours since midnight - [0,23]
  172. uint32 tm_mday; // day of the month - [1,31]
  173. uint32 tm_mon; // months since January - [1,12]
  174. uint32 tm_year; // years
  175. uint32 tm_wday; // days since Sunday - [0,6]
  176. uint32 tm_yday; // days since January 1 - [0,365]
  177. uint32 tm_isdst; // daylight savings time flag
  178. } SCI_TM_T; // // To be deleted
  179. /*****************************************************************************/
  180. // Description : Initialize system date & time.
  181. // lobal resource dependence :
  182. // Author:
  183. // Note:
  184. /*****************************************************************************/
  185. PUBLIC void TM_Init(void);
  186. /*****************************************************************************/
  187. // Description : Get time (year/mon/day/hour/min/sec)
  188. // lobal resource dependence :
  189. // Author:
  190. // Note:
  191. /*****************************************************************************/
  192. PUBLIC void TM_GetTime(SCI_TM_T *realtime); // To be deleted
  193. /*****************************************************************************/
  194. // Description : Set time (year/mon/day/hour/min/sec)
  195. // lobal resource dependence :
  196. // Author:
  197. // Note:
  198. /*****************************************************************************/
  199. PUBLIC uint32 TM_SetTime(SCI_TM_T realtime); // To be deleted
  200. /*****************************************************************************/
  201. // Description : This API retrun the result if RTC is abnormal
  202. // Global resource dependence :
  203. // Author:
  204. // Note:
  205. /*****************************************************************************/
  206. PUBLIC BOOLEAN TM_IsRtcAbnormal(void);
  207. /* End; @Xueliang.Wang modify; CR10641; (2004-07-14) */
  208. /**---------------------------------------------------------------------------*
  209. ** Compiler Flag *
  210. **---------------------------------------------------------------------------*/
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #endif // _DAL_TIME_H