1 /* 2 * Copyright 2021-2023 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 #ifndef LINFLEXD_UART_IP_H 7 #define LINFLEXD_UART_IP_H 8 9 /** 10 * @file 11 * @defgroup linflexd_uart_ip Linflexd UART IPL 12 * @addtogroup linflexd_uart_ip Linflexd UART IPL 13 * @{ 14 */ 15 16 #ifdef __cplusplus 17 extern "C"{ 18 #endif 19 20 /*================================================================================================== 21 * INCLUDE FILES 22 * 1) system and project includes 23 * 2) needed interfaces from external units 24 * 3) internal and external interfaces from this unit 25 ==================================================================================================*/ 26 #include "Linflexd_Uart_Ip_Types.h" 27 #include "Linflexd_Uart_Ip_Cfg.h" 28 /*================================================================================================== 29 * SOURCE FILE VERSION INFORMATION 30 ==================================================================================================*/ 31 #define LINFLEXD_UART_IP_VENDOR_ID 43 32 #define LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION 4 33 #define LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION 7 34 #define LINFLEXD_UART_IP_AR_RELEASE_REVISION_VERSION 0 35 #define LINFLEXD_UART_IP_SW_MAJOR_VERSION 1 36 #define LINFLEXD_UART_IP_SW_MINOR_VERSION 0 37 #define LINFLEXD_UART_IP_SW_PATCH_VERSION 0 38 /*================================================================================================== 39 * FILE VERSION CHECKS 40 ==================================================================================================*/ 41 /* Checks against Linflexd_Uart_Ip_Types.h */ 42 #if (LINFLEXD_UART_IP_VENDOR_ID != LINFLEXD_UART_IP_TYPES_VENDOR_ID) 43 #error "Linflexd_Uart_Ip.h and Linflexd_Uart_Ip_Types.h have different vendor ids" 44 #endif 45 #if ((LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION != LINFLEXD_UART_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \ 46 (LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION != LINFLEXD_UART_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \ 47 (LINFLEXD_UART_IP_AR_RELEASE_REVISION_VERSION != LINFLEXD_UART_IP_TYPES_AR_RELEASE_REVISION_VERSION) \ 48 ) 49 #error "AUTOSAR Version Numbers of Linflexd_Uart_Ip.h and Linflexd_Uart_Ip_Types.h are different" 50 #endif 51 #if ((LINFLEXD_UART_IP_SW_MAJOR_VERSION != LINFLEXD_UART_IP_TYPES_SW_MAJOR_VERSION) || \ 52 (LINFLEXD_UART_IP_SW_MINOR_VERSION != LINFLEXD_UART_IP_TYPES_SW_MINOR_VERSION) || \ 53 (LINFLEXD_UART_IP_SW_PATCH_VERSION != LINFLEXD_UART_IP_TYPES_SW_PATCH_VERSION) \ 54 ) 55 #error "Software Version Numbers of Linflexd_Uart_Ip.h and Linflexd_Uart_Ip_Types.h are different" 56 #endif 57 58 /* Checks against Linflexd_Uart_Ip_Cfg.h */ 59 #if (LINFLEXD_UART_IP_VENDOR_ID != LINFLEXD_UART_IP_CFG_VENDOR_ID) 60 #error "Linflexd_Uart_Ip.h and Linflexd_Uart_Ip_Cfg.h have different vendor ids" 61 #endif 62 #if ((LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION != LINFLEXD_UART_IP_CFG_AR_RELEASE_MAJOR_VERSION) || \ 63 (LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION != LINFLEXD_UART_IP_CFG_AR_RELEASE_MINOR_VERSION) || \ 64 (LINFLEXD_UART_IP_AR_RELEASE_REVISION_VERSION != LINFLEXD_UART_IP_CFG_AR_RELEASE_REVISION_VERSION) \ 65 ) 66 #error "AUTOSAR Version Numbers of Linflexd_Uart_Ip.h and Linflexd_Uart_Ip_Cfg.h are different" 67 #endif 68 #if ((LINFLEXD_UART_IP_SW_MAJOR_VERSION != LINFLEXD_UART_IP_CFG_SW_MAJOR_VERSION) || \ 69 (LINFLEXD_UART_IP_SW_MINOR_VERSION != LINFLEXD_UART_IP_CFG_SW_MINOR_VERSION) || \ 70 (LINFLEXD_UART_IP_SW_PATCH_VERSION != LINFLEXD_UART_IP_CFG_SW_PATCH_VERSION) \ 71 ) 72 #error "Software Version Numbers of Linflexd_Uart_Ip.h and Linflexd_Uart_Ip_Cfg.h are different" 73 #endif 74 75 /*================================================================================================== 76 * CONSTANTS 77 ==================================================================================================*/ 78 #define UART_START_SEC_CONFIG_DATA_UNSPECIFIED 79 #include "Uart_MemMap.h" 80 /* Calling the external Configuration symbols defined by Linflexd_Uart_Ip_Cfg.h */ 81 LINFLEXD_UART_IP_CONFIG_EXT 82 #define UART_STOP_SEC_CONFIG_DATA_UNSPECIFIED 83 #include "Uart_MemMap.h" 84 /*================================================================================================== 85 * DEFINES AND MACROS 86 ==================================================================================================*/ 87 88 /*================================================================================================== 89 * ENUMS 90 ==================================================================================================*/ 91 92 /*================================================================================================== 93 * STRUCTURES AND OTHER TYPEDEFS 94 ==================================================================================================*/ 95 96 /*================================================================================================== 97 * GLOBAL VARIABLE DECLARATIONS 98 ==================================================================================================*/ 99 100 /*================================================================================================== 101 * FUNCTION PROTOTYPES 102 ==================================================================================================*/ 103 104 #define UART_START_SEC_CODE 105 #include "Uart_MemMap.h" 106 107 /** 108 * @brief Sets the baud rate for UART communication. 109 * 110 * @details This function computes the fractional and integer parts of the baud rate divisor 111 * to obtain the desired baud rate using the current protocol clock. 112 * 113 * @param[in] Instance - LINFLEXD hardware instance number. 114 * @param[in] DesiredBaudRate - Desired baud rate. 115 * @param[in] ClockFrequency - the current clock frequency used in the baud rate parameters calculations. 116 * @return Linflexd_Uart_Ip_StatusType 117 * @retval LINFLEXD_UART_IP_STATUS_BUSY - A trasfer is ongoing, therefore a baurate value change can't be possible. 118 * @retval LINFLEXD_UART_IP_STATUS_ERROR - Error in changing the baudrate. 119 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Baudrate value changed successfully. 120 */ 121 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_SetBaudrate(const uint8 Instance, 122 const Linflexd_Uart_Ip_BaudrateType DesiredBaudRate, 123 const uint32 ClockFrequency 124 ); 125 126 127 /** 128 * @brief Gets the baud rate for UART communication. 129 * 130 * @details This function returns the current UART baud rate, according to register values 131 * and the protocol clock frequency. 132 * 133 * @param[in] Instance - LINFLEXD hardware instance number. 134 * @param[out] ConfiguredBaudRate - Pointer to a valid memory location where the current baudrate value will be provided. 135 * @return void 136 */ 137 void Linflexd_Uart_Ip_GetBaudrate(const uint8 Instance, uint32 * ConfiguredBaudRate); 138 139 140 /** 141 * @brief Initializes a LINFLEXD instance for UART operations. 142 * 143 * 144 * @param Instance[in] - LINFLEXD hardware instance number. 145 * @param UserConfig[in] - User configuration structure. 146 * @return void 147 */ 148 void Linflexd_Uart_Ip_Init(const uint8 Instance, const Linflexd_Uart_Ip_UserConfigType * UserConfig); 149 150 151 /** 152 * @brief Shuts down the UART functionality of the LINFLEXD module 153 * by disabling interrupts and transmitter/receiver. 154 * 155 * @param Instance[in] - LINFLEXD hardware instance number. 156 * @retval LINFLEXD_UART_IP_STATUS_ERROR - The current transfer processes are not finished completely 157 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Operation ended successfully. 158 */ 159 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_Deinit(const uint8 Instance); 160 161 /** 162 * @brief Sets the internal driver reference to the tx buffer. 163 * 164 * @details This function can be called from the tx callback to provide the driver 165 * with a new buffer, for continuous transmission. 166 * 167 * @param Instance[in] - LINFLEXD hardware instance number. 168 * @param TxBuff[in] - Source buffer containing 8-bit data chars to send. 169 * @param TxSize[in] - The number of bytes to send. 170 * @return void 171 */ 172 void Linflexd_Uart_Ip_SetTxBuffer(const uint8 Instance, const uint8 * TxBuff, const uint32 TxSize); 173 174 175 /** 176 * @brief Sets the internal driver reference to the rx buffer. 177 * 178 * @details This function can be called from the rx callback to provide the driver 179 * with a new buffer, for continuous reception. 180 * 181 * @param Instance[in] - LINFLEXD hardware instance number. 182 * @param TxBuff[in] - Source buffer containing 8-bit data chars to receive. 183 * @param TxSize[in] - The number of bytes to receive. 184 * @return void 185 */ 186 void Linflexd_Uart_Ip_SetRxBuffer(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize); 187 188 189 /** 190 * @brief Terminates a non-blocking receive early. 191 * 192 * @param Instance[in] - LINFLEXD hardware instance number 193 * 194 * @return Linflexd_Uart_Ip_StatusType 195 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Operation has been successfully ended or no operation was on-going. 196 */ 197 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AbortReceivingData(const uint8 Instance); 198 199 200 /** 201 * @brief Terminates a non-blocking transfer(send) early. 202 * 203 * @param Instance[in] - LINFLEXD hardware instance number 204 * 205 * @return Linflexd_Uart_Ip_StatusType 206 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Operation has been successfully ended or no operation was on-going. 207 */ 208 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AbortSendingData(const uint8 Instance); 209 210 211 /** 212 * @brief Sends data using LINFLEXD module in UART mode with polling method. 213 * 214 * @details Blocking means that the function does not return until the transmission is complete. 215 * 216 * @param Instance[in] - LINFLEXD hardware instance number. 217 * @param TxBuff[in] - Source buffer containing 8-bit data chars to send. 218 * @param TxSize[in] - TxBuff size. 219 * @param Timeout[in] Timeout value in microseconds. 220 * @return Linflexd_Uart_Ip_StatusType 221 * @retval LINFLEXD_UART_IP_STATUS_BUSY - A trasfer is ongoing, therefore a new transfer can't begin. 222 * @retval LINFLEXD_UART_IP_STATUS_ERROR - Error in transmission. 223 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Operation ended successfully. 224 * @retval LINFLEXD_UART_IP_STATUS_TIMEOUT - Operation has timeout. 225 */ 226 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_SyncSend(const uint8 Instance, const uint8 *TxBuff, const uint32 TxSize, const uint32 Timeout); 227 228 /** 229 * @brief Sends data using LINFLEXD module in UART mode with polling method. 230 * 231 * @details Blocking means that the function does not return until the transmission is complete. 232 * 233 * @param Instance[in] - LINFLEXD hardware instance number. 234 * @param RxBuff[in] - Source buffer containing 8-bit data chars to receive. 235 * @param RxSize[in] - RxBuff size. 236 * @param Timeout[in] Timeout value in microseconds. 237 * @return Linflexd_Uart_Ip_StatusType 238 * @retval LINFLEXD_UART_IP_STATUS_BUSY - A trasfer is ongoing, therefore a new transfer can't begin. 239 * @retval LINFLEXD_UART_IP_STATUS_ERROR - Error in reception. 240 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Operation ended successfully. 241 * @retval LINFLEXD_UART_IP_STATUS_TIMEOUT - Operation has timeout. 242 */ 243 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_SyncReceive(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize, const uint32 Timeout); 244 245 /** 246 * @brief Starts data reception from the LINFLEXD module in UART mode with non-blocking method. 247 * @details This enables an a-sync method for receiving data. When used with 248 * a non-blocking transmission, the UART driver can perform a full duplex operation. 249 * Non-blocking means that the function returns immediately. 250 * The application has to get the receive status to know when the receive is complete. 251 * 252 * @param Instance[in] - LINFLEXD hardware instance number. 253 * @param RxBuff[in] - Buffer containing 8-bit read data chars to be received. 254 * @param RxSize[in] - Size of RxBuff. 255 * @return Linflexd_Uart_Ip_StatusType 256 * @retval LINFLEXD_UART_IP_STATUS_BUSY - A trasfer is ongoing, therefore a new transfer can't begin. 257 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Operation started successfully. 258 */ 259 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AsyncReceive(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize); 260 261 /** 262 * @brief Sends data using LINFLEXD module in UART mode with non-blocking method. 263 * 264 * @details This enables an a-sync method for transmitting data. When used with 265 * a non-blocking receive, the UART driver can perform a full duplex operation. 266 * Non-blocking means that the function returns immediately. 267 * The application has to get the transmit status to know when the transmission is complete. 268 * 269 * @param Instance[in] - LINFLEXD hardware instance number. 270 * @param TxBuff[in] - source buffer containing 8-bit data chars to send. 271 * @param TxSize[in] - the number of bytes to send. 272 * @return Linflexd_Uart_Ip_StatusType 273 * @retval LINFLEXD_UART_IP_STATUS_BUSY - A trasfer is ongoing, therefore a new transfer can't begin. 274 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Operation started successfully. 275 */ 276 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AsyncSend(const uint8 Instance, const uint8 * TxBuff, const uint32 TxSize); 277 278 279 /** 280 * @brief Returns whether the status of the previous transmission. 281 * 282 * @param Instance[in] - LINFLEXD hardware instance number. 283 * @param BytesRemaining[out] - Pointer to value that is populated with the number of bytes that 284 * have been sent in the active transfer. 285 * @note In DMA mode, this parameter may not be accurate, in case the transfer completes 286 * right after calling this function; in this edge-case, the parameter will reflect 287 * the initial transfer size, due to automatic reloading of the major loop count 288 * in the DMA transfer descriptor. 289 * @return Linflexd_Uart_Ip_StatusType 290 * @retval LINFLEXD_UART_IP_STATUS_BUSY - A trasfer is ongoing. 291 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Previous operation ended successfully. 292 * @retval LINFLEXD_UART_IP_STATUS_ERROR - Previous operation had a DMA error. 293 * @retval LINFLEXD_UART_IP_STATUS_ABORTED - Previous transfer has been aborted 294 * @retval LINFLEXD_UART_IP_STATUS_DMA_ERROR - Previous transfer has DMA errors. 295 */ 296 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_GetTransmitStatus(const uint8 Instance, uint32 * BytesRemaining); 297 298 299 /** 300 * @brief Returns whether the status of the previous reception. 301 * 302 * @param Instance[in] - LINFLEXD hardware instance number 303 * @param BytesRemaining[out] - Pointer to value that is filled with the number of bytes that 304 * still need to be received in the active transfer. 305 * @note The parameter BytesRemaining may not be accurate, in case the transfer completes 306 * right after calling this function; in this edge-case, this parameter will 307 * have the wrong value. 308 * @return Linflexd_Uart_Ip_StatusType 309 * @retval LINFLEXD_UART_IP_STATUS_BUSY - A trasfer is ongoing. 310 * @retval LINFLEXD_UART_IP_STATUS_SUCCESS - Previous operation ended successfully. 311 * @retval LINFLEXD_UART_IP_STATUS_RX_OVERRUN - Previous operation had an overrun error. 312 * @retval LINFLEXD_UART_IP_STATUS_FRAMING_ERROR - Previous operation had a framing error. 313 * @retval LINFLEXD_UART_IP_STATUS_DMA_ERROR - Previous transfer has DMA errors. 314 * @retval LINFLEXD_UART_IP_STATUS_ABORTED - Previous transfer has been aborted 315 * @retval LINFLEXD_UART_IP_STATUS_PARITY_ERROR - A parity error occured 316 * @retval LINFLEXD_UART_IP_STATUS_NOISE_ERROR - A noise error occured 317 */ 318 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_GetReceiveStatus(const uint8 Instance, uint32 * BytesRemaining); 319 320 void Linflexd_Uart_Ip_IRQHandler(uint8 Instance); 321 322 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON) 323 /** 324 * @internal 325 * @brief : Finish up a transmit by completing the process of sending 326 * data and disabling the DMA requests. This is a part of callback for DMA major loop 327 * completion, so it must match the DMA callback signature. 328 * @param Instance LINFLEXD hardware instance number 329 * @return void 330 */ 331 void Linflexd_Uart_Ip_CompleteSendUsingDma(uint8 Instance); 332 333 /** 334 * @internal 335 * @brief : Finish up a receive by completing the process of receiving data 336 * and disabling the DMA requests. This is a part of callback for DMA major loop 337 * completion, so it must match the DMA callback signature. 338 * @param Instance LINFLEXD hardware instance number 339 * @return void 340 */ 341 void Linflexd_Uart_Ip_CompleteReceiveUsingDma(uint8 Instance); 342 #endif 343 344 #define UART_STOP_SEC_CODE 345 #include "Uart_MemMap.h" 346 347 #ifdef __cplusplus 348 } 349 #endif 350 351 /** @} */ 352 353 #endif /* LINFLEXD_UART_IP_DRIVER_H */ 354