Lpuart_Uart_Ip_HwAccess.h 27 KB

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