Lpuart_Uart_Ip_HwAccess.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 LPUART_UART_IP_HWACCESS_H__
  25. #define LPUART_UART_IP_HWACCESS_H__
  26. /**
  27. * @file
  28. * @internal
  29. * @defgroup lpuart_ip Lpuart IPL
  30. * @addtogroup lpuart_ip Lpuart 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 "OsIf.h"
  44. #include "Lpuart_Uart_Ip_Defines.h"
  45. #include "SchM_Uart.h"
  46. /*==================================================================================================
  47. * SOURCE FILE VERSION INFORMATION
  48. ==================================================================================================*/
  49. #define LPUART_UART_IP_HWACCESS_VENDOR_ID 43
  50. #define LPUART_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION 4
  51. #define LPUART_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION 4
  52. #define LPUART_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION 0
  53. #define LPUART_UART_IP_HWACCESS_SW_MAJOR_VERSION 1
  54. #define LPUART_UART_IP_HWACCESS_SW_MINOR_VERSION 0
  55. #define LPUART_UART_IP_HWACCESS_SW_PATCH_VERSION 0
  56. /*==================================================================================================
  57. * FILE VERSION CHECKS
  58. ==================================================================================================*/
  59. /* Checks against Lpuart_Uart_Ip_Defines.h */
  60. #if (LPUART_UART_IP_HWACCESS_VENDOR_ID != LPUART_UART_IP_DEFINES_VENDOR_ID)
  61. #error "Lpuart_Uart_Ip_HwAccess.h and Lpuart_Uart_Ip_Defines.h have different vendor ids"
  62. #endif
  63. #if ((LPUART_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != LPUART_UART_IP_DEFINES_AR_RELEASE_MAJOR_VERSION) || \
  64. (LPUART_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != LPUART_UART_IP_DEFINES_AR_RELEASE_MINOR_VERSION) || \
  65. (LPUART_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION != LPUART_UART_IP_DEFINES_AR_RELEASE_REVISION_VERSION))
  66. #error "AUTOSAR Version Numbers of Lpuart_Uart_Ip_HwAccess.h and Lpuart_Uart_Ip_Defines.h are different"
  67. #endif
  68. #if ((LPUART_UART_IP_HWACCESS_SW_MAJOR_VERSION != LPUART_UART_IP_DEFINES_SW_MAJOR_VERSION) || \
  69. (LPUART_UART_IP_HWACCESS_SW_MINOR_VERSION != LPUART_UART_IP_DEFINES_SW_MINOR_VERSION) || \
  70. (LPUART_UART_IP_HWACCESS_SW_PATCH_VERSION != LPUART_UART_IP_DEFINES_SW_PATCH_VERSION))
  71. #error "Software Version Numbers of Lpuart_Uart_Ip_HwAccess.h and Lpuart_Uart_Ip_Defines.h are different"
  72. #endif
  73. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  74. /* Check if current file and StandardTypes.h header file are of the same Autosar version */
  75. #if ((LPUART_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
  76. (LPUART_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION))
  77. #error "Lpuart_Uart_Ip_HwAccess.h and StandardTypes.h are different"
  78. #endif
  79. /* Check if current file and OsIf.h header file are of the same Autosar version */
  80. #if ((LPUART_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  81. (LPUART_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != OSIF_AR_RELEASE_MINOR_VERSION))
  82. #error "Lpuart_Uart_Ip_HwAccess.h and OsIf.h are different"
  83. #endif
  84. /* Check if current file and SchM_Uart.h header file are of the same Autosar version */
  85. #if ((LPUART_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != SCHM_UART_AR_RELEASE_MAJOR_VERSION) || \
  86. (LPUART_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != SCHM_UART_AR_RELEASE_MAJOR_VERSION))
  87. #error "Lpuart_Uart_Ip_HwAccess.h and SchM_Uart.h are different"
  88. #endif
  89. #endif
  90. /*==================================================================================================
  91. * CONSTANTS
  92. ==================================================================================================*/
  93. /*==================================================================================================
  94. * DEFINES AND MACROS
  95. ==================================================================================================*/
  96. #define LPUART_FEATURE_DEFAULT_OSR (0xFU)
  97. #define LPUART_FEATURE_DEFAULT_SBR (0x4U)
  98. #define LPUART_FEATURE_STAT_REG_FLAGS_MASK (0xC01FC000U)
  99. /*! @brief LPUART number of bits in a character
  100. *
  101. *
  102. */
  103. /* implements Lpuart_Uart_Ip_BitCountPerCharType_enum */
  104. typedef enum
  105. {
  106. LPUART_UART_IP_7_BITS_PER_CHAR = 0x0U, /*!< 7-bit data characters */
  107. LPUART_UART_IP_8_BITS_PER_CHAR = 0x1U, /*!< 8-bit data characters */
  108. LPUART_UART_IP_9_BITS_PER_CHAR = 0x2U, /*!< 9-bit data characters */
  109. LPUART_UART_IP_10_BITS_PER_CHAR = 0x3U /*!< 10-bit data characters */
  110. } Lpuart_Uart_Ip_BitCountPerCharType;
  111. /*! @brief LPUART parity mode
  112. *
  113. *
  114. */
  115. /* implements Lpuart_Uart_Ip_ParityModeType_enum */
  116. typedef enum
  117. {
  118. LPUART_UART_IP_PARITY_DISABLED = 0x0U, /*!< parity disabled */
  119. LPUART_UART_IP_PARITY_EVEN = 0x2U, /*!< parity enabled, type even, bit setting: PE|PT = 10 */
  120. LPUART_UART_IP_PARITY_ODD = 0x3U /*!< parity enabled, type odd, bit setting: PE|PT = 11 */
  121. } Lpuart_Uart_Ip_ParityModeType;
  122. typedef enum
  123. {
  124. LPUART_UART_IP_ONE_STOP_BIT = 0x0U, /*!< one stop bit */
  125. LPUART_UART_IP_TWO_STOP_BIT = 0x1U /*!< two stop bits */
  126. } Lpuart_Uart_Ip_StopBitCountType;
  127. /*!
  128. * @brief LPUART status flags.
  129. *
  130. * This provides constants for the LPUART status flags for use in the UART functions.
  131. */
  132. typedef enum
  133. {
  134. LPUART_UART_IP_TX_DATA_REG_EMPTY = (uint32)LPUART_STAT_TDRE_SHIFT,
  135. /*!< Tx data register empty flag, sets when Tx buffer is empty */
  136. LPUART_UART_IP_TX_COMPLETE = (uint32)LPUART_STAT_TC_SHIFT,
  137. /*!< Transmission complete flag, sets when transmission activity complete */
  138. LPUART_UART_IP_DATA_REG_FULL = (uint32)LPUART_STAT_RDRF_SHIFT,
  139. /*!< Rx data register full flag, sets when the receive data buffer is full */
  140. LPUART_UART_IP_RX_OVERRUN = (uint32)LPUART_STAT_OR_SHIFT,
  141. /*!< Rx Overrun sets if new data is received before data is read */
  142. LPUART_UART_IP_NOISE_DETECT = (uint32)LPUART_STAT_NF_SHIFT,
  143. /*!< Rx takes 3 samples of each received bit. If these differ, the flag sets */
  144. LPUART_UART_IP_FRAME_ERR = (uint32)LPUART_STAT_FE_SHIFT,
  145. /*!< Frame error flag, sets if logic 0 was detected where stop bit expected */
  146. LPUART_UART_IP_PARITY_ERR = (uint32)LPUART_STAT_PF_SHIFT,
  147. } Lpuart_Uart_Ip_StatusFlagType;
  148. /*! @brief LPUART interrupt configuration structure, default settings are 0 (disabled) */
  149. typedef enum
  150. {
  151. LPUART_UART_IP_INT_TX_DATA_REG_EMPTY = (uint32)LPUART_CTRL_TIE_SHIFT, /*!< Transmit data register empty. */
  152. LPUART_UART_IP_INT_TX_COMPLETE = (uint32)LPUART_CTRL_TCIE_SHIFT, /*!< Transmission complete. */
  153. LPUART_UART_IP_INT_RX_DATA_REG_FULL = (uint32)LPUART_CTRL_RIE_SHIFT, /*!< Receiver data register full. */
  154. LPUART_UART_IP_INT_RX_OVERRUN = (uint32)LPUART_CTRL_ORIE_SHIFT, /*!< Receiver Overrun. */
  155. LPUART_UART_IP_INT_NOISE_ERR_FLAG = (uint32)LPUART_CTRL_NEIE_SHIFT, /*!< Noise error flag. */
  156. LPUART_UART_IP_INT_FRAME_ERR_FLAG = (uint32)LPUART_CTRL_FEIE_SHIFT, /*!< Framing error flag. */
  157. LPUART_UART_IP_INT_PARITY_ERR_FLAG = (uint32)LPUART_CTRL_PEIE_SHIFT, /*!< Parity error flag. */
  158. } Lpuart_Uart_Ip_InterruptType;
  159. /*==================================================================================================
  160. * STRUCTURES AND OTHER TYPEDEFS
  161. ==================================================================================================*/
  162. /*==================================================================================================
  163. * GLOBAL VARIABLE DECLARATIONS
  164. ==================================================================================================*/
  165. /*==================================================================================================
  166. * FUNCTION PROTOTYPES
  167. ==================================================================================================*/
  168. #define UART_START_SEC_CODE
  169. #include "Uart_MemMap.h"
  170. /*!
  171. * @brief Initializes the LPUART controller.
  172. *
  173. * This function Initializes the LPUART controller to known state.
  174. *
  175. *
  176. * @param Base LPUART base pointer.
  177. */
  178. static inline void Lpuart_Uart_Ip_Hw_Init(LPUART_Type * Base)
  179. {
  180. /* Set the default oversampling ratio (16) and baud-rate divider (4) */
  181. Base->BAUD = ((uint32)(((uint32)LPUART_FEATURE_DEFAULT_OSR << LPUART_BAUD_OSR_SHIFT) | \
  182. (LPUART_FEATURE_DEFAULT_SBR << LPUART_BAUD_SBR_SHIFT)));
  183. /* Clear the error/interrupt flags */
  184. Base->STAT = LPUART_FEATURE_STAT_REG_FLAGS_MASK;
  185. /* Reset all features/interrupts by default */
  186. Base->CTRL = 0x00000000;
  187. }
  188. /*!
  189. * @brief Enable/Disable the LPUART transmitter.
  190. *
  191. * This function enables or disables the LPUART transmitter, based on the
  192. * parameter received.
  193. *
  194. *
  195. * @param Base LPUART base pointer.
  196. * @param Enable Enable(true) or disable(false) transmitter.
  197. */
  198. static inline void Lpuart_Uart_Ip_SetTransmitterCmd(LPUART_Type * Base, boolean Enable)
  199. {
  200. Base->CTRL = (Base->CTRL & ~LPUART_CTRL_TE_MASK) | ((Enable ? 1UL : 0UL) << LPUART_CTRL_TE_SHIFT);
  201. }
  202. /*!
  203. * @brief Enable/Disable the LPUART receiver.
  204. *
  205. * This function enables or disables the LPUART receiver, based on the
  206. * parameter received.
  207. *
  208. *
  209. * @param Base LPUART base pointer
  210. * @param Enable Enable(true) or disable(false) receiver.
  211. */
  212. static inline void Lpuart_Uart_Ip_SetReceiverCmd(LPUART_Type * Base, boolean Enable)
  213. {
  214. Base->CTRL = (Base->CTRL & ~LPUART_CTRL_RE_MASK) | ((Enable ? 1UL : 0UL) << LPUART_CTRL_RE_SHIFT);
  215. }
  216. /*!
  217. * @brief Sets the LPUART baud rate modulo divisor.
  218. *
  219. * This function sets the LPUART baud rate modulo divisor.
  220. *
  221. *
  222. * @param Base LPUART base pointer.
  223. * @param baudRateDivisor The baud rate modulo division "SBR"
  224. */
  225. static inline void Lpuart_Uart_Ip_SetBaudRateDivisor(LPUART_Type * Base, uint32 baudRateDivisor)
  226. {
  227. Base->BAUD = (Base->BAUD & ~LPUART_BAUD_SBR_MASK) | (baudRateDivisor & LPUART_BAUD_SBR_MASK);
  228. }
  229. /*!
  230. * @brief Gets the LPUART baud rate modulo divisor.
  231. *
  232. * This function gets the LPUART baud rate modulo divisor.
  233. *
  234. *
  235. * @param Base LPUART base pointer.
  236. * @return The baud rate modulo division "SBR"
  237. */
  238. static inline uint16 Lpuart_Uart_Ip_GetBaudRateDivisor(const LPUART_Type * Base)
  239. {
  240. return ((uint16)((Base->BAUD & LPUART_BAUD_SBR_MASK) >> LPUART_BAUD_SBR_SHIFT));
  241. }
  242. /*!
  243. * @brief Sets the LPUART baud rate oversampling ratio
  244. *
  245. * This function sets the LPUART baud rate oversampling ratio.
  246. * (Note: Feature available on select LPUART instances used together with baud rate programming)
  247. * The oversampling ratio should be set between 4x (00011) and 32x (11111). Writing
  248. * an invalid oversampling ratio results in an error and is set to a default
  249. * 16x (01111) oversampling ratio.
  250. * Disable the transmitter/receiver before calling this function.
  251. *
  252. *
  253. * @param Base LPUART base pointer.
  254. * @param OverSamplingRatio The oversampling ratio "OSR"
  255. */
  256. static inline void Lpuart_Uart_Ip_SetOversamplingRatio(LPUART_Type * Base, uint32 OverSamplingRatio)
  257. {
  258. Base->BAUD = (Base->BAUD & ~LPUART_BAUD_OSR_MASK) | LPUART_BAUD_OSR(OverSamplingRatio);
  259. }
  260. /*!
  261. * @brief Gets the LPUART baud rate oversampling ratio
  262. *
  263. * This function gets the LPUART baud rate oversampling ratio.
  264. * (Note: Feature available on select LPUART instances used together with baud rate programming)
  265. *
  266. *
  267. * @param Base LPUART base pointer.
  268. * @return The oversampling ratio "OSR"
  269. */
  270. static inline uint8 Lpuart_Uart_Ip_GetOversamplingRatio(const LPUART_Type * Base)
  271. {
  272. return ((uint8)((Base->BAUD & LPUART_BAUD_OSR_MASK) >> LPUART_BAUD_OSR_SHIFT));
  273. }
  274. /*!
  275. * @brief Configures the LPUART baud rate both edge sampling
  276. *
  277. * This function configures the LPUART baud rate both edge sampling.
  278. * (Note: Feature available on select LPUART instances used with baud rate programming)
  279. * When enabled, the received data is sampled on both edges of the baud rate clock.
  280. * This must be set when the oversampling ratio is between 4x and 7x.
  281. * This function should only be called when the receiver is disabled.
  282. *
  283. *
  284. * @param Base LPUART base pointer.
  285. */
  286. static inline void Lpuart_Uart_Ip_EnableBothEdgeSamplingCmd(LPUART_Type * Base)
  287. {
  288. Base->BAUD |= LPUART_BAUD_BOTHEDGE_MASK;
  289. }
  290. /*!
  291. * @brief Configures the number of bits per character in the LPUART controller.
  292. *
  293. * This function configures the number of bits per character in the LPUART controller.
  294. * In some LPUART instances, the user should disable the transmitter/receiver
  295. * before calling this function.
  296. * Generally, this may be applied to all LPUARTs to ensure safe operation.
  297. *
  298. * @param Base LPUART base pointer.
  299. * @param BitCountPerChar Number of bits per char (7, 8, 9, or 10, depending on the LPUART instance)
  300. * @param Parity Specifies whether parity bit is enabled
  301. */
  302. static inline void Lpuart_Uart_Ip_SetBitCountPerChar(LPUART_Type * Base,
  303. Lpuart_Uart_Ip_BitCountPerCharType BitCountPerChar,
  304. boolean Parity)
  305. {
  306. uint32 TmpBitCountPerChar = (uint32)BitCountPerChar;
  307. if (Parity)
  308. {
  309. TmpBitCountPerChar += 1U;
  310. }
  311. if (TmpBitCountPerChar == (uint32)LPUART_UART_IP_10_BITS_PER_CHAR)
  312. {
  313. Base->BAUD = (Base->BAUD & ~LPUART_BAUD_M10_MASK) | ((uint32)1U << LPUART_BAUD_M10_SHIFT);
  314. }
  315. else
  316. {
  317. if (LPUART_UART_IP_7_BITS_PER_CHAR == BitCountPerChar)
  318. {
  319. /* Check if parity is enabled or not*/
  320. if (Parity)
  321. {
  322. /* clear M7 to make sure not 7-bit mode (M7 = 0) and config 8 bits (M = 0) */
  323. Base->CTRL &= ~(LPUART_CTRL_M7_MASK | LPUART_CTRL_M_MASK);
  324. }
  325. else
  326. {
  327. /* config 7-bits (M7 = 1)*/
  328. Base->CTRL = (Base->CTRL & ~LPUART_CTRL_M7_MASK) | ((uint32)1U << LPUART_CTRL_M7_SHIFT);
  329. }
  330. }
  331. else
  332. {
  333. TmpBitCountPerChar -= 1U;
  334. /* config 8-bit (M=0) or 9-bits (M=1) */
  335. Base->CTRL = (Base->CTRL & ~LPUART_CTRL_M_MASK) | (TmpBitCountPerChar << LPUART_CTRL_M_SHIFT);
  336. }
  337. /* clear M10 to make sure not 10-bit mode */
  338. Base->BAUD &= ~LPUART_BAUD_M10_MASK;
  339. }
  340. }
  341. /*!
  342. * @brief Configures parity mode in the LPUART controller.
  343. *
  344. * This function configures parity mode in the LPUART controller.
  345. * In some LPUART instances, the user should disable the transmitter/receiver
  346. * before calling this function.
  347. * Generally, this may be applied to all LPUARTs to ensure safe operation.
  348. *
  349. * @param Base LPUART base pointer.
  350. * @param ParityModeType Parity mode (enabled, disable, odd, even - see parity_mode_t struct)
  351. */
  352. static inline void Lpuart_Uart_Ip_SetParityMode(LPUART_Type * Base, Lpuart_Uart_Ip_ParityModeType ParityModeType)
  353. {
  354. Base->CTRL = (Base->CTRL & ~LPUART_CTRL_PE_MASK) | (((uint32)ParityModeType >> 1U) << LPUART_CTRL_PE_SHIFT);
  355. Base->CTRL = (Base->CTRL & ~LPUART_CTRL_PT_MASK) | (((uint32)ParityModeType & 1U) << LPUART_CTRL_PT_SHIFT);
  356. }
  357. /*!
  358. * @brief Configures the number of stop bits in the LPUART controller.
  359. *
  360. * This function configures the number of stop bits in the LPUART controller.
  361. * In some LPUART instances, the user should disable the transmitter/receiver
  362. * before calling this function.
  363. * Generally, this may be applied to all LPUARTs to ensure safe operation.
  364. *
  365. * @param Base LPUART base pointer.
  366. * @param StopBitCount Number of stop bits (1 or 2 - see Lpuart_Uart_Ip_StopBitCountType struct)
  367. */
  368. static inline void Lpuart_Uart_Ip_SetStopBitCount(LPUART_Type * Base, Lpuart_Uart_Ip_StopBitCountType StopBitCount)
  369. {
  370. Base->BAUD = (Base->BAUD & ~LPUART_BAUD_SBNS_MASK) | ((uint32)StopBitCount << LPUART_BAUD_SBNS_SHIFT);
  371. }
  372. /*!
  373. * @brief Configures the LPUART module interrupts.
  374. *
  375. * This function configures the LPUART module interrupts to enable/disable various interrupt sources.
  376. *
  377. *
  378. * @param Base LPUART module base pointer.
  379. * @param IntSrc LPUART interrupt configuration data.
  380. * @param Enable true: enable, false: disable.
  381. */
  382. static inline void Lpuart_Uart_Ip_SetIntMode(LPUART_Type * Base, Lpuart_Uart_Ip_InterruptType IntSrc, boolean Enable)
  383. {
  384. Base->CTRL = (Base->CTRL & ~(1UL << (uint32)IntSrc)) | ((Enable ? 1U : 0U) << (uint32)IntSrc);
  385. }
  386. /*!
  387. * @brief Returns LPUART module interrupts state.
  388. *
  389. * This function returns whether a certain LPUART module interrupt is enabled or disabled.
  390. *
  391. *
  392. * @param Base LPUART module base pointer.
  393. * @param IntSrc LPUART interrupt configuration data.
  394. * @return true: enable, false: disable.
  395. */
  396. static inline boolean Lpuart_Uart_Ip_GetIntMode(const LPUART_Type * Base, Lpuart_Uart_Ip_InterruptType IntSrc)
  397. {
  398. boolean RetVal = FALSE;
  399. RetVal = (((Base->CTRL >> (uint32)(IntSrc)) & 1U) > 0U);
  400. return RetVal;
  401. }
  402. #if (LPUART_UART_IP_HAS_DMA_ENABLED == STD_ON)
  403. /*!
  404. * @brief Configures DMA requests.
  405. *
  406. * This function configures DMA requests for LPUART Transmitter.
  407. *
  408. *
  409. * @param Base LPUART base pointer
  410. * @param Enable Transmit DMA request configuration (enable:1 /disable: 0)
  411. */
  412. static inline void Lpuart_Uart_Ip_SetTxDmaCmd(LPUART_Type * Base, boolean Enable)
  413. {
  414. Base->BAUD = (Base->BAUD & ~LPUART_BAUD_TDMAE_MASK) | ((Enable ? 1UL : 0UL) << LPUART_BAUD_TDMAE_SHIFT);
  415. }
  416. /*!
  417. * @brief Configures DMA requests.
  418. *
  419. * This function configures DMA requests for LPUART Receiver.
  420. *
  421. *
  422. * @param Base LPUART base pointer
  423. * @param Enable Receive DMA request configuration (enable: 1/disable: 0)
  424. */
  425. static inline void Lpuart_Uart_Ip_SetRxDmaCmd(LPUART_Type * Base, boolean Enable)
  426. {
  427. Base->BAUD = (Base->BAUD & ~LPUART_BAUD_RDMAE_MASK) | ((Enable ? 1UL : 0UL) << LPUART_BAUD_RDMAE_SHIFT);
  428. }
  429. #endif
  430. /*!
  431. * @brief Sends the LPUART 8-bit character.
  432. *
  433. * This functions sends an 8-bit character.
  434. *
  435. *
  436. * @param Base LPUART Instance
  437. * @param Data data to send (8-bit)
  438. */
  439. static inline void Lpuart_Uart_Ip_Putchar(LPUART_Type * Base, uint8 Data)
  440. {
  441. volatile uint8 * DataRegBytes = (volatile uint8 *)(&(Base->DATA));
  442. DataRegBytes[0] = Data;
  443. }
  444. /*!
  445. * @brief Sends the LPUART 9-bit character.
  446. *
  447. * This functions sends a 9-bit character.
  448. *
  449. *
  450. * @param Base LPUART Instance
  451. * @param Data data to send (9-bit)
  452. */
  453. static inline void Lpuart_Uart_Ip_Putchar9(LPUART_Type * Base, uint16 Data)
  454. {
  455. uint8 NinthDataBit;
  456. volatile uint8 * DataRegBytes = (volatile uint8 *)(&(Base->DATA));
  457. NinthDataBit = (uint8)((Data >> 8U) & 0x1U);
  458. /* write to ninth data bit T8(where T[0:7]=8-bits, T8=9th bit) */
  459. Base->CTRL = (Base->CTRL & ~LPUART_CTRL_R9T8_MASK) | ((uint32)(NinthDataBit) << LPUART_CTRL_R9T8_SHIFT);
  460. /* write 8-bits to the data register*/
  461. DataRegBytes[0] = (uint8)Data;
  462. }
  463. /*!
  464. * @brief Sends the LPUART 10-bit character (Note: Feature available on select LPUART instances).
  465. *
  466. * This functions sends a 10-bit character.
  467. *
  468. *
  469. * @param Base LPUART Instance
  470. * @param Data data to send (10-bit)
  471. */
  472. static inline void Lpuart_Uart_Ip_Putchar10(LPUART_Type * Base, uint16 Data)
  473. {
  474. uint8 NinthDataBit, TenthDataBit;
  475. uint32 CtrlRegVal;
  476. volatile uint8 * DataRegBytes = (volatile uint8 *)(&(Base->DATA));
  477. NinthDataBit = (uint8)((Data >> 8U) & 0x1U);
  478. TenthDataBit = (uint8)((Data >> 9U) & 0x1U);
  479. /* write to ninth/tenth data bit (T[0:7]=8-bits, T8=9th bit, T9=10th bit) */
  480. CtrlRegVal = Base->CTRL;
  481. CtrlRegVal = (CtrlRegVal & ~LPUART_CTRL_R9T8_MASK) | ((uint32)NinthDataBit << LPUART_CTRL_R9T8_SHIFT);
  482. CtrlRegVal = (CtrlRegVal & ~LPUART_CTRL_R8T9_MASK) | ((uint32)TenthDataBit << LPUART_CTRL_R8T9_SHIFT);
  483. /*Note: T8(9th bit) and T9(10th bit) should be written at same time. */
  484. Base->CTRL = CtrlRegVal;
  485. /* write to 8-bits to the Data register */
  486. DataRegBytes[0] = (uint8)Data;
  487. }
  488. /*!
  489. * @brief Gets the LPUART 8-bit character.
  490. *
  491. * This functions receives an 8-bit character.
  492. *
  493. *
  494. * @param Base LPUART base pointer
  495. * @param ReadData Data read from receive (8-bit)
  496. */
  497. static inline uint8 Lpuart_Uart_Ip_Getchar(const LPUART_Type * Base)
  498. {
  499. return (uint8)Base->DATA;
  500. }
  501. /*!
  502. * @brief Gets the LPUART 9-bit character.
  503. *
  504. * This functions receives a 9-bit character.
  505. *
  506. *
  507. * @param Base LPUART base pointer
  508. */
  509. static inline uint16 Lpuart_Uart_Ip_Getchar9(const LPUART_Type * Base)
  510. {
  511. uint16 ReadData;
  512. /* get ninth bit from lpuart data register */
  513. ReadData = (uint16)(((Base->CTRL >> LPUART_CTRL_R8T9_SHIFT) & 1U) << 8);
  514. /* get 8-bit data from the lpuart data register */
  515. ReadData |= (uint8)Base->DATA;
  516. return ReadData;
  517. }
  518. /*!
  519. * @brief Gets the LPUART 10-bit character.
  520. *
  521. * This functions receives a 10-bit character.
  522. *
  523. *
  524. * @param Base LPUART Base pointer
  525. */
  526. static inline uint16 Lpuart_Uart_Ip_Getchar10(const LPUART_Type * Base)
  527. {
  528. uint16 ReadData;
  529. /* read tenth data bit */
  530. ReadData = (uint16)(((Base->CTRL >> LPUART_CTRL_R9T8_SHIFT) & 1U) << 9);
  531. /* read ninth data bit */
  532. ReadData |= (uint16)(((Base->CTRL >> LPUART_CTRL_R8T9_SHIFT) & 1U) << 8);
  533. /* get 8-bit data */
  534. ReadData |= (uint8)Base->DATA;
  535. return ReadData;
  536. }
  537. /*!
  538. * @brief LPUART get status flag
  539. *
  540. * This function returns the state of a status flag.
  541. *
  542. *
  543. * @param Base LPUART base pointer
  544. * @param StatusFlag The status flag to query
  545. * @return Whether the current status flag is set(true) or not(false).
  546. */
  547. static inline boolean Lpuart_Uart_Ip_GetStatusFlag(const LPUART_Type * Base, Lpuart_Uart_Ip_StatusFlagType StatusFlag)
  548. {
  549. boolean RetVal = FALSE;
  550. RetVal = (((Base->STAT >> (uint32)(StatusFlag)) & 1U) > 0U);
  551. return RetVal;
  552. }
  553. /*!
  554. * @brief LPUART clears an individual status flag.
  555. *
  556. * This function clears an individual status flag (see Lpuart_Uart_Ip_StatusFlagType for list of status bits).
  557. *
  558. *
  559. * @param Base LPUART base pointer
  560. * @param StatusFlag Desired LPUART status flag to clear
  561. * @return LPUART_UART_IP_STATUS_SUCCESS if successful or STATUS_ERROR if an error occured
  562. */
  563. static inline void Lpuart_Uart_Ip_ClearStatusFlag(LPUART_Type * Base, Lpuart_Uart_Ip_StatusFlagType StatusFlag)
  564. {
  565. switch(StatusFlag)
  566. {
  567. case LPUART_UART_IP_RX_OVERRUN:
  568. Base->STAT = (Base->STAT & (~LPUART_FEATURE_STAT_REG_FLAGS_MASK)) | LPUART_STAT_OR_MASK;
  569. break;
  570. case LPUART_UART_IP_NOISE_DETECT:
  571. Base->STAT = (Base->STAT & (~LPUART_FEATURE_STAT_REG_FLAGS_MASK)) | LPUART_STAT_NF_MASK;
  572. break;
  573. case LPUART_UART_IP_FRAME_ERR:
  574. Base->STAT = (Base->STAT & (~LPUART_FEATURE_STAT_REG_FLAGS_MASK)) | LPUART_STAT_FE_MASK;
  575. break;
  576. case LPUART_UART_IP_PARITY_ERR:
  577. Base->STAT = (Base->STAT & (~LPUART_FEATURE_STAT_REG_FLAGS_MASK)) | LPUART_STAT_PF_MASK;
  578. break;
  579. default:
  580. /* Dummy code */
  581. break;
  582. }
  583. }
  584. /*!
  585. * @brief LPUART clears an individual status flag.
  586. *
  587. * This function clears an individual status flag (see Lpuart_Uart_Ip_StatusFlagType for list of status bits).
  588. *
  589. *
  590. * @param Base LPUART base pointer
  591. * @param Mask LPUART Status Register Mask to clear
  592. */
  593. static inline void Lpuart_Uart_Ip_ClearStatusFlagWithMask(LPUART_Type * Base, uint32 Mask)
  594. {
  595. Base->STAT = (Base->STAT & (~LPUART_FEATURE_STAT_REG_FLAGS_MASK)) | Mask;
  596. }
  597. /*!
  598. * @brief Clears the error flags treated by the driver
  599. *
  600. * This function clears the error flags treated by the driver.
  601. * *
  602. * @param Base LPUART Base pointer
  603. */
  604. static inline void Lpuart_Uart_Ip_ClearErrorFlags(LPUART_Type * Base)
  605. {
  606. uint32 Mask = LPUART_STAT_OR_MASK | \
  607. LPUART_STAT_NF_MASK | \
  608. LPUART_STAT_FE_MASK | \
  609. LPUART_STAT_PF_MASK;
  610. Base->STAT = (Base->STAT & (~LPUART_FEATURE_STAT_REG_FLAGS_MASK)) | Mask;
  611. }
  612. /**
  613. * @brief : Prepare for timeout checking
  614. * @internal
  615. * @return : None
  616. */
  617. static inline void Lpuart_Uart_Ip_StartTimeout(uint32 *StartTimeOut, uint32 *TimeoutTicksOut, uint32 TimeoutUs, OsIf_CounterType OsifCounter)
  618. {
  619. *StartTimeOut = OsIf_GetCounter(OsifCounter);
  620. *TimeoutTicksOut = OsIf_MicrosToTicks(TimeoutUs, OsifCounter);
  621. }
  622. /**
  623. * @brief : Checks for timeout condition
  624. * @internal
  625. * @return TRUE Timeout occurs
  626. * FALSE Timeout does not occur
  627. */
  628. static inline boolean Lpuart_Uart_Ip_CheckTimeout(uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks, OsIf_CounterType OsifCounter)
  629. {
  630. uint32 CurrentElapsedTicks = OsIf_GetElapsed(StartTime, OsifCounter);
  631. *ElapsedTicks += CurrentElapsedTicks;
  632. return ((*ElapsedTicks >= TimeoutTicks) ? TRUE : FALSE);
  633. }
  634. /**
  635. * @brief : Flush Tx Buffer
  636. *
  637. * This function causes all data that is stored in the transmit FIFO/buffer to be flushed.
  638. * *
  639. * @param Base LPUART Base pointer
  640. */
  641. static inline void Lpuart_Uart_Ip_FlushTxBuffer(LPUART_Type * Base)
  642. {
  643. Base->FIFO |= LPUART_FIFO_TXFLUSH_MASK;
  644. }
  645. /**
  646. * @brief : Flush Rx Buffer
  647. *
  648. * This function causes all data that is stored in the receive FIFO/buffer to be flushed.
  649. * *
  650. * @param Base LPUART Base pointer
  651. */
  652. static inline void Lpuart_Uart_Ip_FlushRxBuffer(LPUART_Type * Base)
  653. {
  654. Base->FIFO |= LPUART_FIFO_RXFLUSH_MASK;
  655. }
  656. #define UART_STOP_SEC_CODE
  657. #include "Uart_MemMap.h"
  658. #if defined(__cplusplus)
  659. }
  660. #endif
  661. /*@}*/
  662. #endif /* LPUART_HW_ACCESS_H__ */