Flexio_Uart_Ip_HwAccess.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : FLEXIO
  5. * Dependencies :
  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 FLEXIO_UART_IP_HWACCESS_H__
  25. #define FLEXIO_UART_IP_HWACCESS_H__
  26. /**
  27. * @file
  28. * @internal
  29. * @defgroup flexio_ip Flexio IPL
  30. * @addtogroup flexio_ip Flexio IPL
  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 "StandardTypes.h"
  43. #include "Flexio_Uart_Ip_Types.h"
  44. #include "OsIf.h"
  45. #ifdef FLEXIO_UART_IP_IS_USING
  46. #if (FLEXIO_UART_IP_IS_USING == STD_ON)
  47. #include "Flexio_Mcl_Ip_HwAccess.h"
  48. #endif /* (FLEXIO_UART_IP_IS_USING == STD_ON) */
  49. #endif /* #ifdef FLEXIO_UART_IP_IS_USING */
  50. /*==================================================================================================
  51. * SOURCE FILE VERSION INFORMATION
  52. ==================================================================================================*/
  53. #define FLEXIO_UART_IP_HWACCESS_VENDOR_ID 43
  54. #define FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION 4
  55. #define FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION 4
  56. #define FLEXIO_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION 0
  57. #define FLEXIO_UART_IP_HWACCESS_SW_MAJOR_VERSION 1
  58. #define FLEXIO_UART_IP_HWACCESS_SW_MINOR_VERSION 0
  59. #define FLEXIO_UART_IP_HWACCESS_SW_PATCH_VERSION 0
  60. /* Checks against Flexio_Uart_Ip_Types.h */
  61. #if (FLEXIO_UART_IP_HWACCESS_VENDOR_ID != FLEXIO_UART_IP_TYPES_VENDOR_ID)
  62. #error "Flexio_Uart_Ip_HwAccess.h and Flexio_Uart_Ip_Types.h have different vendor ids"
  63. #endif
  64. #if ((FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != FLEXIO_UART_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
  65. (FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != FLEXIO_UART_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
  66. (FLEXIO_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION != FLEXIO_UART_IP_TYPES_AR_RELEASE_REVISION_VERSION))
  67. #error "AUTOSAR Version Numbers of Flexio_Uart_Ip_HwAccess.h and Flexio_Uart_Ip_Types.h are different"
  68. #endif
  69. #if ((FLEXIO_UART_IP_HWACCESS_SW_MAJOR_VERSION != FLEXIO_UART_IP_TYPES_SW_MAJOR_VERSION) || \
  70. (FLEXIO_UART_IP_HWACCESS_SW_MINOR_VERSION != FLEXIO_UART_IP_TYPES_SW_MINOR_VERSION) || \
  71. (FLEXIO_UART_IP_HWACCESS_SW_PATCH_VERSION != FLEXIO_UART_IP_TYPES_SW_PATCH_VERSION))
  72. #error "Software Version Numbers of Flexio_Uart_Ip_HwAccess.h and Flexio_Uart_Ip_Types.h are different"
  73. #endif
  74. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  75. /* Check if current file and StandardTypes.h header file are of the same Autosar version */
  76. #if ((FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
  77. (FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION))
  78. #error "Flexio_Uart_Ip_HwAccess.h and StandardTypes.h are different"
  79. #endif
  80. /* Check if current file and OsIf.h header file are of the same Autosar version */
  81. #if ((FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  82. (FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != OSIF_AR_RELEASE_MINOR_VERSION))
  83. #error "Flexio_Uart_Ip_HwAccess.h and OsIf.h are different"
  84. #endif
  85. #ifdef FLEXIO_UART_IP_IS_USING
  86. #if (FLEXIO_UART_IP_IS_USING == STD_ON)
  87. /* Checks against Flexio_Mcl_Ip_HwAccess.h */
  88. #if ((FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != FLEXIO_IP_HW_ACCESS_AR_RELEASE_MAJOR_VERSION_H) || \
  89. (FLEXIO_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != FLEXIO_IP_HW_ACCESS_AR_RELEASE_MINOR_VERSION_H))
  90. #error "AUTOSAR Version Numbers of Flexio_Uart_Ip_HwAccess.h and Flexio_Mcl_Ip_HwAccess.h are different"
  91. #endif
  92. #endif /* (FLEXIO_UART_IP_IS_USING == STD_ON) */
  93. #endif /* #ifdef FLEXIO_UART_IP_IS_USING */
  94. #endif
  95. #ifdef FLEXIO_UART_IP_IS_USING
  96. #if (FLEXIO_UART_IP_IS_USING == STD_ON)
  97. /*******************************************************************************
  98. * Definitions
  99. ******************************************************************************/
  100. /*******************************************************************************
  101. * API
  102. ******************************************************************************/
  103. #define UART_START_SEC_CODE
  104. #include "Uart_MemMap.h"
  105. /*
  106. * This function sets the following configurations for the specified Shifter:
  107. * start bit, stop bit, input Source
  108. */
  109. static inline void Flexio_Uart_Ip_SetShifterConfig(FLEXIO_Type * Base,
  110. uint8 Shifter,
  111. Flexio_Mcl_Ip_ShifterStartType Start,
  112. Flexio_Mcl_Ip_ShifterStopType Stop,
  113. Flexio_Mcl_Ip_ShifterSourceType Source)
  114. {
  115. Base->SHIFTCFG[Shifter] = FLEXIO_SHIFTCFG_SSTART(Start)
  116. | FLEXIO_SHIFTCFG_SSTOP(Stop)
  117. | FLEXIO_SHIFTCFG_INSRC(Source);
  118. }
  119. /*
  120. * This function configures the control settings for the specified Shifter: mode settings
  121. * and timer settings.
  122. */
  123. static inline void Flexio_Uart_Ip_SetShifterControl(FLEXIO_Type * Base,
  124. uint8 Shifter,
  125. Flexio_Mcl_Ip_ShifterModeType Mode,
  126. uint8 Timer,
  127. Flexio_Mcl_Ip_TimerPolarityType TimerPolarity)
  128. {
  129. Base->SHIFTCTL[Shifter] = (Base->SHIFTCTL[Shifter] & ~(FLEXIO_SHIFTCTL_SMOD_MASK)) | FLEXIO_SHIFTCTL_SMOD(Mode);
  130. Base->SHIFTCTL[Shifter] = (Base->SHIFTCTL[Shifter] & ~(FLEXIO_SHIFTCTL_TIMPOL_MASK)) | FLEXIO_SHIFTCTL_TIMPOL(TimerPolarity);
  131. Base->SHIFTCTL[Shifter] = (Base->SHIFTCTL[Shifter] & ~(FLEXIO_SHIFTCTL_TIMSEL_MASK)) | FLEXIO_SHIFTCTL_TIMSEL(Timer);
  132. }
  133. /*
  134. * This function configures the control settings for the specified Shifter: pin settings.
  135. */
  136. static inline void Flexio_Uart_Ip_SetPinShifterControl(FLEXIO_Type * Base,
  137. uint8 Shifter,
  138. uint8 Pin,
  139. Flexio_Mcl_Ip_PinPolarityType PinPolarity,
  140. Flexio_Mcl_Ip_PinConfigType PinConfig)
  141. {
  142. Base->SHIFTCTL[Shifter] = (Base->SHIFTCTL[Shifter] & ~(FLEXIO_SHIFTCTL_PINPOL_MASK)) | FLEXIO_SHIFTCTL_PINPOL(PinPolarity);
  143. Base->SHIFTCTL[Shifter] = (Base->SHIFTCTL[Shifter] & ~(FLEXIO_SHIFTCTL_PINSEL_MASK)) | FLEXIO_SHIFTCTL_PINSEL(Pin);
  144. Base->SHIFTCTL[Shifter] = (Base->SHIFTCTL[Shifter] & ~(FLEXIO_SHIFTCTL_PINCFG_MASK)) | FLEXIO_SHIFTCTL_PINCFG(PinConfig);
  145. }
  146. /*
  147. * This function configures the compare value for the specified timer.
  148. * The timer compare value is loaded into the timer counter when the timer is first enabled,
  149. * when the timer is reset and when the timer decrements down to zero.
  150. * In dual 8-bit counters baud/bit mode, the lower 8-bits configure the baud rate divider
  151. * and the upper 8-bits configure the number of bits in each word.
  152. * In dual 8-bit counters PWM mode, the lower 8-bits configure the high period of the output
  153. * and the upper 8-bits configure the low period.
  154. * In 16-bit counter mode, the compare value can be used to generate the baud rate divider
  155. * (if shift clock source is timer output) or the number of bits in each word (when the shift
  156. * clock source is a pin or trigger input).
  157. */
  158. static inline void Flexio_Uart_Ip_SetTimerCompare(FLEXIO_Type * Base,
  159. uint8 Timer,
  160. uint16 Value)
  161. {
  162. Base->TIMCMP[Timer] = (uint32)Value;
  163. }
  164. /*
  165. * This function sets the following configurations for the specified timer:
  166. * Reset condition, Decrement condition, initial output
  167. */
  168. static inline void Flexio_Uart_Ip_SetTimerConfig(FLEXIO_Type * Base,
  169. uint8 Timer,
  170. Flexio_Mcl_Ip_TimerResetType Reset,
  171. Flexio_Uart_Ip_TimerDecrementType Decrement,
  172. Flexio_Mcl_Ip_TimerOutputType Output)
  173. {
  174. Base->TIMCFG[Timer] = (Base->TIMCFG[Timer] & ~(FLEXIO_TIMCFG_TIMRST_MASK)) | FLEXIO_TIMCFG_TIMRST(Reset);
  175. Base->TIMCFG[Timer] = (Base->TIMCFG[Timer] & ~(FLEXIO_TIMCFG_TIMDEC_MASK)) | FLEXIO_TIMCFG_TIMDEC(Decrement);
  176. Base->TIMCFG[Timer] = (Base->TIMCFG[Timer] & ~(FLEXIO_TIMCFG_TIMOUT_MASK)) | FLEXIO_TIMCFG_TIMOUT(Output);
  177. }
  178. /*
  179. * This function sets the following configurations for the specified timer:
  180. * Start bit, Stop bit
  181. */
  182. static inline void Flexio_Uart_Ip_SetTimerStartStopBitConfig(FLEXIO_Type * Base,
  183. uint8 Timer,
  184. Flexio_Mcl_Ip_TimerStartType Start,
  185. Flexio_Mcl_Ip_TimerStopType Stop)
  186. {
  187. Base->TIMCFG[Timer] = (Base->TIMCFG[Timer] & ~(FLEXIO_TIMCFG_TSTART_MASK)) | FLEXIO_TIMCFG_TSTART(Start);
  188. Base->TIMCFG[Timer] = (Base->TIMCFG[Timer] & ~(FLEXIO_TIMCFG_TSTOP_MASK)) | FLEXIO_TIMCFG_TSTOP(Stop);
  189. }
  190. /*
  191. * This function sets the following configurations for the specified timer:
  192. * Enable condition, disable condition,
  193. */
  194. static inline void Flexio_Uart_Ip_SetTimerCondition(FLEXIO_Type * Base,
  195. uint8 Timer,
  196. Flexio_Mcl_Ip_TimerEnableType Enable,
  197. Flexio_Mcl_Ip_TimerDisableType Disable)
  198. {
  199. Base->TIMCFG[Timer] = (Base->TIMCFG[Timer] & ~(FLEXIO_TIMCFG_TIMENA_MASK)) | FLEXIO_TIMCFG_TIMENA(Enable);
  200. Base->TIMCFG[Timer] = (Base->TIMCFG[Timer] & ~(FLEXIO_TIMCFG_TIMDIS_MASK)) | FLEXIO_TIMCFG_TIMDIS(Disable);
  201. }
  202. /*
  203. * This function configures the control settings for the specified timer: mode settings.
  204. */
  205. static inline void Flexio_Uart_Ip_SetTimerControl(FLEXIO_Type * Base,
  206. uint8 Timer,
  207. Flexio_Mcl_Ip_TimerModeType Mode)
  208. {
  209. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_TIMOD_MASK)) | FLEXIO_TIMCTL_TIMOD(Mode);
  210. }
  211. /*
  212. * This function configures the control settings for the specified timer: trigger settings.
  213. */
  214. static inline void Flexio_Uart_Ip_SetTimerTrigger(FLEXIO_Type * Base,
  215. uint8 Timer,
  216. uint8 Trigger,
  217. Flexio_Mcl_Ip_TriggerPolarityType TriggerPolarity,
  218. Flexio_Mcl_Ip_TriggerSourceType TriggerSource)
  219. {
  220. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_TRGSRC_MASK)) | FLEXIO_TIMCTL_TRGSRC(TriggerSource);
  221. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_TRGPOL_MASK)) | FLEXIO_TIMCTL_TRGPOL(TriggerPolarity);
  222. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_TRGSEL_MASK)) | FLEXIO_TIMCTL_TRGSEL(Trigger);
  223. }
  224. /*
  225. * This function configures the control settings for the specified timer:
  226. * pin settings.
  227. */
  228. static inline void Flexio_Uart_Ip_SetPinTimerControl(FLEXIO_Type * Base,
  229. uint8 Timer,
  230. uint8 Pin,
  231. Flexio_Mcl_Ip_PinPolarityType PinPolarity,
  232. Flexio_Mcl_Ip_PinConfigType PinConfig)
  233. {
  234. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_PINSEL_MASK)) | FLEXIO_TIMCTL_PINSEL(Pin);
  235. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_PINPOL_MASK)) | FLEXIO_TIMCTL_PINPOL(PinPolarity);
  236. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_PINCFG_MASK)) | FLEXIO_TIMCTL_PINCFG(PinConfig);
  237. }
  238. /*
  239. * This function configures the mode for the specified timer.
  240. * In 8-bit counter mode, the lower 8-bits of the counter and compare register are used to
  241. * configure the baud rate of the timer shift clock and the upper 8-bits are used to configure
  242. * the shifter bit count.
  243. * In 8-bit PWM mode, the lower 8-bits of the counter and compare
  244. * register are used to configure the high period of the timer shift clock and the upper
  245. * 8-bits are used to configure the low period of the timer shift clock. The shifter bit count
  246. * is configured using another timer or external signal.
  247. * In 16-bit counter mode, the full 16-bits of the counter and compare register are used to
  248. * configure either the baud rate of the shift clock or the shifter bit count.
  249. */
  250. static inline void Flexio_Uart_Ip_SetTimerMode(FLEXIO_Type * Base,
  251. uint8 Timer,
  252. Flexio_Mcl_Ip_TimerModeType Mode)
  253. {
  254. Base->TIMCTL[Timer] = (Base->TIMCTL[Timer] & ~(FLEXIO_TIMCTL_TIMOD_MASK)) | FLEXIO_TIMCTL_TIMOD(Mode);
  255. }
  256. /*
  257. * This function configures the mode for the specified shifter.
  258. */
  259. static inline void Flexio_Uart_Ip_SetShifterMode(FLEXIO_Type * Base,
  260. uint8 Shifter,
  261. Flexio_Mcl_Ip_ShifterModeType Mode)
  262. {
  263. Base->SHIFTCTL[Shifter] = (Base->SHIFTCTL[Shifter] & ~(FLEXIO_SHIFTCTL_SMOD_MASK)) | FLEXIO_SHIFTCTL_SMOD(Mode);
  264. }
  265. /*
  266. * This function configures the sending or receiving of
  267. * a start bit in Transmit, Receive or Match Store modes.
  268. */
  269. static inline void Flexio_Uart_Ip_SetShifterStartBit(FLEXIO_Type * Base,
  270. uint8 Shifter,
  271. Flexio_Mcl_Ip_ShifterStartType Start)
  272. {
  273. Base->SHIFTCFG[Shifter] = (Base->SHIFTCFG[Shifter] & ~(FLEXIO_SHIFTCFG_SSTART_MASK)) | FLEXIO_SHIFTCFG_SSTART(Start);
  274. }
  275. /*
  276. * This function writes data in the specified shifter buffer.
  277. */
  278. static inline void Flexio_Uart_Ip_WriteShifterBuffer(FLEXIO_Type * Base,
  279. uint8 Shifter,
  280. uint32 Value)
  281. {
  282. Base->SHIFTBUF[Shifter] = Value;
  283. }
  284. /*
  285. * This function reads data from the specified shifter buffer.
  286. */
  287. static inline uint32 Flexio_Uart_Ip_ReadShifterBuffer(const FLEXIO_Type * Base,
  288. uint8 Shifter)
  289. {
  290. uint32 Data;
  291. Data = Base->SHIFTBUF[Shifter];
  292. return Data;
  293. }
  294. /*
  295. * Returns the state of the interrupt for corresponding timer.
  296. */
  297. static inline boolean Flexio_Uart_Ip_GetTimerInterrupt(const FLEXIO_Type * Base, uint8 Timer)
  298. {
  299. boolean RetStatus;
  300. uint32 RegValue = (uint32)Base->TIMIEN;
  301. RegValue = (RegValue >> Timer) & 1U;
  302. if(RegValue != 0U)
  303. {
  304. RetStatus = TRUE;
  305. }
  306. else
  307. {
  308. RetStatus = FALSE;
  309. }
  310. return RetStatus;
  311. }
  312. /*
  313. * Returns the state of the error interrupt for corresponding shifter.
  314. */
  315. static inline boolean Flexio_Uart_Ip_GetShifterErrorInterrupt(const FLEXIO_Type * Base, uint8 Shifter)
  316. {
  317. boolean RetStatus;
  318. uint32 RegValue = (uint32)Base->SHIFTEIEN;
  319. RegValue = (RegValue >> Shifter) & 1U;
  320. if(RegValue != 0U)
  321. {
  322. RetStatus = TRUE;
  323. }
  324. else
  325. {
  326. RetStatus = FALSE;
  327. }
  328. return RetStatus;
  329. }
  330. /*
  331. * Returns the state of the interrupt for corresponding shifter.
  332. */
  333. static inline boolean Flexio_Uart_Ip_GetShifterInterrupt(const FLEXIO_Type * Base, uint8 Shifter)
  334. {
  335. boolean RetStatus;
  336. uint32 RegValue = (uint32)Base->SHIFTSIEN;
  337. RegValue = (RegValue >> Shifter) & 1U;
  338. if(RegValue != 0U)
  339. {
  340. RetStatus = TRUE;
  341. }
  342. else
  343. {
  344. RetStatus = FALSE;
  345. }
  346. return RetStatus;
  347. }
  348. /**
  349. * @brief : Prepare for timeout checking
  350. * @internal
  351. * @return : None
  352. */
  353. static inline void Flexio_Uart_Ip_StartTimeout(uint32 *StartTimeOut, uint32 *TimeoutTicksOut, uint32 TimeoutUs, OsIf_CounterType OsifCounter)
  354. {
  355. *StartTimeOut = OsIf_GetCounter(OsifCounter);
  356. *TimeoutTicksOut = OsIf_MicrosToTicks(TimeoutUs, OsifCounter);
  357. }
  358. /**
  359. * @brief : Checks for timeout condition
  360. * @internal
  361. * @return TRUE Timeout occurs
  362. * FALSE Timeout does not occur
  363. */
  364. static inline boolean Flexio_Uart_Ip_CheckTimeout(uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks, OsIf_CounterType OsifCounter)
  365. {
  366. uint32 CurrentElapsedTicks = OsIf_GetElapsed(StartTime, OsifCounter);
  367. *ElapsedTicks += CurrentElapsedTicks;
  368. return ((*ElapsedTicks >= TimeoutTicks) ? TRUE : FALSE);
  369. }
  370. #define UART_STOP_SEC_CODE
  371. #include "Uart_MemMap.h"
  372. #endif /* (FLEXIO_UART_IP_IS_USING == STD_ON) */
  373. #endif /* #ifdef FLEXIO_UART_IP_IS_USING */
  374. #if defined(__cplusplus)
  375. }
  376. #endif
  377. /*! @}*/
  378. #endif /* FLEXIO_UART_IP_HWACCESS_H__ */