al_time.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /**
  2. * Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved.
  3. *
  4. * @file
  5. *
  6. * @brief The header file of al time module
  7. *
  8. */
  9. #ifndef _AL_TIME_H_
  10. #define _AL_TIME_H_
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #include "al_basictypes.h"
  15. /**
  16. * @brief define the default value of year
  17. *
  18. */
  19. #define DEFAULT_YEAR (2000)
  20. /**
  21. * @brief define the default value of month
  22. *
  23. */
  24. #define DEFAULT_MONTH (1)
  25. /**
  26. * @brief define the default value of day
  27. *
  28. */
  29. #define DEFAULT_DAY (1)
  30. /**
  31. * @brief define the default value of hour
  32. *
  33. */
  34. #define DEFAULT_HOUR (0)
  35. /**
  36. * @brief define the default value of minute
  37. *
  38. */
  39. #define DEFAULT_MIN (0)
  40. /**
  41. * @brief define the default value of second
  42. *
  43. */
  44. #define DEFAULT_SECOND (0)
  45. /**
  46. * @brief GMT offset mode
  47. *
  48. */
  49. typedef enum
  50. {
  51. AL_TIME_GMT_OFFSET_ZERO = 24,
  52. AL_TIME_GMT_OFFSET_AUTO = 49,
  53. AL_TIME_GMT_OFFSET_MAX = 50,
  54. } AL_Time_GMT_OffSet_t;
  55. /**
  56. * @brief Day light saving mode
  57. *
  58. */
  59. typedef enum {
  60. AL_TIME_DST_OFF = 0,
  61. AL_TIME_DST_ON,
  62. AL_TIME_DST_MAX,
  63. } AL_Time_DstMode_t;
  64. /**
  65. * @brief System time is obtained from where?
  66. *
  67. */
  68. typedef enum _al_time_SyncMode_
  69. {
  70. AL_TIME_SyncMode_Manual = 0,
  71. AL_TIME_SyncMode_Auto, /* get systime time from TOT */
  72. AL_TIME_SyncMode_MAX,
  73. }AL_Time_SyncMode_e;
  74. /**
  75. * @brief al time format including year, month, day, hour, min and second
  76. *
  77. */
  78. typedef struct _AL_Time_t
  79. {
  80. al_uint16 Year; /*!< \brief year */
  81. al_uint8 Month; /*!< \brief month */
  82. al_uint8 Day; /*!< \brief day */
  83. al_uint8 Hour; /*!< \brief hour */
  84. al_uint8 Min; /*!< \brief minute */
  85. al_uint8 Sec; /*!< \brief second */
  86. } AL_Time_t;
  87. /**
  88. * @brief Data structure for al time module to get time zone, DST, etc
  89. *
  90. */
  91. typedef struct _AL_Time_Context_t
  92. {
  93. al_uint8 Timezone;
  94. al_uint8 DST;
  95. al_uint8 Param1;
  96. al_uint8 Param2;
  97. } AL_Time_Context_t;
  98. /**
  99. * @brief Callback function prototype to get context
  100. *
  101. */
  102. typedef AL_Return_t (* AL_Time_GetConext)(AL_Time_Context_t * pstContext);
  103. /**
  104. * === Miscellaneous Time Operation===
  105. */
  106. /**
  107. * @brief Called to update system time periodically.
  108. *
  109. * This API is used to update the system time every second, and check
  110. * the available timer and post message to its SM if timeout happened
  111. *
  112. * @param none
  113. *
  114. * @retval None
  115. */
  116. void AL_Time_Timeout(void);
  117. /**
  118. * @brief To reset system time when user change country.
  119. *
  120. * @note This API is used to reset system time when change country.
  121. *
  122. * @param none
  123. *
  124. * @retval AL_SUCCESS means success
  125. */
  126. AL_Return_t AL_Time_Reset(void);
  127. /**
  128. * @brief This API is used to get days by the requested month and year
  129. *
  130. * @param u16Year year
  131. *
  132. * @param u8Month Month
  133. *
  134. * @retval None
  135. */
  136. al_uint8 AL_Time_GetDayByMonth(al_uint16 u16Year, al_uint8 u8Month);
  137. /**
  138. * @brief This API is used to get GMT time offset, which is also affected by DST
  139. *
  140. * @param None
  141. *
  142. * @retval AL_SUCCESS means succss. AL_FAILURE means failed.
  143. */
  144. al_int32 AL_Time_GetGMTOffset(void);
  145. /**
  146. * @brief This API is used to set next time offset value which is used for tot update
  147. *
  148. * @param None
  149. *
  150. * @retval AL_SUCCESS means succss. AL_FAILURE means failed.
  151. */
  152. al_int32 AL_Time_GetNextGMTOffset(void);
  153. /**
  154. * @brief This API is used to get time offset
  155. *
  156. * @param pTimeOffset Time offset
  157. *
  158. * @retval None
  159. */
  160. void AL_Time_GetTimeOffset(al_int32 *pTimeOffset);
  161. /**
  162. * @brief Get total secs from 1970/01/01
  163. *
  164. * @param CurTimeInSec Get total secs from 1970/01/01
  165. *
  166. * @retval AL_SUCCESS means success
  167. */
  168. AL_Return_t AL_Time_GetCurTimeInSecs(al_uint32 *CurTimeInSec);
  169. /**
  170. * @brief This API is used to get system date in the form of Y,M,D, this date is affected by GMT offset
  171. *
  172. * @param pusYear MJD
  173. *
  174. * @param pucMonth year
  175. *
  176. * @param pucDay month
  177. *
  178. * @retval None
  179. */
  180. void AL_Time_GetDate(al_uint16 *pusYear, al_uint8 *pucMonth, al_uint8 *pucDay);
  181. /**
  182. * @brief This API is used to get system time in the form of Hour,Min,Second, this value is affected by GMT offset
  183. *
  184. * @param pucHour Hour
  185. *
  186. * @param pucMin Minite
  187. *
  188. * @param pucSec Second
  189. *
  190. * @retval None
  191. */
  192. void AL_Time_GetTime(al_uint8 *pucHour, al_uint8 *pucMin, al_uint8 *pucSec);
  193. /**
  194. * @brief This API is used to get current system time has been updated by ts or not after power on
  195. *
  196. * @retval g_bDateUpdated
  197. */
  198. al_bool AL_Time_GetDateBeUpdated(void);
  199. /**
  200. * === MJD Time Operation===
  201. */
  202. /**
  203. * @brief :This API is used to get system date in the form of MJD, this date is affected by GMT offset
  204. *
  205. * @param None
  206. *
  207. * @retval MJD
  208. */
  209. al_uint32 AL_Time_GetMjd(void);
  210. /**
  211. * @brief :This API is used to get system date in the form of MJD, this date is not affected by GMT offset
  212. *
  213. * @param None
  214. *
  215. * @retval None
  216. */
  217. al_uint32 AL_Time_GetRawMjd(void);
  218. /**
  219. * @brief This API is used to get system time in the form of Hour,Min,Second
  220. *
  221. * @param pucHour Hour
  222. *
  223. * @param pucMin Minite
  224. *
  225. * @param pucSec Second
  226. *
  227. * @retval None
  228. */
  229. void AL_Time_GetRawTime(al_uint8 * pu8Hour, al_uint8 * pu8Min, al_uint8 * pu8Sec);
  230. /**
  231. * @brief This API is used to translate date from MJD format to YMD format
  232. *
  233. * @param uiMjd MJD
  234. *
  235. * @param pusYear year
  236. *
  237. * @param pucMonth month
  238. *
  239. * @param pucDay day
  240. *
  241. * @retval al_true means succss. al_false means failed.
  242. */
  243. al_bool AL_Time_MjdToYmd(al_uint32 uiMjd, al_uint16 *pusYear, al_uint8 *pucMonth, al_uint8 *pucDay);
  244. /**
  245. * @brief This API is used to translate date from YMD format to MJD format
  246. *
  247. * @param usYear Year
  248. *
  249. * @param ucMonth Month
  250. *
  251. * @param ucDay Day
  252. *
  253. * @retval MJD
  254. */
  255. al_uint32 AL_Time_YmdToMjd(al_uint16 usYear, al_uint8 ucMonth, al_uint8 ucDay);
  256. /**
  257. * @brief :This API is used to get system time in seconds, this value should be less
  258. * then 86400 (= 60*60*24), this value is not affected by GMT offset
  259. *
  260. * @param None
  261. *
  262. * @retval Raw second
  263. */
  264. al_uint32 AL_Time_GetRawSecond(void);
  265. /**
  266. * === Date And Seconds Transfer Operation ===
  267. */
  268. /**
  269. * @brief Translate date to secs(from 1970/01/01)
  270. *
  271. * @param p_RTCDate Date
  272. *
  273. * @param p_u32secs Total Seconds
  274. *
  275. * @retval AL_SUCCESS means success
  276. */
  277. AL_Return_t AL_Time_DateToSecs(const AL_Time_t *p_RTCDate, al_uint32 *p_u32secs);
  278. /**
  279. * @brief Translate date to secs(from 1970/01/01)
  280. *
  281. * @param p_RTCDate Date
  282. *
  283. * @param p_u32secs Total Seconds from 1970/01/01
  284. *
  285. * @retval AL_SUCCESS means success
  286. */
  287. AL_Return_t AL_Time_Secs2Date(const al_uint32 *p_u32secs, AL_Time_t *p_RTCDate);
  288. /**
  289. * @brief This API is used to set time dst
  290. *
  291. * @param dTimeDST time dst applied to
  292. *
  293. * @retval None
  294. */
  295. void AL_Time_SetTimeDST(al_uint32 dTimeDST);
  296. /**
  297. * @brief This API is used to set time offset
  298. *
  299. * @param iTimeOffset time offset applied to
  300. *
  301. * @retval None
  302. */
  303. void AL_Time_SetTimeOffset(al_int32 iTimeOffset);
  304. /**
  305. * @brief This API is used to set current system time when boot up
  306. *
  307. * @param None
  308. *
  309. * @retval None
  310. */
  311. void AL_Time_BootOnUpdateTime(void);
  312. /**
  313. * @brief This API is used to update RTC
  314. *
  315. * @param None
  316. *
  317. * @retval None
  318. */
  319. void AL_Time_UpdateRTC(void);
  320. /**
  321. * @brief This API is set system time which user set by manual
  322. *
  323. * @param None
  324. *
  325. * @retval None
  326. */
  327. AL_Return_t AL_Time_SetSystimefromManual(AL_Time_t* stTime, al_bool bSync);
  328. /**
  329. * @brief This API is get system time which user set by manual
  330. *
  331. * @param None
  332. *
  333. * @retval None
  334. */
  335. AL_Return_t AL_Time_GetSystimefromManual(AL_Time_t* stTime);
  336. /**
  337. * @brief This API is used to update RTC
  338. *
  339. * @param None
  340. *
  341. * @retval g_SyncMode
  342. */
  343. AL_Time_SyncMode_e AL_Time_GetSyncMode(void);
  344. /**
  345. * @brief This API is get Sync mode
  346. *
  347. * @param AL_TIME_SyncMode_Manual - system time from menu
  348. * AL_TIME_SyncMode_Auto - system time from TOT/TDT
  349. * @retval None
  350. */
  351. AL_Return_t AL_Time_SetSyncMode(AL_Time_SyncMode_e mode);
  352. int AL_Time_GetTimeZoneOffset();
  353. AL_Return_t AL_Time_GetRawTimeInSecs(al_uint32 *CurTimeInSec);
  354. AL_Return_t AL_Time_Get_NTPTime();
  355. #ifdef __cplusplus
  356. }
  357. #endif
  358. #endif /* _AL_TIME_H_ */