Ftm_Gpt_Ip.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 FTM_GPT_IP_H
  25. #define FTM_GPT_IP_H
  26. /**
  27. * @file Ftm_Gpt_Ip.h
  28. *
  29. * @addtogroup ftm_ip FTM 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 "Ftm_Gpt_Ip_Types.h"
  43. #include "Ftm_Gpt_Ip_Cfg.h"
  44. #include "OsIf.h"
  45. #include "Mcal.h"
  46. #include "SchM_Gpt.h"
  47. #if FTM_GPT_IP_DEV_ERROR_DETECT == STD_ON
  48. #include "Devassert.h"
  49. #endif
  50. #if (FTM_GPT_IP_ENABLE_USER_MODE_SUPPORT == STD_ON)
  51. #include "Reg_eSys.h"
  52. #endif
  53. /*==================================================================================================
  54. * SOURCE FILE VERSION INFORMATION
  55. ==================================================================================================*/
  56. /**
  57. * @internal
  58. * @brief Defines used for file version checks
  59. */
  60. #define FTM_GPT_IP_VENDOR_ID 43
  61. #define FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION 4
  62. #define FTM_GPT_IP_AR_RELEASE_MINOR_VERSION 4
  63. #define FTM_GPT_IP_AR_RELEASE_REVISION_VERSION 0
  64. #define FTM_GPT_IP_SW_MAJOR_VERSION 1
  65. #define FTM_GPT_IP_SW_MINOR_VERSION 0
  66. #define FTM_GPT_IP_SW_PATCH_VERSION 0
  67. /*==================================================================================================
  68. * FILE VERSION CHECKS
  69. ==================================================================================================*/
  70. #if (FTM_GPT_IP_VENDOR_ID != FTM_GPT_IP_TYPES_VENDOR_ID)
  71. #error "Ftm_Gpt_Ip.h and Ftm_Gpt_Ip_Types.h have different vendor ids"
  72. #endif
  73. /* Check if header file and Gpt header file are of the same Autosar version */
  74. #if ((FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION != FTM_GPT_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
  75. (FTM_GPT_IP_AR_RELEASE_MINOR_VERSION != FTM_GPT_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
  76. (FTM_GPT_IP_AR_RELEASE_REVISION_VERSION != FTM_GPT_IP_TYPES_AR_RELEASE_REVISION_VERSION) \
  77. )
  78. #error "AutoSar Version Numbers of Ftm_Gpt_Ip.h and Ftm_Gpt_Ip_Types.h are different"
  79. #endif
  80. /* Check if source file and GPT header file are of the same Software version */
  81. #if ((FTM_GPT_IP_SW_MAJOR_VERSION != FTM_GPT_IP_TYPES_SW_MAJOR_VERSION) || \
  82. (FTM_GPT_IP_SW_MINOR_VERSION != FTM_GPT_IP_TYPES_SW_MINOR_VERSION) || \
  83. (FTM_GPT_IP_SW_PATCH_VERSION != FTM_GPT_IP_TYPES_SW_PATCH_VERSION) \
  84. )
  85. #error "Software Version Numbers of Ftm_Gpt_Ip.h and Ftm_Gpt_Ip_Types.h are different"
  86. #endif
  87. #if (FTM_GPT_IP_VENDOR_ID != FTM_GPT_IP_VENDOR_ID_CFG)
  88. #error "Ftm_Gpt_Ip.h and Ftm_Gpt_Ip_Cfg.h have different vendor ids"
  89. #endif
  90. /* Check if Ftm_Gpt_Ip header file and Ftm_Gpt_Ip_Cfg header file are of the same Autosar version */
  91. #if ((FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION != FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION_CFG) || \
  92. (FTM_GPT_IP_AR_RELEASE_MINOR_VERSION != FTM_GPT_IP_AR_RELEASE_MINOR_VERSION_CFG) || \
  93. (FTM_GPT_IP_AR_RELEASE_REVISION_VERSION != FTM_GPT_IP_AR_RELEASE_REVISION_VERSION_CFG) \
  94. )
  95. #error "AutoSar Version Numbers of Ftm_Gpt_Ip.h and Ftm_Gpt_Ip_Cfg.h are different"
  96. #endif
  97. /* Check if Ftm_Gpt_Ip file and Ftm_Gpt_Ip_Cfg header file are of the same Software version */
  98. #if ((FTM_GPT_IP_SW_MAJOR_VERSION != FTM_GPT_IP_SW_MAJOR_VERSION_CFG) || \
  99. (FTM_GPT_IP_SW_MINOR_VERSION != FTM_GPT_IP_SW_MINOR_VERSION_CFG) || \
  100. (FTM_GPT_IP_SW_PATCH_VERSION != FTM_GPT_IP_SW_PATCH_VERSION_CFG) \
  101. )
  102. #error "Software Version Numbers of Ftm_Gpt_Ip.h and Ftm_Gpt_Ip_Cfg.h are different"
  103. #endif
  104. #if (FTM_GPT_IP_ENABLE_USER_MODE_SUPPORT == STD_ON)
  105. /* Check if header file and StandardTypes.h file are of the same Autosar version */
  106. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  107. #if ((FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION != REG_ESYS_AR_RELEASE_MAJOR_VERSION) || \
  108. (FTM_GPT_IP_AR_RELEASE_MINOR_VERSION != REG_ESYS_AR_RELEASE_MINOR_VERSION))
  109. #error "AutoSar Version Numbers of Ftm_Gpt_Ip.h and Reg_eSys.h are different"
  110. #endif
  111. #endif
  112. #endif
  113. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  114. #if ((FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION != SCHM_GPT_AR_RELEASE_MAJOR_VERSION) || \
  115. (FTM_GPT_IP_AR_RELEASE_MINOR_VERSION != SCHM_GPT_AR_RELEASE_MINOR_VERSION))
  116. #error "AutoSar Version Numbers of Ftm_Gpt_Ip.h and SchM_Gpt.h are different"
  117. #endif
  118. /* Check if this header file and OsIf.h file are of the same Autosar version */
  119. #if ((FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  120. (FTM_GPT_IP_AR_RELEASE_MINOR_VERSION != OSIF_AR_RELEASE_MINOR_VERSION))
  121. #error "AutoSar Version Numbers of Ftm_Gpt_Ip.h and OsIf.h are different"
  122. #endif
  123. #endif
  124. /* Checks against Devassert.h */
  125. #if FTM_GPT_IP_DEV_ERROR_DETECT == STD_ON
  126. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  127. #if ((FTM_GPT_IP_AR_RELEASE_MAJOR_VERSION != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  128. (FTM_GPT_IP_AR_RELEASE_MINOR_VERSION != DEVASSERT_AR_RELEASE_MINOR_VERSION))
  129. #error "AutoSar Version Numbers of Ftm_Gpt_Ip.h and Devassert.h are different"
  130. #endif
  131. #endif
  132. #endif /* STD_ON == FTM_GPT_IP_DEV_ERROR_DETECT */
  133. /*==================================================================================================
  134. * CONSTANT-LIKE DEFINES
  135. ==================================================================================================*/
  136. /*==================================================================================================
  137. * FUNCTION-LIKE DEFINES(MACROS)
  138. ==================================================================================================*/
  139. #if (FTM_GPT_IP_USED == STD_ON)
  140. /**
  141. * @internal
  142. * @brief The total FTM timer channel
  143. */
  144. #define FTM_CHANNEL_COUNT FTM_CONTROLS_COUNT
  145. /**
  146. * @internal
  147. * @brief Counter max value
  148. */
  149. #define FTM_CNT_MAX_VALUE 0x0000FFFFU
  150. /*==================================================================================================
  151. * ENUMS
  152. ==================================================================================================*/
  153. /*==================================================================================================
  154. * STRUCTURES AND OTHER TYPEDEFS
  155. ==================================================================================================*/
  156. /*==================================================================================================
  157. * GLOBAL VARIABLE DECLARATIONS
  158. ==================================================================================================*/
  159. /**
  160. * @internal
  161. * @brief MemMap section
  162. */
  163. #define GPT_START_SEC_VAR_CLEARED_32
  164. #include "Gpt_MemMap.h"
  165. /**
  166. * @internal
  167. * @brief Global array variable used to store the runtime target time value.
  168. */
  169. extern uint32 Ftm_Gpt_Ip_u32TargetValue[FTM_INSTANCE_COUNT][FTM_CONTROLS_COUNT];
  170. /**
  171. * @internal
  172. * @brief MemMap section
  173. */
  174. #define GPT_STOP_SEC_VAR_CLEARED_32
  175. #include "Gpt_MemMap.h"
  176. /*==================================================================================================
  177. * FUNCTION PROTOTYPES
  178. ==================================================================================================*/
  179. /**
  180. * @internal
  181. * @brief MemMap section
  182. */
  183. #define GPT_START_SEC_CODE
  184. #include "Gpt_MemMap.h"
  185. uint32 Ftm_Gpt_Ip_GetCounter(uint8 instance);
  186. uint32 Ftm_Gpt_Ip_GetCompareValue(uint8 instance, uint8 channel);
  187. uint32 Ftm_Gpt_Ip_GetInterruptFlag(uint8 instance, uint8 channel);
  188. extern FTM_Type * const ftmGptBase[FTM_INSTANCE_COUNT];
  189. /*================================================================================================*/
  190. /*================================================================================================*/
  191. /**
  192. * @brief Function Name : Ftm_Gpt_Ip_Init
  193. * @details Initializes the FTM instance. This functions is called for each FTM hardware Instance.
  194. *
  195. * @param[in] instance FTM hardware instance number
  196. * @param[in] configPtr Pointer to a selected configuration structure
  197. * @return void
  198. * @pre The data structure including the configuration set required for initializing the GPT driver
  199. */
  200. void Ftm_Gpt_Ip_Init(uint8 instance, const Ftm_Gpt_Ip_InstanceConfigType *configPtr);
  201. /*================================================================================================*/
  202. /**
  203. * @brief Function Name : Ftm_Gpt_Ip_InitChannel
  204. * @details Initializes the FTM channels. This functions is called for each FTM hardware channel and:
  205. *
  206. * @param[in] instance FTM hardware instance number
  207. * @param[in] configPtr Pointer to a selected configuration structure
  208. * @return void
  209. * @pre The data structure including the configuration set required for initializing the GPT driver
  210. */
  211. void Ftm_Gpt_Ip_InitChannel(uint8 instance, const Ftm_Gpt_Ip_ChannelConfigType *configPtr);
  212. /*================================================================================================*/
  213. /**
  214. * @brief Function Name : Ftm_Gpt_Ip_Deinit
  215. * @details De-Initializes the FTM module. This functions is called for each FTM hardware instance and:
  216. * - resets all channels to default
  217. * - disables the timer compare interrupts corresponding to Ftm channel
  218. * - clears the timer compare interrupt flags corresponding to Ftm channel
  219. * - resets the counter register and the counter initial value register.
  220. * - resets the channel value register and the modulo register
  221. * - disables the freeze mode
  222. *
  223. * @param[in] instance FTM hardware instance number
  224. * @return void
  225. * @pre The data structure including the configuration set required for initializing the GPT driver.
  226. */
  227. void Ftm_Gpt_Ip_Deinit(uint8 instance);
  228. /*================================================================================================*/
  229. /**
  230. * @brief Function Name : Ftm_Gpt_Ip_StartCounting
  231. * @details This function is called for starting the Ftm timer channel
  232. *
  233. * @param[in] instance FTM hardware instance number
  234. * @param[in] channel Ftm channel
  235. * @param[in] compareValue Compare value
  236. * @return void
  237. * @pre The driver needs to be initialized. This function is called for starting the FTM timer channel.
  238. */
  239. void Ftm_Gpt_Ip_StartCounting(uint8 instance, uint8 channel, uint16 compareValue);
  240. /*================================================================================================*/
  241. /**
  242. * @brief Function Name : Ftm_Gpt_Ip_StartTimer
  243. * @details This function is called for setting a new start counter value and enables the FTM counter and
  244. * - sets the new counter value
  245. * - enables the FTM counter
  246. */
  247. void Ftm_Gpt_Ip_StartTimer(uint8 instance, uint16 counterValue);
  248. /*================================================================================================*/
  249. /**
  250. * @brief Function Name : Ftm_Gpt_Ip_StopTimer
  251. * @details This function is callded for stopping the Ftm counter.
  252. * - disables the FTM counter
  253. *
  254. * @param[in] instance FTM hardware instance
  255. * @return void
  256. * @pre The driver needs to be initialized. This function is called for stoping the FTM timer channel.
  257. */
  258. void Ftm_Gpt_Ip_StopTimer(uint8 instance);
  259. /*================================================================================================*/
  260. /**
  261. * @brief Function Name : Ftm_Gpt_Ip_EnableChannelInterrupt
  262. * @details This function allows enabling interrupt generation of timer channel
  263. * when timeout occurs
  264. *
  265. * @param[in] instance FTM hardware instance
  266. * @param[in] channel FTM hardware channel
  267. * @return void
  268. * @pre The driver needs to be initialized.
  269. */
  270. void Ftm_Gpt_Ip_EnableChannelInterrupt(uint8 instance, uint8 channel);
  271. /*================================================================================================*/
  272. /**
  273. * @brief Function Name : Ftm_Gpt_Ip_DisableChannelInterrupt
  274. * @details This function allows disabling interrupt generation of timer channel
  275. * when timeout occurs
  276. *
  277. * @param[in] instance FTM hardware instance
  278. * @param[in] channel FTM hardware channel
  279. * @return void
  280. * @pre The driver needs to be initialized.
  281. */
  282. void Ftm_Gpt_Ip_DisableChannelInterrupt(uint8 instance, uint8 channel);
  283. /*================================================================================================*/
  284. /**
  285. * @brief Function Name : Ftm_Gpt_Ip_SetHalfCycleReloadPoint
  286. * @details Configures the value of the counter with half cycle of reload point.
  287. *
  288. * @param[in] instance FTM hardware instance
  289. * @param[in] reloadPoint Reload value
  290. * @return
  291. * @pre The driver needs to be initialized.
  292. */
  293. void Ftm_Gpt_Ip_SetHalfCycleReloadPoint(uint8 instance, uint16 reloadPoint);
  294. /*================================================================================================*/
  295. #if (FTM_GPT_IP_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON)
  296. /**
  297. * @brief The function changes the Ftm compare register value.
  298. * @details This function:
  299. * - Write next timeout to local variable
  300. *
  301. * @param[in] instance FTM hardware instance
  302. * @param[in] channel Channel
  303. * @param[in] value Channel timeout value
  304. * @return void
  305. * @pre The driver needs to be initialized.
  306. */
  307. void Ftm_Gpt_Ip_ChangeNextTimeoutValue(uint8 instance, uint8 channel, uint16 value);
  308. #endif/*FTM_GPT_IP_CHANGE_NEXT_TIMEOUT_VALUE*/
  309. /*================================================================================================*/
  310. #if (FTM_GPT_IP_SET_CLOCK_MODE == STD_ON)
  311. /**
  312. * @brief The function changes the FTM prescaler value.
  313. * @details This function sets the FTM prescaler based on the input mode.
  314. *
  315. * @param[in] instance FTM hardware instance
  316. * @param[in] prescalerMode FTM_GPT_IP_CLOCKMODE_NORMAL or FTM_GPT_IP_CLOCKMODE_ALTERNATE
  317. *
  318. * @return void
  319. * @pre The driver needs to be initialized.On/Off by the configuration parameter: GPT_DUAL_CLOCK_MODE
  320. * @implements Ftm_Gpt_Ip_SetClockMode_Activity
  321. */
  322. void Ftm_Gpt_Ip_SetClockMode(uint8 instance, Ftm_Gpt_Ip_ClockModeType prescalerMode);
  323. #endif/*FTM_GPT_IP_SET_CLOCK_MODE*/
  324. /*================================================================================================*/
  325. #if(FTM_GPT_IP_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  326. /**
  327. * @brief The function start the FTM channel.
  328. * @details This function start the FTM channel the input mode.
  329. *
  330. * @param[in] instance FTM hardware instance
  331. * @param[in] uPrescaler Prescaler
  332. * @param[in] bFreezeEnable Freezebit
  333. * @return void
  334. * @pre The driver needs to be initialized
  335. */
  336. void Ftm_Gpt_Ip_StartPredefTimer (uint8 instance,uint8 channel, uint8 uPrescaler, uint8 clocksource, boolean bFreezeEnable);
  337. /*================================================================================================*/
  338. /**
  339. * @brief The function stop the FTM channel.
  340. * @details This function stop the FTM channel.
  341. *
  342. * @param[in] channel FTM hardware channel
  343. * @param[in] instance FTM hardware instance
  344. *
  345. *
  346. * @return void
  347. * @pre The driver needs to be initialized
  348. */
  349. void Ftm_Gpt_Ip_StopPredefTimer (uint8 instance, uint8 channel);
  350. #endif/*FTM_GPT_IP_PREDEFTIMER_FUNCTIONALITY_API*/
  351. /**
  352. * @internal
  353. * @brief MemMap section
  354. */
  355. #define GPT_STOP_SEC_CODE
  356. #include "Gpt_MemMap.h"
  357. #endif/*FTM_GPT_IP_USED*/
  358. #ifdef __cplusplus
  359. }
  360. #endif
  361. /** @} */
  362. #endif/*FTM_GPT_IP_H*/