Uart.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 UART_H
  25. #define UART_H
  26. /**
  27. * @file
  28. *
  29. * @defgroup uart_driver UART Driver
  30. * @addtogroup uart_driver UART Driver
  31. * @{
  32. */
  33. #ifdef __cplusplus
  34. extern "C"
  35. {
  36. #endif
  37. /*==================================================================================================
  38. * INCLUDE FILES
  39. * 1) system and project includes
  40. * 2) needed interfaces from external units
  41. * 3) internal and external interfaces from this unit
  42. ==================================================================================================*/
  43. #include "Mcal.h"
  44. #include "Uart_Cfg.h"
  45. #include "Uart_Defines.h"
  46. #include "Uart_Types.h"
  47. #include "Uart_Ipw.h"
  48. /*==================================================================================================
  49. * SOURCE FILE VERSION INFORMATION
  50. ==================================================================================================*/
  51. #define UART_MODULE_ID 255
  52. #define UART_AR_RELEASE_MAJOR_VERSION 4
  53. #define UART_AR_RELEASE_MINOR_VERSION 4
  54. #define UART_AR_RELEASE_REVISION_VERSION 0
  55. #define UART_SW_MAJOR_VERSION 1
  56. #define UART_SW_MINOR_VERSION 0
  57. #define UART_SW_PATCH_VERSION 0
  58. #define UART_VENDOR_ID 43
  59. /*==================================================================================================
  60. FILE VERSION CHECKS
  61. ==================================================================================================*/
  62. /*Checks against Uart_Defines.h */
  63. #if (UART_VENDOR_ID!= UART_DEFINES_VENDOR_ID_CFG)
  64. #error "Uart.h and Uart_Defines.h have different vendor ids"
  65. #endif
  66. #if ((UART_AR_RELEASE_MAJOR_VERSION != UART_DEFINES_AR_RELEASE_MAJOR_VERSION_CFG) || \
  67. (UART_AR_RELEASE_MINOR_VERSION != UART_DEFINES_AR_RELEASE_MINOR_VERSION_CFG) || \
  68. (UART_AR_RELEASE_REVISION_VERSION!= UART_DEFINES_AR_RELEASE_REVISION_VERSION_CFG))
  69. #error "AUTOSAR Version Numbers of Uart.h and Uart_Defines.h are different"
  70. #endif
  71. #if ((UART_SW_MAJOR_VERSION!= UART_DEFINES_SW_MAJOR_VERSION_CFG) || \
  72. (UART_SW_MINOR_VERSION!= UART_DEFINES_SW_MINOR_VERSION_CFG) || \
  73. (UART_SW_PATCH_VERSION!= UART_DEFINES_SW_PATCH_VERSION_CFG) \
  74. )
  75. #error "Software Version Numbers of Uart.h and Uart_Defines.h are different"
  76. #endif
  77. /*Checks against Uart_Ipw.h */
  78. #if (UART_VENDOR_ID!= UART_IPW_VENDOR_ID)
  79. #error "Uart.h and Uart_Ipw.h have different vendor ids"
  80. #endif
  81. #if ((UART_AR_RELEASE_MAJOR_VERSION != UART_IPW_AR_RELEASE_MAJOR_VERSION) || \
  82. (UART_AR_RELEASE_MINOR_VERSION != UART_IPW_AR_RELEASE_MINOR_VERSION) || \
  83. (UART_AR_RELEASE_REVISION_VERSION!= UART_IPW_AR_RELEASE_REVISION_VERSION))
  84. #error "AUTOSAR Version Numbers of Uart.h and Uart_Ipw.h are different"
  85. #endif
  86. #if ((UART_SW_MAJOR_VERSION!= UART_IPW_SW_MAJOR_VERSION) || \
  87. (UART_SW_MINOR_VERSION!= UART_IPW_SW_MINOR_VERSION) || \
  88. (UART_SW_PATCH_VERSION!= UART_IPW_SW_PATCH_VERSION) \
  89. )
  90. #error "Software Version Numbers of Uart.h and Uart_Ipw.h are different"
  91. #endif
  92. /* Checks against Uart_Cfg.h */
  93. #if (UART_VENDOR_ID != UART_CFG_VENDOR_ID)
  94. #error "Uart.h and Uart_Cfg.h have different vendor ids"
  95. #endif
  96. #if ((UART_AR_RELEASE_MAJOR_VERSION != UART_CFG_AR_RELEASE_MAJOR_VERSION) || \
  97. (UART_AR_RELEASE_MINOR_VERSION != UART_CFG_AR_RELEASE_MINOR_VERSION) || \
  98. (UART_AR_RELEASE_REVISION_VERSION!= UART_CFG_AR_RELEASE_REVISION_VERSION))
  99. #error "AUTOSAR Version Numbers of Uart.h and Uart_Cfg.h are different"
  100. #endif
  101. #if ((UART_SW_MAJOR_VERSION!= UART_CFG_SW_MAJOR_VERSION) || \
  102. (UART_SW_MINOR_VERSION!= UART_CFG_SW_MINOR_VERSION) || \
  103. (UART_SW_PATCH_VERSION!= UART_CFG_SW_PATCH_VERSION) \
  104. )
  105. #error "Software Version Numbers of Uart.h and Uart_Cfg.h are different"
  106. #endif
  107. /* Checks against Uart_Types.h */
  108. #if (UART_VENDOR_ID != UART_TYPES_VENDOR_ID)
  109. #error "Uart.h and Uart_Types.h have different vendor ids"
  110. #endif
  111. #if ((UART_AR_RELEASE_MAJOR_VERSION != UART_TYPES_AR_RELEASE_MAJOR_VERSION) || \
  112. (UART_AR_RELEASE_MINOR_VERSION != UART_TYPES_AR_RELEASE_MINOR_VERSION) || \
  113. (UART_AR_RELEASE_REVISION_VERSION!= UART_TYPES_AR_RELEASE_REVISION_VERSION))
  114. #error "AUTOSAR Version Numbers of Uart.h and Uart_Types.h are different"
  115. #endif
  116. #if ((UART_SW_MAJOR_VERSION!= UART_TYPES_SW_MAJOR_VERSION) || \
  117. (UART_SW_MINOR_VERSION!= UART_TYPES_SW_MINOR_VERSION) || \
  118. (UART_SW_PATCH_VERSION!= UART_TYPES_SW_PATCH_VERSION) \
  119. )
  120. #error "Software Version Numbers of Uart.h and Uart_Types.h are different"
  121. #endif
  122. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  123. /* Checks against Mcal.h */
  124. #if ((UART_AR_RELEASE_MAJOR_VERSION != MCAL_AR_RELEASE_MAJOR_VERSION) || \
  125. (UART_AR_RELEASE_MINOR_VERSION != MCAL_AR_RELEASE_MINOR_VERSION))
  126. #error "AUTOSAR Version Numbers of Uart.h and Mcal.h are different"
  127. #endif
  128. #endif
  129. /*==================================================================================================
  130. * CONSTANTS
  131. ==================================================================================================*/
  132. /*==================================================================================================
  133. DEFINES AND MACROS
  134. ==================================================================================================*/
  135. /*==================================================================================================
  136. ENUMS
  137. ==================================================================================================*/
  138. /*==================================================================================================
  139. * STRUCTURES AND OTHER TYPEDEFS
  140. ==================================================================================================*/
  141. /*==================================================================================================
  142. GLOBAL VARIABLE DECLARATIONS
  143. ==================================================================================================*/
  144. #define UART_START_SEC_CONFIG_DATA_UNSPECIFIED
  145. /* @violates @ref Uart_h_REF_1 This violation is not fixed since the inclusion of Uart_MemMap.h is as per AUTOSAR requirement*/
  146. #include "Uart_MemMap.h"
  147. #if STD_OFF == UART_PRECOMPILE_SUPPORT
  148. UART_CONFIG_EXT
  149. #endif
  150. #define UART_STOP_SEC_CONFIG_DATA_UNSPECIFIED
  151. /* @violates @ref Uart_h_REF_1 This violation is not fixed since the inclusion of Uart_MemMap.h is as per AUTOSAR requirement*/
  152. #include "Uart_MemMap.h"
  153. /*==================================================================================================
  154. * FUNCTION PROTOTYPES
  155. ==================================================================================================*/
  156. #define UART_START_SEC_CODE
  157. #include "Uart_MemMap.h"
  158. /**
  159. * @brief Initializes the UART module.
  160. * @details This function performs software initialization of UART
  161. * driver. It shall configure the Uart hardware peripheral for each channel.
  162. *
  163. * @param[in] Config - Pointer to UART driver configuration set.
  164. *
  165. * @return void
  166. *
  167. * @pre -
  168. *
  169. *
  170. **/
  171. void Uart_Init(const Uart_ConfigType * Config);
  172. /**
  173. * @brief De-initializes the UART module.
  174. * @details This function performs software de-initialization of UART
  175. * driver.
  176. *
  177. * @param -
  178. *
  179. * @return void
  180. *
  181. * @pre -
  182. *
  183. *
  184. **/
  185. void Uart_Deinit(void);
  186. /**
  187. * @brief Configures the baud rate for the serial communication.
  188. * @details This function performs the setting of the communication baudrate provided in the parameter.
  189. *
  190. * @param[in] Channel - Uart channel to be addressed.
  191. * @param[in] Baudrate - Baudrate value to be set.
  192. *
  193. * @return Std_ReturnType.
  194. * @retval E_NOT_OK If the Uart Channel is not valid or
  195. * Uart driver is not initialized or
  196. * a transfer is on-going or
  197. * wrong core is addressed.
  198. *
  199. * @retval E_OK Successfull baudrate configuration.
  200. *
  201. *
  202. * @pre Uart_Init function must be called before this API.
  203. *
  204. *
  205. **/
  206. Std_ReturnType Uart_SetBaudrate(uint8 Channel, Uart_BaudrateType Baudrate);
  207. /**
  208. * @brief Retrieves the baud rate which is currently set for the serial communication.
  209. * @details This function returns via the second parameter the current serial baudrate.
  210. *
  211. * @param[in] Channel - Uart channel to be addressed.
  212. * @param[out] Baudrate - Pointer to a memory location where the baudrate value is returned.
  213. *
  214. * @return Std_ReturnType.
  215. * @retval E_NOT_OK If the Uart Channel is not valid or
  216. * Uart driver is not initialized or
  217. * a transfer is on-going or
  218. * wrong core is addressed or
  219. * a NULL_PTR pointer has been provided
  220. *
  221. * @retval E_OK Successfull baudrate retrieval.
  222. *
  223. *
  224. * @pre Uart_Init function must be called before this API. Otherwise a random value can be returned.
  225. *
  226. *
  227. **/
  228. Std_ReturnType Uart_GetBaudrate(uint8 Channel, uint32 *Baudrate);
  229. /**
  230. * @brief Configures a new buffer for continuous transfers.
  231. * @details This function can be called inside a notification callback and
  232. * offers the possibility to change the buffer in order to assure a
  233. * continuous asynchronous transfer.
  234. * @param[in] Channel - Uart channel to be addressed.
  235. * @param[in] Buffer - The new buffer provided.
  236. * @param[in] BufferSize - The size of the new buffer.
  237. * @param[in] Direction - This parameter indicates for which type of transmission is the buffer set. Its values are UART_SEND for
  238. * setting a buffer when the previous buffer is empty and there are more bytes to send and UART_RECEIVE to set
  239. * a new buffer when the previous buffer is full with received buffer and there is more data to be received.
  240. *
  241. * @return Std_ReturnType.
  242. * @retval E_NOT_OK If the Uart Channel is not valid or
  243. * Uart driver is not initialized or
  244. * Buffer is a NULL_PTR or
  245. * BufferSize is 0, meaning no space has been allocated for the buffer or
  246. * a wrong core has been accessed
  247. *
  248. * @retval E_OK Successfull buffer setting.
  249. *
  250. *
  251. * @pre Uart_Init function must be called before this API.
  252. *
  253. *
  254. **/
  255. Std_ReturnType Uart_SetBuffer(uint8 Channel, uint8* Buffer, uint32 BufferSize, Uart_DataDirectionType Direction);
  256. /**
  257. * @brief Starts a synchronous transfer of bytes.
  258. * @details This function starts sending a number of bytes in a synchronous manner.
  259. *
  260. * @param[in] Channel - Uart channel to be addressed.
  261. * @param[in] Buffer - The buffer which contains the bytes to be sent.
  262. * @param[in] BufferSize - The Buffer size.
  263. * @param[in] Timeout - The timeout in us.
  264. * @return Std_ReturnType.
  265. * @retval E_NOT_OK If the Uart Channel is not valid or
  266. * Uart driver is not initialized or
  267. * Buffer is a NULL_PTR or
  268. * BufferSize is 0, meaning no space has been allocated for the buffer or
  269. * a wrong core has been accessed or
  270. * a transfer is already on going on the requested channel or
  271. * timeout occured.
  272. *
  273. * @retval E_OK Successful transfer.
  274. *
  275. *
  276. * @pre Uart_Init function must be called before this API.
  277. *
  278. *
  279. **/
  280. Std_ReturnType Uart_SyncSend(uint8 Channel, const uint8* Buffer, uint32 BufferSize, uint32 Timeout);
  281. /**
  282. * @brief Starts a synchronous reception of bytes.
  283. * @details This function starts receiving a number of bytes in a synchronous manner.
  284. *
  285. * @param[in] Channel - Uart channel to be addressed.
  286. * @param[in] Buffer - The buffer where the bytes will be located.
  287. * @param[in] BufferSize - The Buffer size.
  288. * @param[in] Timeout - The timeout in us.
  289. *
  290. * @return Std_ReturnType.
  291. * @retval E_NOT_OK If the Uart Channel is not valid or
  292. * Uart driver is not initialized or
  293. * Buffer is a NULL_PTR or
  294. * BufferSize is 0, meaning no space has been allocated for the buffer or
  295. * a wrong core has been accessed or
  296. * a reception is already on going on the requested channel or
  297. * timeout occured.
  298. *
  299. * @retval E_OK Successful reception.
  300. *
  301. *
  302. * @pre Uart_Init function must be called before this API.
  303. *
  304. *
  305. **/
  306. Std_ReturnType Uart_SyncReceive(uint8 Channel, uint8* Buffer, uint32 BufferSize, uint32 Timeout);
  307. /**
  308. * @brief Aborts an on-going transfer.
  309. * @details This function aborts either a reception or a transmission depending on the last parameter.
  310. *
  311. * @param[in] Channel - Uart channel to be addressed.
  312. * @param[in] TransmissionType - Type of the transfer to be aborted. It can be either UART_SEND or UART_RECEIVE.
  313. *
  314. * @return Std_ReturnType.
  315. * @retval E_NOT_OK If the Uart Channel is not valid or
  316. * Uart driver is not initialized or
  317. * a wrong core has been accessed
  318. *
  319. * @retval E_OK Successful transfer aborted or in case no transfer was on going.
  320. *
  321. *
  322. * @pre Uart_Init function must be called before this API.
  323. *
  324. *
  325. **/
  326. Std_ReturnType Uart_Abort(uint8 Channel, Uart_DataDirectionType TransmissionType);
  327. /**
  328. * @brief Starts an asynchronous transfer(send) of bytes.
  329. * @details This function starts sending a number of bytes in an asynchronous manner. The transfer can be performed using
  330. * either DMA or interrupts depending on the transfer type configured on the addressed channel.
  331. *
  332. * @param[in] Channel - Uart channel to be addressed.
  333. * @param[in] Buffer - The buffer where the data to be sent is located.
  334. * @param[in] BufferSize - The Buffer size.
  335. *
  336. * @return Std_ReturnType.
  337. * @retval E_NOT_OK If the Uart Channel is not valid or
  338. * Uart driver is not initialized or
  339. * Buffer is a NULL_PTR or
  340. * BufferSize is 0, meaning no space has been allocated for the buffer or
  341. * a wrong core has been accessed or
  342. * a transfer(send) is already on going on the requested channel.
  343. *
  344. * @retval E_OK The transfer(send) started successfully.
  345. *
  346. *
  347. * @pre Uart_Init function must be called before this API.
  348. *
  349. *
  350. **/
  351. Std_ReturnType Uart_AsyncSend(uint8 Channel, const uint8* Buffer, uint32 BufferSize);
  352. /**
  353. * @brief Starts an asynchronous transfer(receive) of bytes.
  354. * @details This function starts receiving a number of bytes in an asynchronous manner. The transfer can be performed using
  355. * either DMA or interrupts depending on the transfer type configured on the addressed channel.
  356. *
  357. * @param[in] Channel - Uart channel to be addressed.
  358. * @param[in] Buffer - The buffer where the data to be received will located.
  359. * @param[in] BufferSize - The Buffer size.
  360. *
  361. * @return Std_ReturnType.
  362. * @retval E_NOT_OK If the Uart Channel is not valid or
  363. * Uart driver is not initialized or
  364. * Buffer is a NULL_PTR or
  365. * BufferSize is 0, meaning no space has been allocated for the buffer or
  366. * a wrong core has been accessed or
  367. * a transfer(receive) is already on going on the requested channel.
  368. *
  369. * @retval E_OK The transfer(receive) started successfully.
  370. *
  371. *
  372. * @pre Uart_Init function must be called before this API.
  373. *
  374. *
  375. **/
  376. Std_ReturnType Uart_AsyncReceive(uint8 Channel, uint8* Buffer, uint32 BufferSize);
  377. /**
  378. * @brief Returns the status of the previous transfer.
  379. * @details This function returns the status of the previous transfer.
  380. * If there is a transfer in progress, this function will also get the number of remaining bytes at the time the function was called.
  381. * @param[in] Channel - Uart channel to be addressed.
  382. * @param[out] BytesTransfered - A pointer where the number of remaining bytes will be written.
  383. * @param[in] TransferType - The type of trasfer in discussion (UART_SEND or UART_RECEIVE).
  384. *
  385. * @return Uart_StatusType.
  386. * @retval UART_STATUS_NO_ERROR - Operation has ended successfully.
  387. * @retval UART_STATUS_FRAMING_ERROR - Operation has had a framing error. This status is returned only if the TransferType parameter is RECEIVE.
  388. * @retval UART_STATUS_RX_OVERRUN_ERROR - Operation has had an overrun error. This status is returned only if the TransferType parameter is RECEIVE.
  389. * @retval UART_STATUS_PARITY_ERROR - Operation has had a parity error. This status is returned only if the TransferType parameter is RECEIVE.
  390. * @retval UART_STATUS_OPERATION_ONGOING - Operation has not finished at the moment of function call.
  391. * @retval UART_STATUS_ABORTED - Operation has been aborted.
  392. * @retval UART_STATUS_TIMEOUT - Operation has had timeout.
  393. *
  394. *
  395. * @pre Uart_Init function must be called before this API.
  396. *
  397. *
  398. **/
  399. Uart_StatusType Uart_GetStatus( uint8 Channel, uint32 *BytesTransfered, Uart_DataDirectionType TransferType);
  400. #if (UART_VERSION_INFO_API == STD_ON)
  401. /**
  402. * @brief Returns the version information of this module.
  403. * @details The version information includes:
  404. *
  405. * - Two bytes for the Vendor ID
  406. * - Two bytes for the Module ID
  407. * - One byte for the Instance ID
  408. * - Three bytes version number. The numbering shall be vendor
  409. * specific: it consists of:
  410. *
  411. * - The major, the minor and the patch version number of
  412. * the module;
  413. * - The AUTOSAR specification version number shall not
  414. * be included. The AUTOSAR specification version number is
  415. * checked during compile time and therefore not required
  416. * in this API.
  417. *
  418. * @param[in,out] VersionInfo Pointer for storing the version information
  419. * of this module.
  420. *
  421. * @return void.
  422. *
  423. *
  424. *
  425. *
  426. **/
  427. void Uart_GetVersionInfo (Std_VersionInfoType * VersionInfo);
  428. #endif /* (UART_VERSION_INFO_API == STD_ON) */
  429. #define UART_STOP_SEC_CODE
  430. #include "Uart_MemMap.h"
  431. #ifdef __cplusplus
  432. }
  433. #endif
  434. /** @} */
  435. #endif /* UART_H */