Lpuart_Uart_Ip_HwAccess.h 27 KB

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