SRtc_Ip.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : Ftm_Srtc_Lptmr_LPit
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. #ifndef SRTC_IP_H
  25. #define SRTC_IP_H
  26. /**
  27. * @file SRtc_Ip.h
  28. *
  29. * @addtogroup srtc_ip Rtc IPL
  30. *
  31. * @{
  32. */
  33. #ifdef __cplusplus
  34. extern "C"{
  35. #endif
  36. /*==================================================================================================
  37. * INCLUDE FILES
  38. * 1) system and project includes
  39. * 2) needed interfaces from external units
  40. * 3) internal and external interfaces from this unit
  41. ==================================================================================================*/
  42. #include "SRtc_Ip_Types.h"
  43. #include "SRtc_Ip_Cfg.h"
  44. #include "OsIf.h"
  45. #include "Mcal.h"
  46. #if SRTC_IP_DEV_ERROR_DETECT == STD_ON
  47. #include "Devassert.h"
  48. #endif
  49. #include "SchM_Gpt.h"
  50. /*==================================================================================================
  51. * SOURCE FILE VERSION INFORMATION
  52. ==================================================================================================*/
  53. #define SRTC_IP_VENDOR_ID 43
  54. #define SRTC_IP_AR_RELEASE_MAJOR_VERSION 4
  55. #define SRTC_IP_AR_RELEASE_MINOR_VERSION 4
  56. #define SRTC_IP_AR_RELEASE_REVISION_VERSION 0
  57. #define SRTC_IP_SW_MAJOR_VERSION 1
  58. #define SRTC_IP_SW_MINOR_VERSION 0
  59. #define SRTC_IP_SW_PATCH_VERSION 0
  60. /*==================================================================================================
  61. * FILE VERSION CHECKS
  62. ==================================================================================================*/
  63. #if (SRTC_IP_VENDOR_ID != SRTC_IP_TYPES_VENDOR_ID)
  64. #error "SRtc_Ip.h and SRtc_Ip_Types.h have different vendor ids"
  65. #endif
  66. /* Check if header file and Gpt header file are of the same Autosar version */
  67. #if ((SRTC_IP_AR_RELEASE_MAJOR_VERSION != SRTC_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
  68. (SRTC_IP_AR_RELEASE_MINOR_VERSION != SRTC_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
  69. (SRTC_IP_AR_RELEASE_REVISION_VERSION != SRTC_IP_TYPES_AR_RELEASE_REVISION_VERSION) \
  70. )
  71. #error "AutoSar Version Numbers of SRtc_Ip.h and SRtc_Ip_Types.h are different"
  72. #endif
  73. /* Check if source file and GPT header file are of the same Software version */
  74. #if ((SRTC_IP_SW_MAJOR_VERSION != SRTC_IP_TYPES_SW_MAJOR_VERSION) || \
  75. (SRTC_IP_SW_MINOR_VERSION != SRTC_IP_TYPES_SW_MINOR_VERSION) || \
  76. (SRTC_IP_SW_PATCH_VERSION != SRTC_IP_TYPES_SW_PATCH_VERSION) \
  77. )
  78. #error "Software Version Numbers of SRtc_Ip.h and SRtc_Ip_Types.h are different"
  79. #endif
  80. #if (SRTC_IP_VENDOR_ID != SRTC_IP_VENDOR_ID_CFG)
  81. #error "SRtc_Ip.h and SRtc_Ip_Cfg.h have different vendor ids"
  82. #endif
  83. /* Check if RTC_IP header file and RTC_IP_Cfg header file are of the same Autosar version */
  84. #if ((SRTC_IP_AR_RELEASE_MAJOR_VERSION != SRTC_IP_AR_RELEASE_MAJOR_VERSION_CFG) || \
  85. (SRTC_IP_AR_RELEASE_MINOR_VERSION != SRTC_IP_AR_RELEASE_MINOR_VERSION_CFG) || \
  86. (SRTC_IP_AR_RELEASE_REVISION_VERSION != SRTC_IP_AR_RELEASE_REVISION_VERSION_CFG) \
  87. )
  88. #error "AutoSar Version Numbers of SRtc_Ip.h and SRtc_Ip_Cfg.h are different"
  89. #endif
  90. /* Check if RTC_IP file and RTC_IP_Cfg header file are of the same Software version */
  91. #if ((SRTC_IP_SW_MAJOR_VERSION != SRTC_IP_SW_MAJOR_VERSION_CFG) || \
  92. (SRTC_IP_SW_MINOR_VERSION != SRTC_IP_SW_MINOR_VERSION_CFG) || \
  93. (SRTC_IP_SW_PATCH_VERSION != SRTC_IP_SW_PATCH_VERSION_CFG) \
  94. )
  95. #error "Software Version Numbers of SRtc_Ip.h and SRtc_Ip_Cfg.h are different"
  96. #endif
  97. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  98. #if ((SRTC_IP_AR_RELEASE_MAJOR_VERSION != SCHM_GPT_AR_RELEASE_MAJOR_VERSION) || \
  99. (SRTC_IP_AR_RELEASE_MINOR_VERSION != SCHM_GPT_AR_RELEASE_MINOR_VERSION))
  100. #error "AutoSar Version Numbers of SRtc_Ip.h and SchM_Gpt.h are different"
  101. #endif
  102. /* Check if this header file and OsIf.h file are of the same Autosar version */
  103. #if ((SRTC_IP_AR_RELEASE_MAJOR_VERSION != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  104. (SRTC_IP_AR_RELEASE_MINOR_VERSION != OSIF_AR_RELEASE_MINOR_VERSION))
  105. #error "AutoSar Version Numbers of SRtc_Ip.h and OsIf.h are different"
  106. #endif
  107. #endif
  108. #if SRTC_IP_DEV_ERROR_DETECT == STD_ON
  109. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  110. #if ((SRTC_IP_AR_RELEASE_MAJOR_VERSION != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  111. (SRTC_IP_AR_RELEASE_MINOR_VERSION != DEVASSERT_AR_RELEASE_MINOR_VERSION))
  112. #error "AutoSar Version Numbers of SRtc_Ip.h and Devassert.h are different"
  113. #endif
  114. #endif
  115. #endif
  116. /*==================================================================================================
  117. * CONSTANTS
  118. ==================================================================================================*/
  119. /*==================================================================================================
  120. * DEFINES AND MACROS
  121. ==================================================================================================*/
  122. /*==================================================================================================
  123. * ENUMS
  124. ==================================================================================================*/
  125. /*==================================================================================================
  126. * STRUCTURES AND OTHER TYPEDEFS
  127. ==================================================================================================*/
  128. /*==================================================================================================
  129. * GLOBAL VARIABLE DECLARATIONS
  130. ==================================================================================================*/
  131. #if (SRTC_IP_USED == STD_ON)
  132. extern uint32 Srtc_Ip_u32TargetValue;
  133. /*==================================================================================================
  134. * FUNCTION PROTOTYPES
  135. ==================================================================================================*/
  136. #define GPT_START_SEC_CODE
  137. #include "Gpt_MemMap.h"
  138. uint32 Srtc_Ip_GetStatusFlags(uint8 instance, Srtc_Ip_InterruptType interruptMode);
  139. uint32 Srtc_Ip_GetTimeSecondsRegister(uint8 instance);
  140. uint32 Srtc_Ip_GetTimeAlarmRegister(uint8 instance);
  141. /*================================================================================================*/
  142. /**
  143. *
  144. * @brief SRtc Driver function
  145. * @details This function:
  146. * - will convert seconds into time-date format.
  147. *
  148. * @param[in] seconds number of seconds
  149. * @param[in] *timeDate pointer to configuration
  150. * @return void
  151. * @pre The driver needs to be initialized.
  152. *
  153. */
  154. void Srtc_Ip_ConvertSecondsToTimeDate(const uint32 *seconds,
  155. Srtc_Ip_TimedateType * const timeDate);
  156. /*================================================================================================*/
  157. /**
  158. *
  159. * @brief SRtc Driver function
  160. * @details This function:
  161. * - will convert time-date into seconds.
  162. *
  163. * @param[in] seconds number of seconds
  164. * @param[in] *timeDate pointer to configuration
  165. * @return void
  166. * @pre The driver needs to be initialized.
  167. *
  168. */
  169. void Srtc_Ip_ConvertTimeDateToSeconds(const Srtc_Ip_TimedateType *timeDate,
  170. uint32 * const seconds);
  171. /*================================================================================================*/
  172. /**
  173. * @brief SRtc driver initialization function for SRtc module.
  174. * @details This function:
  175. * - Disables the time counter
  176. * - Disables all interupt modes
  177. * - Clears Time Invalid Flag
  178. * - Selects source Clock
  179. * - If compensation support is enabled sets the configured values
  180. * - Sets channel state variables
  181. *
  182. * @param[in] instance hw instance
  183. * @param[in] *config pointer to configuration
  184. * @return void
  185. * @pre The data structure including the configuration set required for initializing the driver
  186. *
  187. */
  188. void Srtc_Ip_Init(uint8 instance, const Srtc_Ip_ConfigType *config);
  189. /*================================================================================================*/
  190. /**
  191. * @brief SRtc driver de-initialization function
  192. * @details This function:
  193. * - Performs a software reset
  194. * - Clears global variables
  195. * @param[in] instance Rtc hw instance
  196. * @return void
  197. * @pre The data structure including the configuration set required for initializing the GPT driver
  198. *
  199. */
  200. void Srtc_Ip_DeInit(uint8 instance);
  201. /*================================================================================================*/
  202. /**
  203. * @brief SRtc Driver function for starting the Rtc counter.
  204. * @details This function:
  205. * - Enables the counter
  206. * @param[in] instance Rtc hw instance
  207. * @return Srtc_Ip_StatusType status error
  208. * @pre The driver needs to be initialized.
  209. *
  210. */
  211. Srtc_Ip_StatusType Srtc_Ip_StartCounter(uint8 instance);
  212. /*================================================================================================*/
  213. /**
  214. * @brief SRtc Driver function for stopping the Rtc counter.
  215. * @details This function:
  216. * - Disables Time Alaram Interrupt
  217. * - Clears interrupt flag
  218. * - Disables the counter
  219. * @param[in] instance Rtc hw instance
  220. * @return Srtc_Ip_StatusType status error
  221. * @pre The driver needs to be initialized.
  222. *
  223. */
  224. Srtc_Ip_StatusType Srtc_Ip_StopCounter(uint8 instance);
  225. /*================================================================================================*/
  226. /**
  227. * @brief SRtc Driver function for starting the Rtc timer channel with a timeout value.
  228. * @details This function:
  229. * - Disables counter
  230. * - Disables Time Alaram Interrupt
  231. * - Gets Time Seconds Register value
  232. * - Calcutates new compare value
  233. * - Sets Time Alarm Register
  234. * - Enables Time Alaram Interrupt
  235. * - Enables counter
  236. *
  237. * @param[in] instance Rtc hw instance
  238. * value channel timeout value
  239. * @return void
  240. * @pre The data structure including the configuration set required for initializing the GPT driver
  241. *
  242. */
  243. void Srtc_Ip_StartTimer(uint8 instance, uint32 value);
  244. /*================================================================================================*/
  245. /**
  246. * @brief SRtc Driver function for enabling interrupt for RTC channel
  247. * @details This function:
  248. * - Enables Interrupt for RTC channel based on selected mode
  249. *
  250. * @param[in] instance Rtc hw instance
  251. * interruptMode Rtc hw interrupt mode
  252. * @return void
  253. * @pre The driver needs to be initialized.
  254. *
  255. */
  256. void Srtc_Ip_EnableInterrupt(uint8 instance, Srtc_Ip_InterruptType interruptMode);
  257. /*================================================================================================*/
  258. /**
  259. *
  260. * @brief SRtc Driver function for Disable Interrupt for RTC channel
  261. * @details This function:
  262. * - Disable Interrupt for RTC channel based on selected mode
  263. *
  264. * @param[in] instance Rtc hw instance
  265. * @return void
  266. * @pre The driver needs to be initialized.
  267. *
  268. */
  269. void Srtc_Ip_DisableInterrupt(uint8 instance, Srtc_Ip_InterruptType interruptMode);
  270. /*================================================================================================*/
  271. /**
  272. *
  273. * @brief SRtc Driver function
  274. * @details This function:
  275. * - Sets the date passed by the user.
  276. *
  277. * @param[in] instance SRtc hw instance
  278. * @param[in] *timeDate pointer to configuration
  279. * @return Srtc_Ip_StatusType status error
  280. * @pre The driver needs to be initialized.
  281. *
  282. */
  283. Srtc_Ip_StatusType Srtc_Ip_SetTimeDate(uint8 instance,
  284. const Srtc_Ip_TimedateType *timeDate);
  285. /*================================================================================================*/
  286. /**
  287. *
  288. * @brief SRtc Driver function
  289. * @details This function:
  290. * - Gets the current time and date and it will
  291. * store in the state structure.
  292. *
  293. * @param[in] instance sRtc hw instance
  294. * @param[in] *timeDate pointer to configuration
  295. * @return Srtc_Ip_StatusType status error
  296. * @pre The driver needs to be initialized.
  297. *
  298. */
  299. Srtc_Ip_StatusType Srtc_Ip_GetTimeDate(uint8 instance,
  300. Srtc_Ip_TimedateType * const timeDate);
  301. /*================================================================================================*/
  302. /**
  303. *
  304. * @brief SRtc Driver function
  305. * @details This function:
  306. * - Configures the alarm based on the
  307. * configuration structure passed by the user.
  308. * When using alarm that are configured to be repetitive,
  309. * enable the interrupt. Otherwise the repeat function will
  310. * not work.
  311. *
  312. * @param[in] instance Rtc hw instance
  313. * @param[in] *alarmConfig pointer to configuration
  314. * @return Srtc_Ip_StatusType status error
  315. * @pre The driver needs to be initialized.
  316. *
  317. */
  318. Srtc_Ip_StatusType Srtc_Ip_ConfigureAlarm(uint8 instance,
  319. const Srtc_Ip_AlarmConfigType *alarmConfig);
  320. /*================================================================================================*/
  321. /**
  322. *
  323. * @brief SRtc Driver function
  324. * @details This function:
  325. * - Configures the Time Seconds Interrupt with the Seconds interrupt Configuration Type.
  326. * @param[in] instance Rtc hw instance
  327. * @param[in] occursFrequency how often seconds interrupt occurs
  328. * @return Srtc_Ip_StatusType status error
  329. * @pre The driver needs to be initialized.
  330. *
  331. */
  332. Srtc_Ip_StatusType Srtc_Ip_ConfigureSecondsInterrupt(uint8 instance,
  333. Srtc_Ip_SecIntFreqType occursFrequency);
  334. /*================================================================================================*/
  335. #if (STD_ON == SRTC_IP_ENABLE_LOCK_REGISTER_API)
  336. /**
  337. *
  338. * @brief SRtc Driver function
  339. * @details This function:
  340. * - Configures register lock for the corresponding
  341. * RTC instance. Remember that all the registers are unlocked
  342. * only by software reset or power on reset.
  343. * (Except for CR that is unlocked only by POR).
  344. * @param[in] instance Rtc hw instance
  345. * @param[in] lockRegister register that will be locked
  346. * @return Srtc_Ip_StatusType status error
  347. *
  348. */
  349. Srtc_Ip_StatusType Srtc_Ip_ConfigureLockRegister(uint8 instance,
  350. Srtc_Ip_LockRegConfigType * const lockRegister);
  351. #endif
  352. #define GPT_STOP_SEC_CODE
  353. #include "Gpt_MemMap.h"
  354. #endif /* SRTC_IP_USED == STD_ON */
  355. #ifdef __cplusplus
  356. }
  357. #endif
  358. /** @} */
  359. #endif /* SRTC_IP_H*/