Uart_Ipw.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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. /**
  25. * @file
  26. * @internal
  27. * @addtogroup UART
  28. * @{
  29. */
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /*==================================================================================================
  35. * INCLUDE FILES
  36. * 1) system and project includes
  37. * 2) needed interfaces from external units
  38. * 3) internal and external interfaces from this unit
  39. ==================================================================================================*/
  40. #include "Uart_Ipw.h"
  41. #include "Uart_Ipw_Cfg.h"
  42. #ifdef UART_IPW_LPUART_HW_USING
  43. #include "Lpuart_Uart_Ip.h"
  44. #endif
  45. #ifdef UART_IPW_FLEXIO_HW_USING
  46. #include "Flexio_Uart_Ip.h"
  47. #endif
  48. /*==================================================================================================
  49. * SOURCE FILE VERSION INFORMATION
  50. ==================================================================================================*/
  51. #define UART_IPW_VENDOR_ID_C 43
  52. #define UART_IPW_AR_RELEASE_MAJOR_VERSION_C 4
  53. #define UART_IPW_AR_RELEASE_MINOR_VERSION_C 4
  54. #define UART_IPW_AR_RELEASE_REVISION_VERSION_C 0
  55. #define UART_IPW_SW_MAJOR_VERSION_C 1
  56. #define UART_IPW_SW_MINOR_VERSION_C 0
  57. #define UART_IPW_SW_PATCH_VERSION_C 0
  58. /*==================================================================================================
  59. * FILE VERSION CHECKS
  60. ==================================================================================================*/
  61. /*Checks against Uart_Ipw.h */
  62. #if (UART_IPW_VENDOR_ID_C!= UART_IPW_VENDOR_ID)
  63. #error "Uart_Ipw.c and Uart_Ipw.h have different vendor ids"
  64. #endif
  65. #if ((UART_IPW_AR_RELEASE_MAJOR_VERSION_C != UART_IPW_AR_RELEASE_MAJOR_VERSION) || \
  66. (UART_IPW_AR_RELEASE_MINOR_VERSION_C != UART_IPW_AR_RELEASE_MINOR_VERSION) || \
  67. (UART_IPW_AR_RELEASE_REVISION_VERSION_C!= UART_IPW_AR_RELEASE_REVISION_VERSION))
  68. #error "AUTOSAR Version Numbers of Uart_Ipw.c and Uart_Ipw.h are different"
  69. #endif
  70. #if ((UART_IPW_SW_MAJOR_VERSION_C!= UART_IPW_SW_MAJOR_VERSION) || \
  71. (UART_IPW_SW_MINOR_VERSION_C!= UART_IPW_SW_MINOR_VERSION) || \
  72. (UART_IPW_SW_PATCH_VERSION_C!= UART_IPW_SW_PATCH_VERSION) \
  73. )
  74. #error "Software Version Numbers of Uart_Ipw.c and Uart_Ipw.h are different"
  75. #endif
  76. /* Checks against Uart_Ipw_Cfg.h */
  77. #if (UART_IPW_VENDOR_ID_C != UART_IPW_CFG_VENDOR_ID)
  78. #error "Uart_Ipw.c and Uart_Ipw_Cfg.h have different vendor ids"
  79. #endif
  80. #if ((UART_IPW_AR_RELEASE_MAJOR_VERSION_C != UART_IPW_CFG_AR_RELEASE_MAJOR_VERSION) || \
  81. (UART_IPW_AR_RELEASE_MINOR_VERSION_C != UART_IPW_CFG_AR_RELEASE_MINOR_VERSION) || \
  82. (UART_IPW_AR_RELEASE_REVISION_VERSION_C != UART_IPW_CFG_AR_RELEASE_REVISION_VERSION))
  83. #error "AUTOSAR Version Numbers of Uart_Ipw.c and Uart_Ipw_Cfg.h are different"
  84. #endif
  85. #if ((UART_IPW_SW_MAJOR_VERSION_C != UART_IPW_CFG_SW_MAJOR_VERSION) || \
  86. (UART_IPW_SW_MINOR_VERSION_C != UART_IPW_CFG_SW_MINOR_VERSION) || \
  87. (UART_IPW_SW_PATCH_VERSION_C != UART_IPW_CFG_SW_PATCH_VERSION) \
  88. )
  89. #error "Software Version Numbers of Uart_Ipw.c and Uart_Ipw_Cfg.h are different"
  90. #endif
  91. #ifdef UART_IPW_LPUART_HW_USING
  92. /* Checks against Lpuart_Uart_Ip.h */
  93. #if (UART_IPW_VENDOR_ID_C != LPUART_UART_IP_VENDOR_ID)
  94. #error "Uart_Ipw.c and Lpuart_Uart_Ip.h have different vendor ids"
  95. #endif
  96. #if ((UART_IPW_AR_RELEASE_MAJOR_VERSION_C != LPUART_UART_IP_AR_RELEASE_MAJOR_VERSION) || \
  97. (UART_IPW_AR_RELEASE_MINOR_VERSION_C != LPUART_UART_IP_AR_RELEASE_MINOR_VERSION) || \
  98. (UART_IPW_AR_RELEASE_REVISION_VERSION_C != LPUART_UART_IP_AR_RELEASE_REVISION_VERSION))
  99. #error "AUTOSAR Version Numbers of Uart_Ipw.c and Lpuart_Uart_Ip.h are different"
  100. #endif
  101. #if ((UART_IPW_SW_MAJOR_VERSION_C != LPUART_UART_IP_SW_MAJOR_VERSION) || \
  102. (UART_IPW_SW_MINOR_VERSION_C != LPUART_UART_IP_SW_MINOR_VERSION) || \
  103. (UART_IPW_SW_PATCH_VERSION_C != LPUART_UART_IP_SW_PATCH_VERSION) \
  104. )
  105. #error "Software Version Numbers of Uart_Ipw.c and Lpuart_Uart_Ip.h are different"
  106. #endif
  107. #endif
  108. #ifdef UART_IPW_FLEXIO_HW_USING
  109. /* Checks against Flexio_Uart_Ip.h */
  110. #if (UART_IPW_VENDOR_ID_C != FLEXIO_UART_IP_VENDOR_ID)
  111. #error "Uart_Ipw.c and Flexio_Uart_Ip.h have different vendor ids"
  112. #endif
  113. #if ((UART_IPW_AR_RELEASE_MAJOR_VERSION_C != FLEXIO_UART_IP_AR_RELEASE_MAJOR_VERSION) || \
  114. (UART_IPW_AR_RELEASE_MINOR_VERSION_C != FLEXIO_UART_IP_AR_RELEASE_MINOR_VERSION) || \
  115. (UART_IPW_AR_RELEASE_REVISION_VERSION_C != FLEXIO_UART_IP_AR_RELEASE_REVISION_VERSION))
  116. #error "AUTOSAR Version Numbers of Uart_Ipw.c and Flexio_Uart_Ip.h are different"
  117. #endif
  118. #if ((UART_IPW_SW_MAJOR_VERSION_C != FLEXIO_UART_IP_SW_MAJOR_VERSION) || \
  119. (UART_IPW_SW_MINOR_VERSION_C != FLEXIO_UART_IP_SW_MINOR_VERSION) || \
  120. (UART_IPW_SW_PATCH_VERSION_C != FLEXIO_UART_IP_SW_PATCH_VERSION) \
  121. )
  122. #error "Software Version Numbers of Uart_Ipw.c and Flexio_Uart_Ip.h are different"
  123. #endif
  124. #endif
  125. /*==================================================================================================
  126. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  127. ==================================================================================================*/
  128. /*==================================================================================================
  129. * LOCAL MACROS
  130. ==================================================================================================*/
  131. /*==================================================================================================
  132. * LOCAL CONSTANTS
  133. ==================================================================================================*/
  134. /*==================================================================================================
  135. * LOCAL VARIABLES
  136. ==================================================================================================*/
  137. /*==================================================================================================
  138. * GLOBAL CONSTANTS
  139. ==================================================================================================*/
  140. #if (UART_CALLBACK_DECLARED == STD_ON)
  141. #define UART_START_SEC_VAR_INIT_8
  142. #include "Uart_MemMap.h"
  143. static sint8 Uart_Ipw_s8HwMapping[UART_NUMBER_OF_INSTANCES] = UART_HW_CHANNELS_MAPPING_FOR_INIT;
  144. #define UART_STOP_SEC_VAR_INIT_8
  145. #include "Uart_MemMap.h"
  146. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  147. #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED
  148. #include "Uart_MemMap.h"
  149. const Uart_Ipw_HwConfigType *Uart_Ipw_apChnConfig[UART_CH_MAX_CONFIG];
  150. #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  151. #include "Uart_MemMap.h"
  152. /*==================================================================================================
  153. * GLOBAL VARIABLES
  154. ==================================================================================================*/
  155. /*==================================================================================================
  156. * LOCAL FUNCTION PROTOTYPES
  157. ==================================================================================================*/
  158. #define UART_START_SEC_CODE
  159. #include "Uart_MemMap.h"
  160. #ifdef UART_IPW_LPUART_HW_USING
  161. /* Convert Lpuart Status type to Standard status type */
  162. static Uart_StatusType Uart_Ipw_LpuartConvertStatus(Lpuart_Uart_Ip_StatusType Status);
  163. /* Convert Uart Baudrate type to Ip Baudrate type */
  164. static Lpuart_Uart_Ip_BaudrateType Uart_Ipw_LpuartConvertBaudrateType(Uart_BaudrateType Baudrate);
  165. #if (UART_CALLBACK_DECLARED == STD_ON)
  166. /* Convert HLD Uart Event type to Ip Event type */
  167. static Uart_EventType Uart_Ipw_LpuartConvertEventType(Lpuart_Uart_Ip_EventType Event);
  168. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  169. #endif
  170. #ifdef UART_IPW_FLEXIO_HW_USING
  171. /* Convert Flexio Status type to Standard status type */
  172. static Uart_StatusType Uart_Ipw_FlexioConvertStatus(Flexio_Uart_Ip_StatusType Status);
  173. /* Convert Uart Baudrate type to Ip Baudrate type */
  174. static Flexio_Uart_Ip_BaudrateType Uart_Ipw_FlexioConvertBaudrateType(Uart_BaudrateType Baudrate);
  175. #if (UART_CALLBACK_DECLARED == STD_ON)
  176. /* Convert HLD Uart Event type to Ip Event type */
  177. static Uart_EventType Uart_Ipw_FlexioConvertEventType(Flexio_Uart_Ip_EventType Event);
  178. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  179. #endif
  180. /*==================================================================================================
  181. * LOCAL FUNCTIONS
  182. ==================================================================================================*/
  183. /*==================================================================================================
  184. * GLOBAL FUNCTIONS
  185. ==================================================================================================*/
  186. /**
  187. * @internal
  188. * @brief Initialize an Uart channel.
  189. * @details This function calls a LLD function initializes all hardware registers needed to
  190. * start the Uart functionality on the selected channel.
  191. *
  192. * @param [in] Channel Uart channel to be initialized.
  193. * [in] Config Configuration pointer containing hardware specific settings.
  194. *
  195. * @return void.
  196. *
  197. */
  198. void Uart_Ipw_Init(uint8 Channel, const Uart_Ipw_HwConfigType* Config)
  199. {
  200. uint8 HwUnit = Config->UartHwChannel;
  201. /* Save the mapping between hardware instance and logical channel */
  202. /* Save the channel settings */
  203. Uart_Ipw_apChnConfig[Channel] = Config;
  204. /* Call the LLD Initialization function */
  205. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  206. {
  207. #ifdef UART_IPW_LPUART_HW_USING
  208. #if (UART_CALLBACK_DECLARED == STD_ON)
  209. Uart_Ipw_s8HwMapping[HwUnit] = (sint8)Channel;
  210. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  211. Lpuart_Uart_Ip_Init(HwUnit, Config->UserConfig->LpuartUserConfig);
  212. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  213. }
  214. #ifdef UART_IPW_FLEXIO_HW_USING
  215. else
  216. {
  217. #if (UART_CALLBACK_DECLARED == STD_ON)
  218. Uart_Ipw_s8HwMapping[UART_NUMBER_OF_INSTANCES - FLEXIO_UART_IP_NUMBER_OF_SHIFTER_AND_TIMER + HwUnit] = (sint8)Channel;
  219. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  220. Flexio_Uart_Ip_Init(HwUnit, Config->UserConfig->FlexioUartUserConfig);
  221. }
  222. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  223. }
  224. /**
  225. * @internal
  226. * @brief De-initialize an Uart channel.
  227. * @details This function calls a LLD function de-initializes an Uart Hw instance and resets the current
  228. information regarding the current channel
  229. *
  230. * @param[in] Channel Uart channel to be de-initialized.
  231. *
  232. * @return void.
  233. *
  234. */
  235. void Uart_Ipw_Deinit(uint8 Channel)
  236. {
  237. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  238. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  239. {
  240. #ifdef UART_IPW_LPUART_HW_USING
  241. #if (UART_CALLBACK_DECLARED == STD_ON)
  242. /* Remove the current hw to logic mapping */
  243. Uart_Ipw_s8HwMapping[HwUnit] = -1;
  244. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  245. Lpuart_Uart_Ip_Deinit(HwUnit);
  246. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  247. }
  248. #ifdef UART_IPW_FLEXIO_HW_USING
  249. else
  250. {
  251. #if (UART_CALLBACK_DECLARED == STD_ON)
  252. /* Remove the current hw to logic mapping */
  253. Uart_Ipw_s8HwMapping[UART_NUMBER_OF_INSTANCES - FLEXIO_UART_IP_NUMBER_OF_SHIFTER_AND_TIMER + HwUnit] = -1;
  254. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  255. Flexio_Uart_Ip_Deinit(HwUnit);
  256. }
  257. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  258. /* Remove refference to the current channel configuration */
  259. Uart_Ipw_apChnConfig[Channel] = NULL_PTR;
  260. }
  261. /**
  262. * @internal
  263. * @brief Set a baudrate value for the current channel.
  264. * @details This function calls a LLD function which sets a baudrate value for a given channel,
  265. *
  266. * @param[in] Channel Uart channel where the baudrate shall be configured
  267. * @param[in] BaudRateValue The baudrate value to be configured.
  268. * @param[in] ClockFrequency The clock frequency set for the Uart module.
  269. *
  270. * @return E_OK: Baud rate successfully configured
  271. * E_NOT_OK: Baud rate wasn't successfully configured
  272. *
  273. */
  274. Std_ReturnType Uart_Ipw_SetBaudrate(uint8 Channel, Uart_BaudrateType BaudRateValue, uint32 ClockFrequency)
  275. {
  276. Std_ReturnType TempStatus = (uint8)E_NOT_OK;
  277. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  278. #ifdef UART_IPW_LPUART_HW_USING
  279. Lpuart_Uart_Ip_BaudrateType LpuartBaud = Uart_Ipw_LpuartConvertBaudrateType(BaudRateValue);
  280. #endif
  281. #ifdef UART_IPW_FLEXIO_HW_USING
  282. Flexio_Uart_Ip_BaudrateType FlexioBaud = Uart_Ipw_FlexioConvertBaudrateType(BaudRateValue);
  283. #endif
  284. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  285. {
  286. #ifdef UART_IPW_LPUART_HW_USING
  287. if (LPUART_UART_IP_STATUS_SUCCESS == Lpuart_Uart_Ip_SetBaudRate(HwUnit, LpuartBaud, ClockFrequency))
  288. {
  289. TempStatus = (uint8)E_OK;
  290. }
  291. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  292. }
  293. #ifdef UART_IPW_FLEXIO_HW_USING
  294. else
  295. {
  296. if (FLEXIO_UART_IP_STATUS_SUCCESS == Flexio_Uart_Ip_SetBaudRate(HwUnit, FlexioBaud, ClockFrequency))
  297. {
  298. TempStatus = (uint8)E_OK;
  299. }
  300. }
  301. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  302. return TempStatus;
  303. }
  304. /**
  305. * @internal
  306. * @brief Retrieves the baudrate value configured for the current channel.
  307. * @details This function calls a LLD function returns the baudrate value configured for the given channel
  308. * via a pointer parameter provided by user.
  309. *
  310. * @param[in] Channel Uart channel where the baudrate shall be configured
  311. * @param[out] BaudrateValue The pointer which will contain the baudrate value.
  312. *
  313. * @return void
  314. *
  315. */
  316. void Uart_Ipw_GetBaudrate(uint8 Channel, uint32 *BaudrateValue)
  317. {
  318. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  319. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  320. {
  321. #ifdef UART_IPW_LPUART_HW_USING
  322. Lpuart_Uart_Ip_GetBaudRate(HwUnit, BaudrateValue);
  323. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  324. }
  325. #ifdef UART_IPW_FLEXIO_HW_USING
  326. else
  327. {
  328. Flexio_Uart_Ip_GetBaudRate(HwUnit, BaudrateValue);
  329. }
  330. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  331. }
  332. /**
  333. * @internal
  334. * @brief Aborts an on-going transmission.
  335. * @details This function calls a LLD function which ends a transfer earlier.
  336. *
  337. * @param[in] Channel Uart channel where the transmission shall be ended.
  338. *
  339. * @return E_OK: The transfer ended successfully
  340. * E_NOT_OK: The transfer didn't end successfully
  341. *
  342. */
  343. Std_ReturnType Uart_Ipw_AbortSendingData(uint8 Channel)
  344. {
  345. Std_ReturnType TempStatus = (uint8)E_NOT_OK;
  346. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  347. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  348. {
  349. #ifdef UART_IPW_LPUART_HW_USING
  350. if (LPUART_UART_IP_STATUS_SUCCESS == Lpuart_Uart_Ip_AbortSendingData(HwUnit))
  351. {
  352. TempStatus = (uint8)E_OK;
  353. }
  354. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  355. }
  356. #ifdef UART_IPW_FLEXIO_HW_USING
  357. else
  358. {
  359. if (FLEXIO_UART_IP_STATUS_SUCCESS == Flexio_Uart_Ip_AbortTransferData(HwUnit))
  360. {
  361. TempStatus = (uint8)E_OK;
  362. }
  363. }
  364. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  365. return TempStatus;
  366. }
  367. /**
  368. * @internal
  369. * @brief Aborts an on-going reception.
  370. * @details This function calls a LLD function which ends a reception earlier.
  371. *
  372. * @param[in] Channel Uart channel where the reception shall be ended.
  373. *
  374. * @return E_OK: The reception ended successfully
  375. * E_NOT_OK: The reception didn't end successfully
  376. *
  377. */
  378. Std_ReturnType Uart_Ipw_AbortReceivingData(uint8 Channel)
  379. {
  380. Std_ReturnType TempStatus = (uint8)E_NOT_OK;
  381. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  382. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  383. {
  384. #ifdef UART_IPW_LPUART_HW_USING
  385. if (LPUART_UART_IP_STATUS_SUCCESS == Lpuart_Uart_Ip_AbortReceivingData(HwUnit))
  386. {
  387. TempStatus = (uint8)E_OK;
  388. }
  389. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  390. }
  391. #ifdef UART_IPW_FLEXIO_HW_USING
  392. else
  393. {
  394. if (FLEXIO_UART_IP_STATUS_SUCCESS == Flexio_Uart_Ip_AbortTransferData(HwUnit))
  395. {
  396. TempStatus = (uint8)E_OK;
  397. }
  398. }
  399. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  400. return TempStatus;
  401. }
  402. /**
  403. * @internal
  404. * @brief Sets a tx buffer.
  405. * @details This function calls a LLD function which sets a buffer for continuos transmission.
  406. *
  407. * @param[in] Channel Uart channel where to set the buffer.
  408. *
  409. * @return void
  410. */
  411. void Uart_Ipw_SetTxBuffer(uint8 Channel, const uint8 *Buffer, uint32 BufferSize)
  412. {
  413. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  414. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  415. {
  416. #ifdef UART_IPW_LPUART_HW_USING
  417. (void)Lpuart_Uart_Ip_SetTxBuffer(HwUnit, Buffer, BufferSize);
  418. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  419. }
  420. #ifdef UART_IPW_FLEXIO_HW_USING
  421. else
  422. {
  423. (void)Flexio_Uart_Ip_SetTxBuffer(HwUnit, Buffer, BufferSize);
  424. }
  425. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  426. }
  427. /**
  428. * @brief Sets a rx buffer.
  429. * @details This function calls a LLD function which sets a buffer for continuos reception.
  430. *
  431. * @param[in] Channel Uart channel where to set the buffer.
  432. *
  433. * @return void
  434. */
  435. void Uart_Ipw_SetRxBuffer(uint8 Channel, uint8 *Buffer, uint32 BufferSize)
  436. {
  437. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  438. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  439. {
  440. #ifdef UART_IPW_LPUART_HW_USING
  441. (void)Lpuart_Uart_Ip_SetRxBuffer(HwUnit, Buffer, BufferSize);
  442. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  443. }
  444. #ifdef UART_IPW_FLEXIO_HW_USING
  445. else
  446. {
  447. (void)Flexio_Uart_Ip_SetRxBuffer(HwUnit, Buffer, BufferSize);
  448. }
  449. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  450. }
  451. /**
  452. * @internal
  453. * @brief Sends a buffer synchronously.
  454. * @details This function calls a LLD function which sends BufferSize bytes using polling method.
  455. *
  456. * @param[in] Channel Uart channel used for transmission.
  457. * @param[in] Buffer Buffer to send.
  458. * @param[in] BufferSize The number of bytes to send.
  459. * @param[in] Timeout The timeout value in us.
  460. *
  461. *
  462. * @return E_OK: Tranmission ended successfully
  463. * UART_STATUS_TIMEOUT: Tranmission has timeout
  464. * E_NOT_OK Tranmission didn't end successfully
  465. */
  466. Std_ReturnType Uart_Ipw_SyncSend(uint8 Channel, const uint8 *Buffer, uint32 BufferSize, uint32 Timeout)
  467. {
  468. Std_ReturnType TempStatus = (uint8)E_NOT_OK;
  469. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  470. /* LPUART is used */
  471. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  472. {
  473. #ifdef UART_IPW_LPUART_HW_USING
  474. Lpuart_Uart_Ip_StatusType u32LpuartIpStatus;
  475. u32LpuartIpStatus = Lpuart_Uart_Ip_SyncSend(HwUnit,
  476. Buffer,
  477. BufferSize,
  478. Timeout);
  479. if (LPUART_UART_IP_STATUS_SUCCESS == u32LpuartIpStatus)
  480. {
  481. TempStatus = (uint8)E_OK;
  482. }
  483. else if (LPUART_UART_IP_STATUS_TIMEOUT == u32LpuartIpStatus)
  484. {
  485. TempStatus = (uint8)UART_STATUS_TIMEOUT;
  486. }
  487. else
  488. {
  489. TempStatus = (uint8)E_NOT_OK;
  490. }
  491. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  492. }
  493. #ifdef UART_IPW_FLEXIO_HW_USING
  494. else
  495. {
  496. Flexio_Uart_Ip_StatusType u32FlexioIpStatus;
  497. u32FlexioIpStatus = Flexio_Uart_Ip_SyncSend(HwUnit,
  498. Buffer,
  499. BufferSize,
  500. Timeout);
  501. if (FLEXIO_UART_IP_STATUS_SUCCESS == u32FlexioIpStatus)
  502. {
  503. TempStatus = (uint8)E_OK;
  504. }
  505. else if (FLEXIO_UART_IP_STATUS_TIMEOUT == u32FlexioIpStatus)
  506. {
  507. TempStatus = (uint8)UART_STATUS_TIMEOUT;
  508. }
  509. else
  510. {
  511. TempStatus = (uint8)E_NOT_OK;
  512. }
  513. }
  514. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  515. return TempStatus;
  516. }
  517. /**
  518. * @internal
  519. * @brief Receives a buffer synchronously.
  520. * @details This function calls a LLD function which receives BufferSize bytes using polling method.
  521. *
  522. * @param[in] Channel Uart channel used for reception.
  523. * @param[in] Buffer Buffer to receive.
  524. * @param[in] BufferSize The number of bytes to receive.
  525. * @param[in] Timeout The timeout value in us.
  526. *
  527. *
  528. * @return E_OK: Reception ended successfully
  529. * E_NOT_OK: Reception didn't end successfully
  530. * UART_STATUS_TIMEOUT: Reception has timeout
  531. */
  532. Std_ReturnType Uart_Ipw_SyncReceive(uint8 Channel, uint8 *Buffer, uint32 BufferSize, uint32 Timeout)
  533. {
  534. Std_ReturnType TempStatus = (uint8)E_NOT_OK;
  535. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  536. /* LPUART is used */
  537. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  538. {
  539. #ifdef UART_IPW_LPUART_HW_USING
  540. Lpuart_Uart_Ip_StatusType u32LpuartIpStatus;
  541. u32LpuartIpStatus = Lpuart_Uart_Ip_SyncReceive(HwUnit,
  542. Buffer,
  543. BufferSize,
  544. Timeout);
  545. if (LPUART_UART_IP_STATUS_SUCCESS == u32LpuartIpStatus)
  546. {
  547. TempStatus = (uint8)E_OK;
  548. }
  549. else if (LPUART_UART_IP_STATUS_TIMEOUT == u32LpuartIpStatus)
  550. {
  551. TempStatus = (uint8)UART_STATUS_TIMEOUT;
  552. }
  553. else
  554. {
  555. TempStatus = (uint8)E_NOT_OK;
  556. }
  557. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  558. }
  559. #ifdef UART_IPW_FLEXIO_HW_USING
  560. else
  561. {
  562. Flexio_Uart_Ip_StatusType u32FlexioIpStatus;
  563. u32FlexioIpStatus = Flexio_Uart_Ip_SyncReceive(HwUnit,
  564. Buffer,
  565. BufferSize,
  566. Timeout);
  567. if (FLEXIO_UART_IP_STATUS_SUCCESS == u32FlexioIpStatus)
  568. {
  569. TempStatus = (uint8)E_OK;
  570. }
  571. else if (FLEXIO_UART_IP_STATUS_TIMEOUT == u32FlexioIpStatus)
  572. {
  573. TempStatus = (uint8)UART_STATUS_TIMEOUT;
  574. }
  575. else
  576. {
  577. TempStatus = (uint8)E_NOT_OK;
  578. }
  579. }
  580. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  581. return TempStatus;
  582. }
  583. /**
  584. * @internal
  585. * @brief Receives a buffer asynchronously.
  586. * @details This function calls a LLD function which receives BufferSize bytes using an asynchornous method.
  587. *
  588. * @param[in] Channel Uart channel used for reception.
  589. * @param[in] Buffer Buffer to receive.
  590. * @param[in] BufferSize The number of bytes to receive.
  591. *
  592. *
  593. * @return E_OK: Reception started successfully
  594. E_NOT_OK: Reception didn't start successfully
  595. */
  596. Std_ReturnType Uart_Ipw_AsyncReceive(uint8 Channel, uint8 *Buffer, uint32 BufferSize)
  597. {
  598. Std_ReturnType TempStatus = (uint8)E_NOT_OK;
  599. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  600. /* LPUART is used */
  601. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  602. {
  603. #ifdef UART_IPW_LPUART_HW_USING
  604. if (LPUART_UART_IP_STATUS_SUCCESS == Lpuart_Uart_Ip_AsyncReceive(HwUnit,
  605. Buffer,
  606. BufferSize))
  607. {
  608. TempStatus = (uint8)E_OK;
  609. }
  610. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  611. }
  612. #ifdef UART_IPW_FLEXIO_HW_USING
  613. else
  614. {
  615. if (FLEXIO_UART_IP_STATUS_SUCCESS == Flexio_Uart_Ip_AsyncReceive(HwUnit,
  616. Buffer,
  617. BufferSize))
  618. {
  619. TempStatus = (uint8)E_OK;
  620. }
  621. }
  622. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  623. return TempStatus;
  624. }
  625. /**
  626. * @internal
  627. * @brief Sends a buffer asynchronously.
  628. * @details This function calls a LLD function which sends BufferSize bytes using an asynchornous method.
  629. *
  630. * @param[in] Channel Uart channel used for transmission.
  631. * @param[in] Buffer Buffer to send.
  632. * @param[in] BufferSize The number of bytes to send.
  633. *
  634. *
  635. * @return E_OK: Transmission started successfully
  636. E_NOT_OK: Transmission didn't start successfully
  637. */
  638. Std_ReturnType Uart_Ipw_AsyncSend(uint8 Channel, const uint8 *Buffer, uint32 BufferSize)
  639. {
  640. Std_ReturnType TempStatus = (uint8)E_NOT_OK;
  641. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  642. /* LPUART is used */
  643. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  644. {
  645. #ifdef UART_IPW_LPUART_HW_USING
  646. if (LPUART_UART_IP_STATUS_SUCCESS == Lpuart_Uart_Ip_AsyncSend(HwUnit,
  647. Buffer,
  648. BufferSize))
  649. {
  650. TempStatus = (uint8)E_OK;
  651. }
  652. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  653. }
  654. #ifdef UART_IPW_FLEXIO_HW_USING
  655. else
  656. {
  657. if (FLEXIO_UART_IP_STATUS_SUCCESS == Flexio_Uart_Ip_AsyncSend(HwUnit,
  658. Buffer,
  659. BufferSize))
  660. {
  661. TempStatus = (uint8)E_OK;
  662. }
  663. }
  664. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  665. return TempStatus;
  666. }
  667. /**
  668. * @internal
  669. * @brief Retrieves the status of the previous transfer.
  670. * @details This function calls a LLD function which retrieves the status of the previous transfer
  671. * and the number of the remaining bytes to send.
  672. *
  673. * @param[in] Channel Uart channel.
  674. * @param[out] BytesRemaining The pointer where to write the number of remaining bytes
  675. *
  676. *
  677. * @return UART_NO_ERR0R: The previous transfer ended successfully
  678. UART_STATUS_OPERATION_ONGOING The transfer is still on going
  679. UART_STATUS_ABORTED The previous transfer was aborted
  680. UART_STATUS_TIMEOUT The previous transfer was timeout
  681. */
  682. Uart_StatusType Uart_Ipw_GetTransmitStatus(uint8 Channel, uint32 *BytesRemaining)
  683. {
  684. Uart_StatusType TempStatus = UART_STATUS_TIMEOUT;
  685. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  686. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  687. {
  688. #ifdef UART_IPW_LPUART_HW_USING
  689. Lpuart_Uart_Ip_StatusType u32LpuartIpStatus;
  690. u32LpuartIpStatus = Lpuart_Uart_Ip_GetTransmitStatus(HwUnit, BytesRemaining);
  691. TempStatus = Uart_Ipw_LpuartConvertStatus(u32LpuartIpStatus);
  692. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  693. }
  694. #ifdef UART_IPW_FLEXIO_HW_USING
  695. else
  696. {
  697. Flexio_Uart_Ip_StatusType u32FlexioIpStatus;
  698. u32FlexioIpStatus = Flexio_Uart_Ip_GetStatus(HwUnit, BytesRemaining);
  699. TempStatus = Uart_Ipw_FlexioConvertStatus(u32FlexioIpStatus);
  700. }
  701. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  702. return TempStatus;
  703. }
  704. /**
  705. * @internal
  706. * @brief Retrieves the status of the previous reception.
  707. * @details This function calls a LLD function which retrieves the status of the previous reception
  708. * and the number of the remaining bytes to receive.
  709. *
  710. * @param[in] Channel Uart channel.
  711. * @param[out] BytesRemaining The pointer where to write the number of remaining bytes
  712. *
  713. *
  714. * @return UART_NO_ERR0R: The previous transfer ended successfully
  715. UART_STATUS_OPERATION_ONGOING The reception is still on going
  716. UART_STATUS_ABORTED The previous reception was aborted
  717. UART_STATUS_FRAMING_ERROR Uart framing error
  718. UART_STATUS_RX_OVERRUN_ERROR Uart overrun error
  719. UART_STATUS_PARITY_ERROR Uart overrun error
  720. UART_STATUS_TIMEOUT Uart operation has timeout
  721. */
  722. Uart_StatusType Uart_Ipw_GetReceiveStatus(uint8 Channel, uint32 *BytesRemaining)
  723. {
  724. Uart_StatusType TempStatus = UART_STATUS_TIMEOUT;
  725. uint8 HwUnit = Uart_Ipw_apChnConfig[Channel]->UartHwChannel;
  726. if (LPUART_IP == Uart_Ipw_apChnConfig[Channel]->UartIpType)
  727. {
  728. #ifdef UART_IPW_LPUART_HW_USING
  729. Lpuart_Uart_Ip_StatusType u32LpuartIpStatus;
  730. u32LpuartIpStatus = Lpuart_Uart_Ip_GetReceiveStatus(HwUnit, BytesRemaining);
  731. TempStatus = Uart_Ipw_LpuartConvertStatus(u32LpuartIpStatus);
  732. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  733. }
  734. #ifdef UART_IPW_FLEXIO_HW_USING
  735. else
  736. {
  737. Flexio_Uart_Ip_StatusType u32FlexioIpStatus;
  738. u32FlexioIpStatus = Flexio_Uart_Ip_GetStatus(HwUnit, BytesRemaining);
  739. TempStatus = Uart_Ipw_FlexioConvertStatus(u32FlexioIpStatus);
  740. }
  741. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  742. return TempStatus;
  743. }
  744. #ifdef UART_IPW_LPUART_HW_USING
  745. /**
  746. * @internal
  747. * @brief Convert Uart IP layer return status to standard return status.
  748. * @details This function receives Uart IP layer return status and convert to standard return status.
  749. * @param[in] Status Uart IP status
  750. *
  751. *
  752. * @return Standard status
  753. * This is not a public API as it is called from other driver functions.
  754. */
  755. static Uart_StatusType Uart_Ipw_LpuartConvertStatus(Lpuart_Uart_Ip_StatusType Status)
  756. {
  757. Uart_StatusType TempStatus = UART_STATUS_TIMEOUT;
  758. switch (Status)
  759. {
  760. case LPUART_UART_IP_STATUS_SUCCESS:
  761. TempStatus = UART_STATUS_NO_ERROR;
  762. break;
  763. case LPUART_UART_IP_STATUS_BUSY:
  764. TempStatus = UART_STATUS_OPERATION_ONGOING;
  765. break;
  766. case LPUART_UART_IP_STATUS_ABORTED:
  767. TempStatus = UART_STATUS_ABORTED;
  768. break;
  769. case LPUART_UART_IP_STATUS_TIMEOUT:
  770. TempStatus = UART_STATUS_TIMEOUT;
  771. break;
  772. case LPUART_UART_IP_STATUS_FRAMING_ERROR:
  773. TempStatus = UART_STATUS_FRAMING_ERROR;
  774. break;
  775. case LPUART_UART_IP_STATUS_RX_OVERRUN:
  776. TempStatus = UART_STATUS_RX_OVERRUN_ERROR;
  777. break;
  778. case LPUART_UART_IP_STATUS_NOISE_ERROR:
  779. TempStatus = UART_STATUS_NOISE_ERROR;
  780. break;
  781. case LPUART_UART_IP_STATUS_PARITY_ERROR:
  782. TempStatus = UART_STATUS_PARITY_ERROR;
  783. break;
  784. default:
  785. TempStatus = UART_STATUS_DMA_ERROR;
  786. break;
  787. }
  788. return TempStatus;
  789. }
  790. /**
  791. * @internal
  792. * @brief Convert Uart HLD baudrate type to IP baudrate type.
  793. * @details This function receives HLD baudrate and convert to IP baudrate.
  794. * @param[in] Baudrate Uart HLD Baudrate
  795. *
  796. *
  797. * @return IP baudrate
  798. * This is not a public API as it is called from other driver functions.
  799. */
  800. static Lpuart_Uart_Ip_BaudrateType Uart_Ipw_LpuartConvertBaudrateType(Uart_BaudrateType Baudrate)
  801. {
  802. Lpuart_Uart_Ip_BaudrateType TempBaud = LPUART_UART_BAUDRATE_1200;
  803. switch (Baudrate)
  804. {
  805. case UART_BAUDRATE_1200:
  806. TempBaud = LPUART_UART_BAUDRATE_1200;
  807. break;
  808. case UART_BAUDRATE_2400:
  809. TempBaud = LPUART_UART_BAUDRATE_2400;
  810. break;
  811. case UART_BAUDRATE_4800:
  812. TempBaud = LPUART_UART_BAUDRATE_4800;
  813. break;
  814. case UART_BAUDRATE_9600:
  815. TempBaud = LPUART_UART_BAUDRATE_9600;
  816. break;
  817. case UART_BAUDRATE_14400:
  818. TempBaud = LPUART_UART_BAUDRATE_14400;
  819. break;
  820. case UART_BAUDRATE_19200:
  821. TempBaud = LPUART_UART_BAUDRATE_19200;
  822. break;
  823. case UART_BAUDRATE_28800:
  824. TempBaud = LPUART_UART_BAUDRATE_28800;
  825. break;
  826. case UART_BAUDRATE_38400:
  827. TempBaud = LPUART_UART_BAUDRATE_38400;
  828. break;
  829. case UART_BAUDRATE_57600:
  830. TempBaud = LPUART_UART_BAUDRATE_57600;
  831. break;
  832. case UART_BAUDRATE_115200:
  833. TempBaud = LPUART_UART_BAUDRATE_115200;
  834. break;
  835. case UART_BAUDRATE_230400:
  836. TempBaud = LPUART_UART_BAUDRATE_230400;
  837. break;
  838. case UART_BAUDRATE_460800:
  839. TempBaud = LPUART_UART_BAUDRATE_460800;
  840. break;
  841. case UART_BAUDRATE_921600:
  842. TempBaud = LPUART_UART_BAUDRATE_921600;
  843. break;
  844. case UART_BAUDRATE_1843200:
  845. TempBaud = LPUART_UART_BAUDRATE_1843200;
  846. break;
  847. default:
  848. /* Nothing to do */
  849. break;
  850. }
  851. return TempBaud;
  852. }
  853. #if (UART_CALLBACK_DECLARED == STD_ON)
  854. /**
  855. * @internal
  856. * @brief Convert Uart IP Event type to HLD Event type.
  857. * @details This function receives IP Event and convert to HLD Event.
  858. * @param[in] Event Uart IP Event
  859. *
  860. *
  861. * @return HLD Event
  862. * This is not a public API as it is called from other driver functions.
  863. */
  864. static Uart_EventType Uart_Ipw_LpuartConvertEventType(Lpuart_Uart_Ip_EventType Event)
  865. {
  866. Uart_EventType TempEvent = UART_EVENT_ERROR;
  867. switch (Event)
  868. {
  869. case LPUART_UART_IP_EVENT_RX_FULL:
  870. TempEvent = UART_EVENT_RX_FULL;
  871. break;
  872. case LPUART_UART_IP_EVENT_TX_EMPTY:
  873. TempEvent = UART_EVENT_TX_EMPTY;
  874. break;
  875. case LPUART_UART_IP_EVENT_END_TRANSFER:
  876. TempEvent = UART_EVENT_END_TRANSFER;
  877. break;
  878. case LPUART_UART_IP_EVENT_ERROR:
  879. TempEvent = UART_EVENT_ERROR;
  880. break;
  881. case LPUART_UART_IP_EVENT_RECV_IDLE: //zhengchao
  882. TempEvent = UART_EVENT_IDLE;
  883. break;
  884. default:
  885. /* Nothing to do */
  886. break;
  887. }
  888. return TempEvent;
  889. }
  890. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  891. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  892. #ifdef UART_IPW_FLEXIO_HW_USING
  893. /**
  894. * @internal
  895. * @brief Convert Uart IP layer return status to standard return status.
  896. * @details This function receives Uart IP layer return status and convert to standard return status.
  897. * @param[in] Status Uart IP status
  898. *
  899. *
  900. * @return Standard status
  901. * This is not a public API as it is called from other driver functions.
  902. */
  903. static Uart_StatusType Uart_Ipw_FlexioConvertStatus(Flexio_Uart_Ip_StatusType Status)
  904. {
  905. Uart_StatusType TempStatus = UART_STATUS_TIMEOUT;
  906. switch (Status)
  907. {
  908. case FLEXIO_UART_IP_STATUS_SUCCESS:
  909. TempStatus = UART_STATUS_NO_ERROR;
  910. break;
  911. case FLEXIO_UART_IP_STATUS_BUSY:
  912. TempStatus = UART_STATUS_OPERATION_ONGOING;
  913. break;
  914. case FLEXIO_UART_IP_STATUS_ABORTED:
  915. TempStatus = UART_STATUS_ABORTED;
  916. break;
  917. case FLEXIO_UART_IP_STATUS_TIMEOUT:
  918. TempStatus = UART_STATUS_TIMEOUT;
  919. break;
  920. case FLEXIO_UART_IP_STATUS_RX_OVERRUN:
  921. TempStatus = UART_STATUS_RX_OVERRUN_ERROR;
  922. break;
  923. default:
  924. TempStatus = UART_STATUS_DMA_ERROR;
  925. break;
  926. }
  927. return TempStatus;
  928. }
  929. /**
  930. * @internal
  931. * @brief Convert Uart HLD baudrate type to IP baudrate type.
  932. * @details This function receives HLD baudrate and convert to IP baudrate.
  933. * @param[in] Baudrate Uart HLD Baudrate
  934. *
  935. *
  936. * @return IP baudrate
  937. * This is not a public API as it is called from other driver functions.
  938. */
  939. static Flexio_Uart_Ip_BaudrateType Uart_Ipw_FlexioConvertBaudrateType(Uart_BaudrateType Baudrate)
  940. {
  941. Flexio_Uart_Ip_BaudrateType TempBaud = FLEXIO_UART_BAUDRATE_1200;
  942. switch (Baudrate)
  943. {
  944. case UART_BAUDRATE_1200:
  945. TempBaud = FLEXIO_UART_BAUDRATE_1200;
  946. break;
  947. case UART_BAUDRATE_2400:
  948. TempBaud = FLEXIO_UART_BAUDRATE_2400;
  949. break;
  950. case UART_BAUDRATE_4800:
  951. TempBaud = FLEXIO_UART_BAUDRATE_4800;
  952. break;
  953. case UART_BAUDRATE_9600:
  954. TempBaud = FLEXIO_UART_BAUDRATE_9600;
  955. break;
  956. case UART_BAUDRATE_14400:
  957. TempBaud = FLEXIO_UART_BAUDRATE_14400;
  958. break;
  959. case UART_BAUDRATE_19200:
  960. TempBaud = FLEXIO_UART_BAUDRATE_19200;
  961. break;
  962. case UART_BAUDRATE_28800:
  963. TempBaud = FLEXIO_UART_BAUDRATE_28800;
  964. break;
  965. case UART_BAUDRATE_38400:
  966. TempBaud = FLEXIO_UART_BAUDRATE_38400;
  967. break;
  968. case UART_BAUDRATE_57600:
  969. TempBaud = FLEXIO_UART_BAUDRATE_57600;
  970. break;
  971. case UART_BAUDRATE_115200:
  972. TempBaud = FLEXIO_UART_BAUDRATE_115200;
  973. break;
  974. case UART_BAUDRATE_230400:
  975. TempBaud = FLEXIO_UART_BAUDRATE_230400;
  976. break;
  977. case UART_BAUDRATE_460800:
  978. TempBaud = FLEXIO_UART_BAUDRATE_460800;
  979. break;
  980. case UART_BAUDRATE_921600:
  981. TempBaud = FLEXIO_UART_BAUDRATE_921600;
  982. break;
  983. case UART_BAUDRATE_1843200:
  984. TempBaud = FLEXIO_UART_BAUDRATE_1843200;
  985. break;
  986. default:
  987. /* Nothing to do */
  988. break;
  989. }
  990. return TempBaud;
  991. }
  992. #if (UART_CALLBACK_DECLARED == STD_ON)
  993. /**
  994. * @internal
  995. * @brief Convert Uart IP Event type to HLD Event type.
  996. * @details This function receives IP Event and convert to HLD Event.
  997. * @param[in] Event Uart IP Event
  998. *
  999. *
  1000. * @return HLD Event
  1001. * This is not a public API as it is called from other driver functions.
  1002. */
  1003. static Uart_EventType Uart_Ipw_FlexioConvertEventType(Flexio_Uart_Ip_EventType Event)
  1004. {
  1005. Uart_EventType TempEvent = UART_EVENT_ERROR;
  1006. switch (Event)
  1007. {
  1008. case FLEXIO_UART_IP_EVENT_RX_FULL:
  1009. TempEvent = UART_EVENT_RX_FULL;
  1010. break;
  1011. case FLEXIO_UART_IP_EVENT_TX_EMPTY:
  1012. TempEvent = UART_EVENT_TX_EMPTY;
  1013. break;
  1014. case FLEXIO_UART_IP_EVENT_END_TRANSFER:
  1015. TempEvent = UART_EVENT_END_TRANSFER;
  1016. break;
  1017. case FLEXIO_UART_IP_EVENT_ERROR:
  1018. TempEvent = UART_EVENT_ERROR;
  1019. break;
  1020. default:
  1021. /* Nothing to do */
  1022. break;
  1023. }
  1024. return TempEvent;
  1025. }
  1026. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  1027. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  1028. #if (UART_CALLBACK_DECLARED == STD_ON)
  1029. #ifdef UART_IPW_LPUART_HW_USING
  1030. /**
  1031. * @internal
  1032. * @internal
  1033. * @brief Low level driver callback for Lpuart
  1034. * @details This function is called by the low level driver in the ISR.
  1035. *
  1036. *
  1037. * This is not a public API as it is called from other driver functions.
  1038. */
  1039. void Uart_Ipw_LpuartCallback(const uint8 HwInstance, const Lpuart_Uart_Ip_EventType Event, void *UserData)
  1040. {
  1041. uint8 Channel = (uint8)Uart_Ipw_s8HwMapping[HwInstance];
  1042. Uart_EventType ConvertEvent = Uart_Ipw_LpuartConvertEventType(Event);
  1043. (void)UserData;
  1044. if (Uart_Ipw_apChnConfig[Channel]->Callback != NULL_PTR)
  1045. {
  1046. Uart_Ipw_apChnConfig[Channel]->Callback(Channel, ConvertEvent);
  1047. }
  1048. }
  1049. #endif /* #ifdef UART_IPW_LPUART_HW_USING */
  1050. #ifdef UART_IPW_FLEXIO_HW_USING
  1051. /**
  1052. * @internal
  1053. * @brief Low level driver Tx or Rx callback for Flexio
  1054. * @details This function is called by the low level driver in the ISR.
  1055. *
  1056. *
  1057. * This is not a public API as it is called from other driver functions.
  1058. */
  1059. void Uart_Ipw_FlexioTransferCallback(const uint32 HwChannel, const Flexio_Uart_Ip_EventType Event, void *UserData)
  1060. {
  1061. uint8 Channel = (uint8)Uart_Ipw_s8HwMapping[UART_NUMBER_OF_INSTANCES - FLEXIO_UART_IP_NUMBER_OF_SHIFTER_AND_TIMER + HwChannel];
  1062. Uart_EventType ConvertEvent = Uart_Ipw_FlexioConvertEventType(Event);
  1063. (void)UserData;
  1064. if (Uart_Ipw_apChnConfig[Channel]->Callback != NULL_PTR)
  1065. {
  1066. Uart_Ipw_apChnConfig[Channel]->Callback(Channel, ConvertEvent);
  1067. }
  1068. }
  1069. #endif /* #ifdef UART_IPW_FLEXIO_HW_USING */
  1070. #endif /* UART_CALLBACK_DECLARED == STD_ON */
  1071. #define UART_STOP_SEC_CODE
  1072. #include "Uart_MemMap.h"
  1073. #ifdef __cplusplus
  1074. }
  1075. /** @} */
  1076. #endif