1 /*
2  * Copyright 2021-2024 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 /**
7 *   @file     Linflexd_Uart_Ip.c
8 *   @defgroup linflexd_uart_ip Linflexd UART IPL
9 *   @addtogroup  linflexd_uart_ip Linflexd UART IPL
10 *   @{
11 */
12 
13 #ifdef __cplusplus
14 extern "C"{
15 #endif
16 
17 /*==================================================================================================
18 *                                          INCLUDE FILES
19 * 1) system and project includes
20 * 2) needed interfaces from external units
21 * 3) internal and external interfaces from this unit
22 ==================================================================================================*/
23 
24 #include "Linflexd_Uart_Ip.h"
25 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
26     #include "Dma_Ip.h"
27 #endif
28 
29 #ifdef LINFLEXD_UART_IP_DEV_ERROR_DETECT
30     #if (LINFLEXD_UART_IP_DEV_ERROR_DETECT == STD_ON)
31         #include "Devassert.h"
32     #endif /* (STD_ON == LINFLEXD_UART_IP_DEV_ERROR_DETECT) */
33 #endif /* ifdef LINFLEXD_UART_IP_DEV_ERROR_DETECT */
34 
35 #if (STD_ON == LINFLEXD_UART_IP_SET_USER_ACCESS_ALLOWED_AVAILABLE)
36     #define USER_MODE_REG_PROT_ENABLED      (STD_ON)
37     #include "RegLockMacros.h"
38 #endif
39 /*==================================================================================================
40 *                                 SOURCE FILE VERSION INFORMATION
41 ==================================================================================================*/
42 
43 #define LINFLEXD_UART_IP_VENDOR_ID_C                      43
44 #define LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION_C       4
45 #define LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION_C       7
46 #define LINFLEXD_UART_IP_AR_RELEASE_REVISION_VERSION_C    0
47 #define LINFLEXD_UART_IP_SW_MAJOR_VERSION_C               2
48 #define LINFLEXD_UART_IP_SW_MINOR_VERSION_C               0
49 #define LINFLEXD_UART_IP_SW_PATCH_VERSION_C               0
50 
51 /*==================================================================================================
52 *                                       FILE VERSION CHECKS
53 ==================================================================================================*/
54 /* Checks against Linflexd_Uart_Ip.h */
55 #if (LINFLEXD_UART_IP_VENDOR_ID_C != LINFLEXD_UART_IP_VENDOR_ID)
56     #error "Linflexd_Uart_Ip.c and Linflexd_Uart_Ip.h have different vendor ids"
57 #endif
58 #if ((LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION_C    != LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION) || \
59      (LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION_C    != LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION) || \
60      (LINFLEXD_UART_IP_AR_RELEASE_REVISION_VERSION_C != LINFLEXD_UART_IP_AR_RELEASE_REVISION_VERSION) \
61     )
62      #error "AUTOSAR Version Numbers of Linflexd_Uart_Ip.c and Linflexd_Uart_Ip.h are different"
63 #endif
64 #if ((LINFLEXD_UART_IP_SW_MAJOR_VERSION_C != LINFLEXD_UART_IP_SW_MAJOR_VERSION) || \
65      (LINFLEXD_UART_IP_SW_MINOR_VERSION_C != LINFLEXD_UART_IP_SW_MINOR_VERSION) || \
66      (LINFLEXD_UART_IP_SW_PATCH_VERSION_C != LINFLEXD_UART_IP_SW_PATCH_VERSION) \
67     )
68     #error "Software Version Numbers of Linflexd_Uart_Ip.c and Linflexd_Uart_Ip.h are different"
69 #endif
70 
71 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
72     /* Checks against Dma_Ip.h */
73     #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
74         #if ((LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION_C != DMA_IP_AR_RELEASE_MAJOR_VERSION) || \
75              (LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION_C != DMA_IP_AR_RELEASE_MINOR_VERSION) \
76             )
77             #error "AutoSar Version Numbers of Linflexd_Uart_Ip.c and Dma_Ip.h are different"
78         #endif
79     #endif
80 
81     /* Checks against RegLockMacros.h */
82     #if (STD_ON == LINFLEXD_UART_IP_SET_USER_ACCESS_ALLOWED_AVAILABLE)
83         #if ((LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MAJOR_VERSION) || \
84              (LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MINOR_VERSION) \
85             )
86             #error "AutoSar Version Numbers of Linflexd_Uart_Ip.c and RegLockMacros.h are different"
87         #endif
88     #endif
89 
90     /* Checks against Devassert.h */
91     #ifdef LINFLEXD_UART_IP_DEV_ERROR_DETECT
92         #if (LINFLEXD_UART_IP_DEV_ERROR_DETECT == STD_ON)
93             #if ((LINFLEXD_UART_IP_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
94                  (LINFLEXD_UART_IP_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION) \
95                 )
96             #error "AutoSar Version Numbers of Linflexd_Uart_Ip.c and Devassert.h are different"
97         #endif
98         #endif /* (STD_ON == LINFLEXD_UART_IP_DEV_ERROR_DETECT) */
99     #endif /* idfef LINFLEXD_UART_IP_DEV_ERROR_DETECT */
100 #endif
101 /*==================================================================================================
102 *                           LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
103 ==================================================================================================*/
104 
105 /*==================================================================================================
106 *                                          LOCAL MACROS
107 ==================================================================================================*/
108 
109 #ifdef LINFLEXD_UART_IP_DEV_ERROR_DETECT
110     #if (LINFLEXD_UART_IP_DEV_ERROR_DETECT == STD_ON)
111         #define LINFLEXD_UART_IP_DEV_ASSERT(x)      DevAssert(x)
112     #else
113         #define LINFLEXD_UART_IP_DEV_ASSERT(x)      (void)(x)
114     #endif
115 #endif
116 
117 /* @brief Address of the least significant byte or word in a 32-bit register (depends on endianness) */
118 #define LINFLEXD_UART_IP_LSBW_ADDR(reg)  ((uint32)(&(reg)))
119 
120 /*==================================================================================================
121 *                                         LOCAL CONSTANTS
122 ==================================================================================================*/
123 
124 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
125     #define LINFLEXD_UART_IP_DMA_CONFIG_LIST_DIMENSION             (10U)
126     #define LINFLEXD_UART_DMA_LEAST_CONFIG_LIST_DIMENSION       (2U)
127 #endif
128 
129 /*==================================================================================================
130 *                                         LOCAL VARIABLES
131 ==================================================================================================*/
132 #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
133 #include "Uart_MemMap.h"
134 
135 /** @brief Array of UART driver runtime state structures */
136 VAR_SEC_NOCACHE(inflexd_Uart_Ip_apStateStructure) Linflexd_Uart_Ip_StateStructureType Linflexd_Uart_Ip_apStateStructure[LINFLEXD_UART_IP_NUMBER_OF_INSTANCES];
137 
138 #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
139 #include "Uart_MemMap.h"
140 
141 #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
142 #include "Uart_MemMap.h"
143 
144 /** @brief User config structure. */
145 VAR_SEC_NOCACHE(Linflexd_Uart_Ip_apUserConfig) static const Linflexd_Uart_Ip_UserConfigType* Linflexd_Uart_Ip_apUserConfig[LINFLEXD_IP_INSTANCE_COUNT];
146 
147 /** @brief Array of pointers to UART driver runtime state structures */
148 VAR_SEC_NOCACHE(Linflexd_Uart_Ip_apStateStructuresArray) static Linflexd_Uart_Ip_StateStructureType* Linflexd_Uart_Ip_apStateStructuresArray[LINFLEXD_IP_INSTANCE_COUNT];
149 
150 #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
151 #include "Uart_MemMap.h"
152 
153 
154 #define UART_START_SEC_CONST_UNSPECIFIED
155 #include "Uart_MemMap.h"
156 
157 /** @brief Table of base addresses for LINFLEXD instances. */
158 static LINFLEXD_Type* const Linflexd_Uart_Ip_apBases[LINFLEXD_IP_INSTANCE_COUNT] = LINFLEXD_IP_BASE_PTRS;
159 
160 #define UART_STOP_SEC_CONST_UNSPECIFIED
161 #include "Uart_MemMap.h"
162 
163 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
164 #define UART_START_SEC_CONST_BOOLEAN
165 #include "Uart_MemMap.h"
166 
167 /** @brief Table storing DMA capabilities for LINFLEXD instances. */
168 static const boolean Linflexd_Uart_Ip_InstHasDma[LINFLEXD_IP_INSTANCE_COUNT] = LINFLEXD_UART_IP_INST_HAS_DMA;
169 
170 #define UART_STOP_SEC_CONST_BOOLEAN
171 #include "Uart_MemMap.h"
172 #endif
173 
174 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
175 #define UART_START_SEC_CONST_BOOLEAN
176 #include "Uart_MemMap.h"
177 
178 /** @brief Table storing timeout interrupt capabilities for LINFLEXD instances. */
179 static const boolean Linflexd_Uart_Ip_InstHasTimeoutInterruptEnabled[LINFLEXD_IP_INSTANCE_COUNT] = LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT_PER_INSTANCE;
180 
181 #define UART_STOP_SEC_CONST_BOOLEAN
182 #include "Uart_MemMap.h"
183 #endif
184 
185 #if (LINFLEXD_UART_IP_ENABLE_INTERNAL_LOOPBACK == STD_ON)
186 #define UART_START_SEC_CONST_BOOLEAN
187 #include "Uart_MemMap.h"
188 
189 /** @brief Table storing internal loopback capabilities for LINFLEXD instances. */
190 static const boolean Linflexd_Uart_Ip_InstHasLoopbackEnabled[LINFLEXD_IP_INSTANCE_COUNT] = LINFLEXD_UART_IP_ENABLE_INTERNAL_LOOPBACK_PER_INSTANCE;
191 
192 #define UART_STOP_SEC_CONST_BOOLEAN
193 #include "Uart_MemMap.h"
194 #endif
195 /*==================================================================================================
196 *                                        GLOBAL CONSTANTS
197 ==================================================================================================*/
198 
199 /*==================================================================================================
200 *                                        GLOBAL VARIABLES
201 ==================================================================================================*/
202 
203 /*==================================================================================================
204 *                                    LOCAL FUNCTION PROTOTYPES
205 ==================================================================================================*/
206 
207 /*==================================================================================================
208 *                                         LOCAL FUNCTIONS
209 ==================================================================================================*/
210 #define UART_START_SEC_CODE
211 #include "Uart_MemMap.h"
212 
213 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartSendUsingInterrupts(const uint8 Instance, const uint8 * TxBuff, const uint32 TxSize);
214 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartReceiveUsingInterrupts(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize);
215 static void Linflexd_Uart_Ip_CompleteSendUsingInterrupts(const uint8 Instance);
216 static void Linflexd_Uart_Ip_CompleteReceiveUsingInterrupts(const uint8 Instance);
217 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
218 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartSendUsingDma(const uint8 Instance, const uint8 * TxBuff, const uint32 TxSize);
219 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartReceiveUsingDma(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize);
220 static void Linflexd_Uart_Ip_FlushRxFifo(const LINFLEXD_Type *Base,const Linflexd_Uart_Ip_WordLengthType WordLength);
221 #endif
222 static void Linflexd_Uart_Ip_PutData(const uint8 Instance);
223 static void Linflexd_Uart_Ip_GetData(const uint8 Instance);
224 static void Linflexd_Uart_Ip_SetWordLength(const uint8 Instance);
225 static void Linflexd_Uart_Ip_SetUp_Init(const uint8 Instance);
226 static void Linflexd_Uart_Ip_SetUp_Receiver(const uint8 Instance);
227 static void Linflexd_Uart_Ip_UpdateReceiver(const uint8 Instance, uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks);
228 static void Linflexd_Uart_Ip_GetRemainingBytes(const uint8 Instance, uint32 * BytesRemaining, Linflexd_Uart_Ip_DataDirectionType Direction);
229 #if (STD_ON == LINFLEXD_UART_IP_SET_USER_ACCESS_ALLOWED_AVAILABLE)
230 void Linflexd_Uart_Ip_SetUserAccess(const uint8 Instance);
231 static void Linflexd_Uart_Ip_SetUserAccessAllowed(const uint8 Instance);
232 #endif /* LINFLEXD_UART_IP_SET_USER_ACCESS_ALLOWED_AVAILABLE */
233 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
234 static void Linflexd_Uart_Ip_SetUp_SetupTimeoutParameters(const uint8 Instance);
235 static uint16 Linflexd_Uart_Ip_GetActualWordLengthValue(const uint8 Instance);
236 #endif
237 static void Linflexd_Uart_Ip_SetTransmitterState(LINFLEXD_Type *Base, boolean Enable);
238 static void Linflexd_Uart_Ip_SetReceiverState(LINFLEXD_Type *Base, boolean Enable);
239 static void Linflexd_Uart_Ip_SetInterruptMode(LINFLEXD_Type * Base, Linflexd_Uart_Ip_InterruptType IntSrc, boolean Enable);
240 static void Linflexd_Uart_Ip_SetUp_Baudrate(const uint8 Instance);
241 static void Linflexd_Uart_Ip_SetTxRxMode(const uint8 Instance);
242 static void Linflexd_Uart_Ip_SetUp_Parity(const uint8 Instance);
243 static void Linflexd_Uart_Ip_SetUp_SetTxRxStopBitsCount(const uint8 Instance);
244 static void Linflexd_Uart_Ip_SyncSendData(const uint8 Instance, const uint32 Timeout);
245 static boolean Linflexd_Uart_Ip_SetUp_EnterInitMode(LINFLEXD_Type *Base);
246 static void Linflexd_Uart_Ip_CompleteAsyncReceiveData(const uint8 Instance);
247 static void Linflexd_Uart_Ip_UpdateErrorIRQHandler(const uint8 Instance);
248 static void Linflexd_Uart_Ip_Callback(const uint8 Instance, const Linflexd_Uart_Ip_EventType Event);
249 /*==================================================================================================
250 *                                        GLOBAL FUNCTIONS
251 ==================================================================================================*/
252 
253 /* implements     Linflexd_Uart_Ip_SetBaudrate_Activity */
Linflexd_Uart_Ip_SetBaudrate(const uint8 Instance,const Linflexd_Uart_Ip_BaudrateType DesiredBaudRate,const uint32 ClockFrequency)254 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_SetBaudrate(const uint8 Instance,
255                                                          const Linflexd_Uart_Ip_BaudrateType DesiredBaudRate,
256                                                          const uint32 ClockFrequency
257                                                         )
258 {
259 
260     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
261 
262     LINFLEXD_Type * Base;
263     uint32 Surplus;
264     uint32 Division;
265     uint8 Numerator;
266     uint32 Mantissa;
267     uint32 FractionDenominator;
268     uint32 Baudrate;
269     boolean ResetIdle = FALSE;
270     boolean IsReturn = FALSE;
271     Linflexd_Uart_Ip_StateStructureType * UartState;
272     Linflexd_Uart_Ip_StatusType Status = LINFLEXD_UART_IP_STATUS_ERROR;
273     uint8 FractionNumerator;
274 
275     Base = Linflexd_Uart_Ip_apBases[Instance];
276     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
277 
278     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
279 
280     if ((TRUE == UartState->IsTxBusy) || (TRUE == UartState->IsRxBusy))
281     {
282         Status = LINFLEXD_UART_IP_STATUS_BUSY;
283     }
284     else
285     {
286         /* Reduced Oversampling is disabled to use OSR as default */
287         Base->UARTCR &= ~LINFLEXD_UARTCR_ROSE(1);
288         /* Compute the values for baud rate divider Mantissa and Fraction */
289         Division = (uint32)DesiredBaudRate * (uint32)DEFAULT_OSR;
290         Mantissa = (uint32)(ClockFrequency / Division);
291         /* Surplus equal to Fraction * Division equal to (ClockFrequency - Mantissa * Division) */
292         Surplus = ClockFrequency - (Mantissa * Division);
293         FractionDenominator = ((uint32)1U << (uint32)LINFLEXD_BAUDRATE_FRACTION_WIDTH);
294         Numerator = (uint8)(((uint32)(Surplus * FractionDenominator) + (uint32)(Division / (uint32)2U)) / Division);
295         FractionNumerator = Numerator;
296 
297         if (FractionNumerator == FractionDenominator)
298         {
299             FractionNumerator = 0;
300             Mantissa++;
301         }
302         /* The current baudrate value is equal to ClockFrequency/((Mantissa + FractionNumerator/FractionDenominator) * DEFAULT_OSR)*/
303         Baudrate = (uint32)((ClockFrequency * FractionDenominator)/(((Mantissa * FractionDenominator) + FractionNumerator) * DEFAULT_OSR));
304 
305         if (Linflexd_Uart_Ip_GetLinState(Base) != LINFLEXD_STATE_INIT_MODE)
306         {
307             /* Init mode error */
308             if (Linflexd_Uart_Ip_SetUp_EnterInitMode(Base) != TRUE)
309             {
310                 Status = LINFLEXD_UART_IP_STATUS_ERROR;
311                 IsReturn = TRUE;
312             }
313             else
314             {
315                 ResetIdle = TRUE;
316             }
317         }
318         if (!IsReturn)
319         {
320             /* Write the computed values to registers */
321             Linflexd_Uart_Ip_SetIntegerBaudRate(Base, Mantissa);
322             Linflexd_Uart_Ip_SetFractionalBaudRate(Base, FractionNumerator);
323 
324             if (TRUE == ResetIdle)
325             {
326                 /* Enter normal mode */
327                 Linflexd_Uart_Ip_EnterNormalMode(Base);
328             }
329             /* Save current baudrate value */
330             UartState->Baudrate = Baudrate;
331             Status = LINFLEXD_UART_IP_STATUS_SUCCESS;
332         }
333     }
334     return Status;
335 }
336 
337 /*FUNCTION**********************************************************************
338  *
339  * Function Name : Linflexd_Uart_Ip_GetBaudrate
340  * Description   : This function retrieves the baud rate for UART communication.
341  *
342 *END**************************************************************************/
343 /* implements     Linflexd_Uart_Ip_GetBaudrate_Activity*/
Linflexd_Uart_Ip_GetBaudrate(const uint8 Instance,uint32 * ConfiguredBaudRate)344 void Linflexd_Uart_Ip_GetBaudrate(const uint8 Instance, uint32 * ConfiguredBaudRate)
345 {
346     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
347     LINFLEXD_UART_IP_DEV_ASSERT(ConfiguredBaudRate != NULL_PTR);
348 
349     const Linflexd_Uart_Ip_StateStructureType *UartStatePtr;
350 
351     UartStatePtr = Linflexd_Uart_Ip_apStateStructuresArray[Instance];
352 
353     LINFLEXD_UART_IP_DEV_ASSERT(UartStatePtr != NULL_PTR);
354 
355     *ConfiguredBaudRate = UartStatePtr->Baudrate;
356 }
357 
358 /*FUNCTION**********************************************************************
359  *
360  * Function Name : Linflexd_Uart_Ip_Init
361  * Description   : This function initializes a LINFLEXD instance for UART
362  * operation.
363  * This function will initialize the run-time state structure to keep track of
364  * the on-going transfers, initialize the module to user defined settings and
365  * default settings, enable the module-level interrupt to the partition, and enable
366  * the UART module transmitter and receiver.
367  *
368  *END**************************************************************************/
369 /* implements     Linflexd_Uart_Ip_Init_Activity*/
Linflexd_Uart_Ip_Init(const uint8 Instance,const Linflexd_Uart_Ip_UserConfigType * UserConfig)370 void Linflexd_Uart_Ip_Init(const uint8 Instance, const Linflexd_Uart_Ip_UserConfigType * UserConfig)
371 {
372     uint32 Index;
373     uint8 *ClearStructPtr;
374 
375     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
376     LINFLEXD_UART_IP_DEV_ASSERT(NULL_PTR == Linflexd_Uart_Ip_apStateStructuresArray[Instance]);
377     LINFLEXD_UART_IP_DEV_ASSERT(UserConfig != NULL_PTR);
378 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
379     /* Check if an instance with no DMA support is configured in DMA mode */
380     LINFLEXD_UART_IP_DEV_ASSERT((UserConfig->TransferType != LINFLEXD_UART_IP_USING_DMA) || Linflexd_Uart_Ip_InstHasDma[Instance]);
381 #endif
382     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
383     Linflexd_Uart_Ip_apStateStructuresArray[Instance] = UserConfig->StateStruct;
384 
385     Linflexd_Uart_Ip_StateStructureType *UartStatePtr = Linflexd_Uart_Ip_apStateStructuresArray[Instance];
386     Linflexd_Uart_Ip_apUserConfig[Instance] = UserConfig;
387     ClearStructPtr = (uint8 *)UartStatePtr;
388 
389     /* Clear the state struct for this Instance. */
390     for (Index = 0; Index < sizeof(Linflexd_Uart_Ip_StateStructureType); Index++)
391     {
392         ClearStructPtr[Index] = 0U;
393     }
394 #if (STD_ON == LINFLEXD_UART_IP_SET_USER_ACCESS_ALLOWED_AVAILABLE)
395     Linflexd_Uart_Ip_SetUserAccessAllowed(Instance);
396 #endif
397 
398     UartStatePtr->IsDriverInitialized = FALSE;
399     /* Request init mode and wait until the mode entry is complete */
400     if (TRUE == Linflexd_Uart_Ip_SetUp_EnterInitMode(Base))
401     {
402         UartStatePtr->IsDriverInitialized = TRUE;
403     }
404 
405     /* Set up UART mode, baud rate, word length, parity, stop bits count and enable FIFO. */
406     Linflexd_Uart_Ip_SetUp_Init(Instance);
407 
408     /* Enter normal mode */
409     Linflexd_Uart_Ip_EnterNormalMode(Base);
410 
411     Linflexd_Uart_Ip_SetTransmitterState(Base, FALSE);
412     Linflexd_Uart_Ip_SetReceiverState(Base, FALSE);
413 
414     /* initialize last driver operation status */
415     UartStatePtr->TransmitStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
416     UartStatePtr->ReceiveStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
417 }
418 
419 
420 /*FUNCTION**********************************************************************
421  *
422  * Function Name : Linflexd_Uart_Ip_Deinit
423  * Description   : This function shuts down the UART by disabling interrupts and
424  *                 transmitter/receiver.
425  *
426 *END**************************************************************************/
427 /* implements     Linflexd_Uart_Ip_Deinit_Activity */
Linflexd_Uart_Ip_Deinit(const uint8 Instance)428 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_Deinit(const uint8 Instance)
429 {
430     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
431 
432     LINFLEXD_Type * Base;
433     Linflexd_Uart_Ip_StatusType RetVal;
434     const Linflexd_Uart_Ip_StateStructureType * UartState;
435     uint32 StartTime;
436     uint32 TimeoutTicks;
437     uint32 ElapsedTicks = 0;
438 
439     Base = Linflexd_Uart_Ip_apBases[Instance];
440     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
441 
442     Linflexd_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_VALUE_US, LINFLEXD_UART_IP_TIMEOUT_TYPE);
443     /* Wait until the data is completely shifted out of shift register */
444     while ((UartState->IsTxBusy || UartState->IsRxBusy) && \
445            !Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE) \
446           )
447     {}
448     /* Disable Tx data register empty and transmission complete interrupt */
449     if (Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
450     {
451         RetVal = LINFLEXD_UART_IP_STATUS_ERROR;
452     }
453     else
454     {
455         /* Calling Linflexd_Uart_Ip_Deinit shall disable the transmitter and reciever. */
456         /* Disable transmission complete interrupt */
457         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_TRANSMITTED_INT, FALSE);
458         /* Disable receive data full interrupt. */
459         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_RECEPTION_COMPLETE_INT, FALSE);
460 
461         /* Calling Linflexd_Uart_Ip_Deinit shall disable error interrupts (rx overrun and framing error).*/
462         /* Disable error interrupts */
463         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_FRAME_ERROR_INT, FALSE);
464         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_BUFFER_OVERRUN_INT, FALSE);
465 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
466     if (Linflexd_Uart_Ip_InstHasTimeoutInterruptEnabled[Instance])
467     {
468         /* Disable timeout interrupt */
469         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_TIMEOUT_INT, FALSE);
470     }
471 #endif
472 
473         /* Clear the saved pointer to the state structure */
474         Linflexd_Uart_Ip_apStateStructuresArray[Instance] = NULL_PTR;
475 
476         RetVal = LINFLEXD_UART_IP_STATUS_SUCCESS;
477     }
478     return RetVal;
479 }
480 
481 /*FUNCTION**********************************************************************
482  *
483  * Function Name : Linflexd_Uart_Ip_SetTxBuffer
484  * Description   : Sets the driver internal reference to the tx buffer.
485  *                 Can be called from the tx callback to provide a different
486  *                 buffer for continuous transmission.
487  *
488 *END**************************************************************************/
489 /* implements     Linflexd_Uart_Ip_SetTxBuffer_Activity */
Linflexd_Uart_Ip_SetTxBuffer(const uint8 Instance,const uint8 * TxBuff,const uint32 TxSize)490 void Linflexd_Uart_Ip_SetTxBuffer(const uint8 Instance, const uint8 * TxBuff, const uint32 TxSize)
491 {
492     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
493     LINFLEXD_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
494     LINFLEXD_UART_IP_DEV_ASSERT(TxSize > 0U);
495 
496     Linflexd_Uart_Ip_StateStructureType * UartState;
497 
498     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
499 
500     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
501 
502     UartState->TxBuff = TxBuff;
503     UartState->TxSize = TxSize;
504 
505 }
506 
507 /*FUNCTION**********************************************************************
508  *
509  * Function Name : Linflexd_Uart_Ip_SetRxBuffer
510  * Description   : Sets the driver internal reference to the rx buffer.
511  *                 Can be called from the rx callback to provide a different
512  *                 buffer for continuous reception.
513  *
514 *END**************************************************************************/
515 /* implements     Linflexd_Uart_Ip_SetRxBuffer_Activity */
Linflexd_Uart_Ip_SetRxBuffer(const uint8 Instance,uint8 * RxBuff,const uint32 RxSize)516 void Linflexd_Uart_Ip_SetRxBuffer(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize)
517 {
518     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
519     LINFLEXD_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
520     LINFLEXD_UART_IP_DEV_ASSERT(RxSize > 0U);
521 
522     Linflexd_Uart_Ip_StateStructureType * UartState;
523 
524     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
525 
526     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
527 
528     UartState->RxBuff = RxBuff;
529     UartState->RxSize = RxSize;
530 
531 }
532 
533 /*FUNCTION**********************************************************************
534  *
535  * Function Name : Linflexd_Uart_Ip_PutData
536  * Description   : Write data to the buffer register, according to configured
537  * word length.
538  * This is not a public API as it is called from other driver functions.
539  *
540  *END**************************************************************************/
Linflexd_Uart_Ip_PutData(const uint8 Instance)541 static void Linflexd_Uart_Ip_PutData(const uint8 Instance)
542 {
543     Linflexd_Uart_Ip_StateStructureType * UartState;
544     LINFLEXD_Type * Base;
545     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
546     Base = Linflexd_Uart_Ip_apBases[Instance];
547 
548     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
549     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
550 
551     if ((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength))
552     {
553         uint8 Data = *(UartState->TxBuff);
554         /* Update the state structure */
555         ++UartState->TxBuff;
556         --UartState->TxSize;
557         /* Transmit the Data */
558         Linflexd_Uart_Ip_SetTxDataBuffer1Byte(Base, Data);
559     }
560     else
561     {
562         /* Transmit the Data and update state structure */
563         if (1U == UartState->TxSize)
564         {
565             uint16 Data = (uint16)(*UartState->TxBuff);
566             ++UartState->TxBuff;
567             --UartState->TxSize;
568             Linflexd_Uart_Ip_SetTxDataBuffer2Bytes(Base, Data);
569         }
570         else
571         {
572             uint16 Data = *((const uint16*)UartState->TxBuff);
573             /* Move the pointer twice */
574             ++UartState->TxBuff;
575             ++UartState->TxBuff;
576             UartState->TxSize -= 2U;
577             Linflexd_Uart_Ip_SetTxDataBuffer2Bytes(Base, Data);
578         }
579     }
580 }
581 
582 /*FUNCTION**********************************************************************
583  *
584  * Function Name : Linflexd_Uart_Ip_CompleteSendUsingInterrupts
585  * Description   : Finish up a transmit by completing the process of sending
586  * Data and disabling the interrupt.
587  * This is not a public API as it is called from other driver functions.
588  *
589  *END**************************************************************************/
Linflexd_Uart_Ip_CompleteSendUsingInterrupts(const uint8 Instance)590 static void Linflexd_Uart_Ip_CompleteSendUsingInterrupts(const uint8 Instance)
591 {
592     Linflexd_Uart_Ip_StateStructureType * UartState;
593     LINFLEXD_Type * Base;
594     uint32 StartTime;
595     uint32 TimeoutTicks = 0;
596     uint32 ElapsedTicks = 0;
597 
598     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
599     Base = Linflexd_Uart_Ip_apBases[Instance];
600 
601     /* Disable transmission complete interrupt */
602     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_TRANSMITTED_INT, FALSE);
603     /* In Abort case, the transmission need to stop instantly */
604     /* In case the Abort function is called when the last byte is transmited
605        checking the Data Transmission Complete flag in the while function will result in Timeout Error
606        so the TxSize needs to be greater than zero. */
607     if ((LINFLEXD_UART_IP_STATUS_ABORTED == UartState->TransmitStatus) && (UartState->TxSize > 0U))
608     {
609         Linflexd_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_VALUE_US, LINFLEXD_UART_IP_TIMEOUT_TYPE);
610         /* Wait until the data is completely shifted out of shift register */
611         while (!Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG) && \
612                !Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE) \
613               )
614         {}
615         if (Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
616         {
617             /* In case timeout occur */
618             UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_TIMEOUT;
619         }
620         /* Clear data transmission completed flag */
621         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
622     }
623     /* Disable the transmitter */
624     Linflexd_Uart_Ip_SetTransmitterState(Base, FALSE);
625 
626     /* Update the information of the module driver state */
627     UartState->IsTxBusy = FALSE;
628 
629     /* If the current transmission hasn't been aborted, update the status */
630     if (LINFLEXD_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
631     {
632         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
633     }
634 }
635 
636 /*FUNCTION**********************************************************************
637  *
638  * Function Name : Linflexd_Uart_Ip_CompleteReceiveUsingInterrupts
639  * Description   : Finish up a receive by completing the process of receiving data
640  * and disabling the interrupt.
641  * This is not a public API as it is called from other driver functions.
642  *
643  *END**************************************************************************/
Linflexd_Uart_Ip_CompleteReceiveUsingInterrupts(const uint8 Instance)644 static void Linflexd_Uart_Ip_CompleteReceiveUsingInterrupts(const uint8 Instance)
645 {
646     Linflexd_Uart_Ip_StateStructureType * UartState;
647     LINFLEXD_Type * Base;
648     uint32 StartTime;
649     uint32 TimeoutTicks;
650     uint32 ElapsedTicks = 0;
651 
652     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
653     Base = Linflexd_Uart_Ip_apBases[Instance];
654 
655     /* Disable receive data full interrupt. */
656     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_RECEPTION_COMPLETE_INT, FALSE);
657 
658     /* Disable error interrupts */
659     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_FRAME_ERROR_INT, FALSE);
660     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_BUFFER_OVERRUN_INT, FALSE);
661 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
662     if (Linflexd_Uart_Ip_InstHasTimeoutInterruptEnabled[Instance])
663     {
664         /* Disable timeout interrupt */
665         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_TIMEOUT_INT, FALSE);
666     }
667 #endif
668     /* In Abort case, the transmission need to stop instantly */
669     /* In case the Abort function is called when the last byte is received
670        checking the Data Reception Complete flag in the while function will result in Timeout Error
671        so the RxSize needs to be greater than zero. */
672     if ((LINFLEXD_UART_IP_STATUS_ABORTED == UartState->ReceiveStatus) && (UartState->RxSize > 0U))
673     {
674         Linflexd_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_VALUE_US, LINFLEXD_UART_IP_TIMEOUT_TYPE);
675         /* Wait until the data is completely received */
676         while (!Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG) && \
677                !Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
678         {}
679 
680         if (Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
681         {
682           /* In case timeout occur */
683             UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_TIMEOUT;
684         }
685         /* Read dummy to get all data remaning */
686         Linflexd_Uart_Ip_GetData(Instance);
687         /* Clear data reception completed flag  */
688         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG);
689     }
690 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
691     if (LINFLEXD_UART_IP_STATUS_RX_IDLE_STATE != UartState->ReceiveStatus)
692 #endif
693     {
694         /* Disable the receiver */
695         Linflexd_Uart_Ip_SetReceiverState(Base, FALSE);
696     }
697 
698     /* Update the information of the module driver state */
699     UartState->IsRxBusy = FALSE;
700 
701     /* If the current reception hasn't been aborted and no error occurred, update the status */
702     if (LINFLEXD_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
703     {
704         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
705     }
706 }
707 
708 /*FUNCTION**********************************************************************
709  *
710  * Function Name : Linflexd_Uart_Ip_SyncSend
711  * Description   : Send out multiple bytes of data using polling method.
712  *
713  *END**************************************************************************/
714  /* @implements    Linflexd_Uart_Ip_SyncSend_Activity */
Linflexd_Uart_Ip_SyncSend(const uint8 Instance,const uint8 * TxBuff,const uint32 TxSize,const uint32 Timeout)715 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_SyncSend(const uint8 Instance, const uint8 *TxBuff, const uint32 TxSize, const uint32 Timeout)
716 {
717 
718     /* Check the validity of the parameters */
719     LINFLEXD_UART_IP_DEV_ASSERT(TxSize > 0U);
720     LINFLEXD_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
721     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
722 
723     Linflexd_Uart_Ip_StateStructureType * UartState;
724     LINFLEXD_Type * Base;
725     Linflexd_Uart_Ip_StatusType Status = LINFLEXD_UART_IP_STATUS_BUSY;
726     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
727     Base = Linflexd_Uart_Ip_apBases[Instance];
728 
729     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
730 
731     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_03();
732     /* Check driver is not busy transmitting data from a previous asynchronous call */
733     if (UartState->IsTxBusy)
734     {
735         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_03();
736         Status = LINFLEXD_UART_IP_STATUS_BUSY;
737     }
738     else
739     {
740          /* Initialize the module driver state structure */
741         UartState->IsTxBusy = TRUE;
742         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_03();
743         UartState->TxBuff = TxBuff;
744         UartState->TxSize = TxSize;
745 
746         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_BUSY;
747 
748         /* The interrupts shall be disabled when the Linflexd_Uart_Ip_SyncReceive and Linflexd_Uart_Ip_SyncSend are called. */
749         /* Disble transmission complete interrupt */
750         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_TRANSMITTED_INT, FALSE);
751         /* Disable receive data full interrupt. */
752         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_RECEPTION_COMPLETE_INT, FALSE);
753 
754         /* Disable error interrupts */
755         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_FRAME_ERROR_INT, FALSE);
756         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_BUFFER_OVERRUN_INT, FALSE);
757 
758         /* Enable the transmitter */
759         Linflexd_Uart_Ip_SetTransmitterState(Base, TRUE);
760 
761         /* Process for sync send data*/
762         Linflexd_Uart_Ip_SyncSendData(Instance, Timeout);
763 
764         /* Disable the transmitter */
765         Linflexd_Uart_Ip_SetTransmitterState(Base, FALSE);
766 
767         UartState->IsTxBusy = FALSE;
768         Status = UartState->TransmitStatus;
769     }
770     return Status;
771 }
772 
773 
774 /*FUNCTION**********************************************************************
775  *
776  * Function Name : Linflexd_Uart_Ip_GetData
777  * Description   : Read data from the buffer register, according to configured
778  * word length.
779  * This is not a public API as it is called from other driver functions.
780  *
781  *END**************************************************************************/
Linflexd_Uart_Ip_GetData(const uint8 Instance)782 static void Linflexd_Uart_Ip_GetData(const uint8 Instance)
783 {
784     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
785     Linflexd_Uart_Ip_StateStructureType * UartState;
786     const LINFLEXD_Type * Base;
787 
788     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
789     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
790     Base = Linflexd_Uart_Ip_apBases[Instance];
791 
792 
793     if ((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength))
794     {
795         /* Get the data */
796         *(UartState->RxBuff) = Linflexd_Uart_Ip_GetRxDataBuffer1Byte(Base);
797         /* Update the state structure */
798         ++UartState->RxBuff;
799         --UartState->RxSize;
800     }
801     else
802     {
803         /* Get the data and update state structure */
804         if (1U == UartState->RxSize)
805         {
806             *(UartState->RxBuff) = (uint8)(Linflexd_Uart_Ip_GetRxDataBuffer2Bytes(Base));
807             ++UartState->RxBuff;
808             --UartState->RxSize;
809         }
810         else
811         {
812             *((uint16*)(UartState->RxBuff)) = Linflexd_Uart_Ip_GetRxDataBuffer2Bytes(Base);
813             /* Move the pointer twice */
814             ++UartState->RxBuff;
815             ++UartState->RxBuff;
816             UartState->RxSize -= 2U;
817         }
818     }
819 }
820 
821 /*FUNCTION**********************************************************************
822  *
823  * Function Name : Linflexd_Uart_Ip_SyncReceive
824  * Description   : Retrieves data from the LINFLEXD module in UART mode with
825  * polling method.
826  *
827 *END**************************************************************************/
828 /* implements     Linflexd_Uart_Ip_SyncReceive_Activity*/
Linflexd_Uart_Ip_SyncReceive(const uint8 Instance,uint8 * RxBuff,const uint32 RxSize,const uint32 Timeout)829 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_SyncReceive(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize, const uint32 Timeout)
830 {
831     /* Check the validity of the parameters */
832     LINFLEXD_UART_IP_DEV_ASSERT(RxSize > 0U);
833     LINFLEXD_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
834     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
835 
836     Linflexd_Uart_Ip_StateStructureType * UartState;
837     LINFLEXD_Type * Base;
838     uint32 StartTime;
839     uint32 TimeoutTicks;
840     uint32 ElapsedTicks = 0;
841     Linflexd_Uart_Ip_StatusType Status = LINFLEXD_UART_IP_STATUS_BUSY;
842 
843     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
844     Base = Linflexd_Uart_Ip_apBases[Instance];
845 
846     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
847 
848     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_06();
849     /* Check driver is not busy transmitting data from a previous asynchronous call */
850     if (UartState->IsRxBusy)
851     {
852         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_06();
853         Status = LINFLEXD_UART_IP_STATUS_BUSY;
854     }
855     else
856     {
857          /* Initialize the module driver state structure */
858         UartState->IsRxBusy = TRUE;
859         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_06();
860         UartState->RxBuff = RxBuff;
861         UartState->RxSize = RxSize;
862         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_BUSY;
863 
864         /*The interrupts shall be disabled when the Linflexd_Uart_Ip_SyncReceive and Linflexd_Uart_Ip_SyncSend are called.*/
865         Linflexd_Uart_Ip_SetUp_Receiver(Instance);
866 
867         Linflexd_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, Timeout, LINFLEXD_UART_IP_TIMEOUT_TYPE);
868 
869         /* Update status and clear the flag according to the error occurred */
870         Linflexd_Uart_Ip_UpdateReceiver(Instance, &StartTime, &ElapsedTicks, TimeoutTicks);
871 
872         if (LINFLEXD_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
873         {
874             UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
875         }
876 
877         /* Disable the receiver */
878         Linflexd_Uart_Ip_SetReceiverState(Base, FALSE);
879         UartState->IsRxBusy = FALSE;
880         Status = UartState->ReceiveStatus;
881     }
882     return Status;
883 }
884 
885 
886 /*FUNCTION**********************************************************************
887  *
888  * Function Name : Linflexd_Uart_Ip_AbortReceivingData
889  * Description   : Terminates a non-blocking receive early.
890  *
891  *END**************************************************************************/
892 /* implements     Linflexd_Uart_Ip_AbortReceivingData_Activity*/
Linflexd_Uart_Ip_AbortReceivingData(const uint8 Instance)893 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AbortReceivingData(const uint8 Instance)
894 {
895     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
896 
897     Linflexd_Uart_Ip_StateStructureType * UartState;
898     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
899 
900     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
901     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
902     Linflexd_Uart_Ip_StatusType Status = LINFLEXD_UART_IP_STATUS_SUCCESS;
903 
904     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
905     LINFLEXD_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
906 
907     /* Check if a transfer is running. */
908     if (!UartState->IsRxBusy)
909     {
910         Status = LINFLEXD_UART_IP_STATUS_SUCCESS;
911     }
912     else
913     {
914         /* Update the rx status */
915         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_ABORTED;
916 
917         /* Stop the running transfer. */
918         if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
919         {
920             Linflexd_Uart_Ip_CompleteReceiveUsingInterrupts(Instance);
921         }
922 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
923         else
924         {
925             /* Release the DMA channel */
926             (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
927             Linflexd_Uart_Ip_CompleteReceiveUsingDma(Instance);
928         }
929 #endif
930     }
931     if (LINFLEXD_UART_IP_STATUS_TIMEOUT == UartState->ReceiveStatus)
932     {
933         Status = LINFLEXD_UART_IP_STATUS_ERROR;
934     }
935     return Status;
936 }
937 
938 /*FUNCTION**********************************************************************
939  *
940  * Function Name : Linflexd_Uart_Ip_AbortSendingData
941  * Description   : This function terminates an non-blocking UART transmission
942  * early. During a non-blocking UART transmission, the user has the option to
943  * terminate the transmission early if the transmission is still in progress.
944  *
945  *END**************************************************************************/
946 /* implements     Linflexd_Uart_Ip_AbortSendingData_Activity */
Linflexd_Uart_Ip_AbortSendingData(const uint8 Instance)947 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AbortSendingData(const uint8 Instance)
948 {
949     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
950 
951     Linflexd_Uart_Ip_StateStructureType * UartState;
952     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
953 
954     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
955     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
956     Linflexd_Uart_Ip_StatusType Status = LINFLEXD_UART_IP_STATUS_SUCCESS;
957 
958     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
959     LINFLEXD_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
960 
961     /* Check if a transfer is running. */
962     if (!UartState->IsTxBusy)
963     {
964         Status = LINFLEXD_UART_IP_STATUS_SUCCESS;
965     }
966     else
967     {
968         /* Update the tx status */
969         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_ABORTED;
970 
971         /* Stop the running transfer. */
972         if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
973         {
974             Linflexd_Uart_Ip_CompleteSendUsingInterrupts(Instance);
975         }
976 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
977         else
978         {
979             /* Release the DMA channel */
980             Linflexd_Uart_Ip_CompleteSendUsingDma(Instance);
981             (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
982         }
983 #endif
984     }
985     if (LINFLEXD_UART_IP_STATUS_TIMEOUT == UartState->TransmitStatus)
986     {
987         Status = LINFLEXD_UART_IP_STATUS_ERROR;
988     }
989     return Status;
990 }
991 
992 /*FUNCTION**********************************************************************
993  *
994  * Function Name : Linflexd_Uart_Ip_StartReceiveUsingInterrupts
995  * Description   : Initiate (start) a receive by beginning the process of
996  * receiving data and enabling the interrupt.
997  * This is not a public API as it is called from other driver functions.
998  *
999  *END**************************************************************************/
Linflexd_Uart_Ip_StartReceiveUsingInterrupts(const uint8 Instance,uint8 * RxBuff,const uint32 RxSize)1000 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartReceiveUsingInterrupts(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize)
1001 {
1002     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
1003     LINFLEXD_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
1004 
1005     Linflexd_Uart_Ip_StateStructureType * UartState;
1006     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
1007     LINFLEXD_Type * Base;
1008 
1009     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1010     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1011     Base = Linflexd_Uart_Ip_apBases[Instance];
1012     Linflexd_Uart_Ip_StatusType Status = LINFLEXD_UART_IP_STATUS_BUSY;
1013 
1014     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_07();
1015     /* Check it's not busy receiving data from a previous function call */
1016     if ((UartState->IsRxBusy) && (UartUserCfg->Callback != NULL_PTR))
1017     {
1018         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_07();
1019         Status = LINFLEXD_UART_IP_STATUS_BUSY;
1020     }
1021     else
1022     {
1023         /* Initialize the module driver state struct to indicate transfer in progress
1024          * and with the buffer and byte count data. */
1025         UartState->IsRxBusy = TRUE;
1026         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_07();
1027         UartState->RxBuff = RxBuff;
1028         LINFLEXD_UART_IP_DEV_ASSERT(RxSize > 0U);
1029         UartState->RxSize = RxSize;
1030         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_BUSY;
1031 
1032         /* Clear the flag */
1033         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG);
1034         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_MESSAGE_BUFFER_FULL_FLAG);
1035         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG);
1036         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG);
1037 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
1038         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_TIMEOUT_INTERRUPT_FLAG);
1039 #endif
1040 
1041         /* Enable the receiver */
1042         Linflexd_Uart_Ip_SetReceiverState(Base, TRUE);
1043 
1044         /* Enable receive data full interrupt */
1045         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_RECEPTION_COMPLETE_INT, TRUE);
1046         Status = LINFLEXD_UART_IP_STATUS_SUCCESS;
1047     }
1048     return Status;
1049 }
1050 
1051 /*FUNCTION**********************************************************************
1052  *
1053  * Function Name : Linflexd_Uart_Ip_GetReceiveStatus
1054  * Description   : This function returns whether the previous UART receive is
1055  * complete. When performing a non-blocking receive, the user can call this
1056  * function to ascertain the state of the current receive progress: in progress
1057  * or complete. In addition, if the receive is still in progress, the user can
1058  * obtain the number of words that have not yet been received.
1059  *
1060  *END**************************************************************************/
1061 /* implements     Linflexd_Uart_Ip_GetReceiveStatus_Activity */
Linflexd_Uart_Ip_GetReceiveStatus(const uint8 Instance,uint32 * BytesRemaining)1062 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_GetReceiveStatus(const uint8 Instance, uint32 * BytesRemaining)
1063 {
1064     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
1065 
1066     const Linflexd_Uart_Ip_StateStructureType * UartState;
1067     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
1068     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1069     Linflexd_Uart_Ip_StatusType localStatus;
1070 
1071     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1072 
1073     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
1074     LINFLEXD_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
1075 
1076     if (BytesRemaining != NULL_PTR)
1077     {
1078         SchM_Enter_Uart_UART_EXCLUSIVE_AREA_10();
1079         localStatus = UartState->ReceiveStatus;
1080         if (UartState->IsRxBusy)
1081         {
1082             SchM_Exit_Uart_UART_EXCLUSIVE_AREA_10();
1083             Linflexd_Uart_Ip_GetRemainingBytes(Instance, BytesRemaining, LINFLEXD_UART_IP_RECEIVE);
1084         }
1085         else
1086         {
1087 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
1088             if (LINFLEXD_UART_IP_STATUS_RX_IDLE_STATE == UartState->ReceiveStatus)
1089             {
1090                 SchM_Exit_Uart_UART_EXCLUSIVE_AREA_10();
1091                 Linflexd_Uart_Ip_GetRemainingBytes(Instance, BytesRemaining, LINFLEXD_UART_IP_RECEIVE);
1092             }
1093             else
1094 #endif
1095             {
1096                 *BytesRemaining = 0;
1097                  SchM_Exit_Uart_UART_EXCLUSIVE_AREA_10();
1098             }
1099         }
1100     }
1101     else
1102     {
1103         SchM_Enter_Uart_UART_EXCLUSIVE_AREA_10();
1104         localStatus = UartState->ReceiveStatus;
1105         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_10();
1106     }
1107 
1108     return localStatus;
1109 }
1110 
1111 /*FUNCTION**********************************************************************
1112  *
1113  * Function Name : Linflexd_Uart_Ip_GetTransmitStatus
1114  * Description   : This function returns whether the previous UART transmit has
1115  * finished. When performing non-blocking transmit, the user can call this
1116  * function to ascertain the state of the current transmission:
1117  * in progress (or busy) or complete (success). In addition, if the transmission
1118  * is still in progress, the user can obtain the number of words that have been
1119  * currently transferred.
1120  *
1121  *END**************************************************************************/
1122  /* implements     Linflexd_Uart_Ip_GetTransmitStatus_Activity */
Linflexd_Uart_Ip_GetTransmitStatus(const uint8 Instance,uint32 * BytesRemaining)1123 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_GetTransmitStatus(const uint8 Instance, uint32 * BytesRemaining)
1124 {
1125     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
1126 
1127     const Linflexd_Uart_Ip_StateStructureType * UartState;
1128     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
1129     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1130     Linflexd_Uart_Ip_StatusType localStatus;
1131 
1132     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1133 
1134     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
1135     LINFLEXD_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
1136 
1137     if (BytesRemaining != NULL_PTR)
1138     {
1139         SchM_Enter_Uart_UART_EXCLUSIVE_AREA_11();
1140         localStatus = UartState->TransmitStatus;
1141         /* Fill in the number of bytes yet to be transferred and update the return value if needed */
1142         if (UartState->IsTxBusy)
1143         {
1144             SchM_Exit_Uart_UART_EXCLUSIVE_AREA_11();
1145             Linflexd_Uart_Ip_GetRemainingBytes(Instance, BytesRemaining, LINFLEXD_UART_IP_SEND);
1146         }
1147         else
1148         {
1149             *BytesRemaining = 0;
1150             SchM_Exit_Uart_UART_EXCLUSIVE_AREA_11();
1151         }
1152     }
1153     else
1154     {
1155         SchM_Enter_Uart_UART_EXCLUSIVE_AREA_11();
1156         localStatus = UartState->TransmitStatus;
1157         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_11();
1158     }
1159     return localStatus;
1160 }
1161 
1162 /*FUNCTION**********************************************************************
1163  *
1164  * Function Name : Linflexd_Uart_Ip_AsyncReceive
1165  * Description   : Retrieves data from the LINFLEXD module in UART mode with
1166  * non-blocking method.
1167  *
1168  *END**************************************************************************/
1169  /* implements     Linflexd_Uart_Ip_AsyncReceive_Activity*/
Linflexd_Uart_Ip_AsyncReceive(const uint8 Instance,uint8 * RxBuff,const uint32 RxSize)1170 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AsyncReceive(const uint8 Instance, uint8 * RxBuff, const uint32 RxSize)
1171 {
1172     LINFLEXD_UART_IP_DEV_ASSERT(RxBuff != NULL_PTR);
1173     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
1174 
1175     LINFLEXD_Type * Base;
1176     Linflexd_Uart_Ip_StatusType RetVal = LINFLEXD_UART_IP_STATUS_ERROR;
1177     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
1178 
1179     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1180     Base = Linflexd_Uart_Ip_apBases[Instance];
1181 
1182     LINFLEXD_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
1183 
1184     /* Enable error interrupts */
1185     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_FRAME_ERROR_INT, TRUE);
1186     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_BUFFER_OVERRUN_INT, TRUE);
1187 
1188 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
1189     if (Linflexd_Uart_Ip_InstHasTimeoutInterruptEnabled[Instance])
1190     {
1191         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_TIMEOUT_INT, TRUE);
1192     }
1193 #endif
1194 
1195     if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
1196     {
1197         /* Start the transmission process using interrupts */
1198         RetVal = Linflexd_Uart_Ip_StartReceiveUsingInterrupts(Instance, RxBuff, RxSize);
1199     }
1200 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
1201     else
1202     {
1203         /* Start the transmission process using DMA */
1204         RetVal = Linflexd_Uart_Ip_StartReceiveUsingDma(Instance, RxBuff, RxSize);
1205     }
1206 #endif
1207     return RetVal;
1208 }
1209 
1210 
1211 /*FUNCTION**********************************************************************
1212  *
1213  * Function Name : Linflexd_Uart_Ip_StartSendUsingInterrupts
1214  * Description   : Initiate (start) a transmit by beginning the process of
1215  * sending data and enabling the interrupt.
1216  * This is not a public API as it is called from other driver functions.
1217  *
1218  *END**************************************************************************/
Linflexd_Uart_Ip_StartSendUsingInterrupts(const uint8 Instance,const uint8 * TxBuff,const uint32 TxSize)1219 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartSendUsingInterrupts(const uint8 Instance, const uint8 * TxBuff, const uint32 TxSize)
1220 {
1221     LINFLEXD_Type * Base;
1222     Linflexd_Uart_Ip_StateStructureType * UartState;
1223     Linflexd_Uart_Ip_StatusType Status = LINFLEXD_UART_IP_STATUS_BUSY;
1224 
1225     Base = Linflexd_Uart_Ip_apBases[Instance];
1226     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1227 
1228     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_04();
1229     /* Check it's not busy transmitting data from a previous function call */
1230     if (UartState->IsTxBusy)
1231     {
1232         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_04();
1233         Status = LINFLEXD_UART_IP_STATUS_BUSY;
1234     }
1235     else
1236     {
1237         /* Initialize the module driver state structure */
1238         UartState->IsTxBusy = TRUE;
1239         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_04();
1240         UartState->TxBuff = TxBuff;
1241 
1242         LINFLEXD_UART_IP_DEV_ASSERT(TxSize > 0U);
1243         UartState->TxSize = TxSize;
1244 
1245         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_BUSY;
1246 
1247         /* Enable the transmitter */
1248         Linflexd_Uart_Ip_SetTransmitterState(Base, TRUE);
1249 
1250         /* Clear the tx empty flag to make sure the transmission of the first byte
1251          * doesn't occur right after enabling the tx interrupt
1252          */
1253         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
1254 
1255         /* Enable transmission complete interrupt */
1256         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_TRANSMITTED_INT, TRUE);
1257 
1258         /* Transmit the first word */
1259         Linflexd_Uart_Ip_PutData(Instance);
1260         Status = LINFLEXD_UART_IP_STATUS_SUCCESS;
1261     }
1262     return Status;
1263 }
1264 
1265 /*FUNCTION**********************************************************************
1266  *
1267  * Function Name : Linflexd_Uart_Ip_AsyncSend
1268  * Description   : This function sends data using LINFLEXD module in UART mode
1269  * with non-blocking method.
1270  *
1271  *END**************************************************************************/
1272  /* implements     Linflexd_Uart_Ip_AsyncSend_Activity */
Linflexd_Uart_Ip_AsyncSend(const uint8 Instance,const uint8 * TxBuff,const uint32 TxSize)1273 Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_AsyncSend(const uint8 Instance, const uint8 * TxBuff, const uint32 TxSize)
1274 {
1275     LINFLEXD_UART_IP_DEV_ASSERT(TxBuff != NULL_PTR);
1276     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
1277 
1278     Linflexd_Uart_Ip_StatusType RetVal = LINFLEXD_UART_IP_STATUS_ERROR;
1279     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
1280 
1281     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1282 
1283     LINFLEXD_UART_IP_DEV_ASSERT(UartUserCfg != NULL_PTR);
1284     LINFLEXD_UART_IP_DEV_ASSERT((LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType) ||
1285                                 (LINFLEXD_UART_IP_USING_DMA == UartUserCfg->TransferType)
1286                                );
1287 
1288     if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
1289     {
1290         /* Start the transmission process using interrupts */
1291         RetVal = Linflexd_Uart_Ip_StartSendUsingInterrupts(Instance, TxBuff, TxSize);
1292     }
1293 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
1294     else
1295     {
1296         /* Start the transmission process using DMA */
1297         RetVal = Linflexd_Uart_Ip_StartSendUsingDma(Instance, TxBuff, TxSize);
1298     }
1299 #endif
1300     /* Start the transmission process */
1301     return RetVal;
1302 }
1303 
1304 /*FUNCTION**********************************************************************
1305  *
1306  * Function Name : Linflexd_Uart_Ip_RxIRQHandler
1307  * Description   : Rx interrupt handler for UART.
1308  * This handler uses the rx buffer stored in the state structure to receive
1309  * data. This is not a public API as it is called by IRQ whenever an interrupt
1310  * occurs.
1311  *
1312  *END**************************************************************************/
Linflexd_Uart_Ip_RxIRQHandler(uint8 Instance)1313 static void Linflexd_Uart_Ip_RxIRQHandler(uint8 Instance)
1314 {
1315     const Linflexd_Uart_Ip_StateStructureType * UartState;
1316     LINFLEXD_Type * Base;
1317 
1318     Base = Linflexd_Uart_Ip_apBases[Instance];
1319     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1320 
1321     if (UartState != NULL_PTR)
1322     {
1323         if ((UartState->IsDriverInitialized) && (UartState->IsRxBusy))
1324         {
1325 
1326             /* Retrieve the data */
1327             Linflexd_Uart_Ip_GetData(Instance);
1328 
1329             /* Clear the flags */
1330             Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG);
1331             Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_MESSAGE_BUFFER_FULL_FLAG);
1332 
1333             /* Check if this was the last byte in the current buffer */
1334             if (0U == UartState->RxSize)
1335             {
1336                 /* Invoke the callback when the buffer is finished;
1337                 * Application can provide another buffer inside the callback by calling Linflexd_Uart_Ip_SetRxBuffer */
1338                 Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_RX_FULL);
1339             }
1340 
1341             /* Finish reception if this was the last byte received */
1342             if (0U == UartState->RxSize)
1343             {
1344                 /* Complete transfer (disable rx logic) */
1345                 Linflexd_Uart_Ip_CompleteReceiveUsingInterrupts(Instance);
1346 
1347                 /* Invoke callback if there is one */
1348                 Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_END_TRANSFER);
1349             }
1350         }
1351         /* Case of spurious interrupt when driver had an error in initialization */
1352         else
1353         {
1354             /* Clear the flags */
1355             Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG);
1356             Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_MESSAGE_BUFFER_FULL_FLAG);
1357         }
1358     }
1359     /* Case of spurious interrupt when driver is not at all initialized*/
1360     else
1361     {
1362         /* Clear the flags */
1363         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG);
1364         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_MESSAGE_BUFFER_FULL_FLAG);
1365     }
1366 }
1367 
1368 /*FUNCTION**********************************************************************
1369  *
1370  * Function Name : Linflexd_Uart_Ip_TxIRQHandler
1371  * Description   : Tx interrupt handler for UART.
1372  * This handler uses the tx buffer stored in the state structure to transmit
1373  * data. This is not a public API as it is called by IRQ whenever an interrupt
1374  * occurs.
1375  *
1376  *END**************************************************************************/
Linflexd_Uart_Ip_TxIRQHandler(uint8 Instance)1377 static void Linflexd_Uart_Ip_TxIRQHandler(uint8 Instance)
1378 {
1379     const Linflexd_Uart_Ip_StateStructureType * UartState;
1380     LINFLEXD_Type * Base;
1381 
1382     Base = Linflexd_Uart_Ip_apBases[Instance];
1383     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1384 
1385     if (UartState != NULL_PTR)
1386     {
1387         if ((UartState->IsDriverInitialized) && (UartState->IsTxBusy))
1388         {
1389             /* Check if there are any more bytes to send */
1390             if (UartState->TxSize > 0U)
1391             {
1392                 /* Clear the flag */
1393                 Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
1394 
1395                 /* Send data */
1396                 Linflexd_Uart_Ip_PutData(Instance);
1397             }
1398             else
1399             {
1400                 /* Invoke the callback when the buffer is finished;
1401                 * Application can provide another buffer inside the callback by calling Linflexd_Uart_Ip_SetTxBuffer */
1402                 Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_TX_EMPTY);
1403                 /* If there is no more data to send, complete the transmission */
1404                 if (0U == UartState->TxSize)
1405                 {
1406                     Linflexd_Uart_Ip_CompleteSendUsingInterrupts(Instance);
1407 
1408                     /* Call the callback to notify application that the transfer is complete */
1409                     Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_END_TRANSFER);
1410                     /* Clear the flag */
1411                     Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
1412                 }
1413             }
1414         }
1415         /* Case of spurious interrupt when driver had an error in initialization */
1416         else
1417         {
1418             Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
1419         }
1420     }
1421     /* Case of spurious interrupt when driver had an error in initialization */
1422     else
1423     {
1424         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
1425     }
1426 }
1427 
1428 /*FUNCTION**********************************************************************
1429  *
1430  * Function Name : Linflexd_Uart_Ip_ErrIRQHandler
1431  * Description   : Error interrupt handler for UART.
1432  * This handler calls the user callback to treat error conditions.
1433  *
1434  *END**************************************************************************/
Linflexd_Uart_Ip_ErrIRQHandler(uint8 Instance)1435 static void Linflexd_Uart_Ip_ErrIRQHandler(uint8 Instance)
1436 {
1437     const Linflexd_Uart_Ip_StateStructureType * UartState;
1438     LINFLEXD_Type * Base;
1439 
1440     Base = Linflexd_Uart_Ip_apBases[Instance];
1441     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1442 
1443     if (UartState != NULL_PTR)
1444     {
1445         if (UartState->IsDriverInitialized)
1446         {
1447             /* Update the receive status according to the error occurred */
1448             Linflexd_Uart_Ip_UpdateErrorIRQHandler(Instance);
1449 
1450             /* Terminate the current reception */
1451             Linflexd_Uart_Ip_CompleteAsyncReceiveData(Instance);
1452         }
1453         /* Case of spurious interrupt when driver had an error in initialization */
1454         else
1455         {
1456             Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG);
1457             Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG);
1458         }
1459     }
1460     /* Case of spurious interrupt when driver had an error in initialization */
1461     else
1462     {
1463         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG);
1464         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG);
1465     }
1466 }
1467 
1468 /*FUNCTION**********************************************************************
1469  *
1470  * Function Name : Linflexd_Uart_Ip_IRQHandler
1471  * Description   : Interrupt handler for UART.
1472  * This handler uses the buffers stored in the state structure to transfer
1473  * data. This is not a public API as it is called by IRQ whenever an interrupt
1474  * occurs.
1475  *
1476  *END**************************************************************************/
1477 /* @implements     Linflexd_Uart_Ip_IRQHandler_Activity*/
Linflexd_Uart_Ip_IRQHandler(uint8 Instance)1478 void Linflexd_Uart_Ip_IRQHandler(uint8 Instance)
1479 {
1480     const LINFLEXD_Type * Base;
1481 
1482     Base = Linflexd_Uart_Ip_apBases[Instance];
1483 
1484     /* Handle receive data full interrupt */
1485     if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG))
1486     {
1487         if (Linflexd_Uart_Ip_IsInterruptEnabled(Base, LINFLEXD_DATA_RECEPTION_COMPLETE_INT))
1488         {
1489             Linflexd_Uart_Ip_RxIRQHandler(Instance);
1490         }
1491         else
1492         {
1493             /* CPR_RTD_00664.uart Spurious interrupt*/
1494             /* Do nothing - Return immediately */
1495         }
1496     }
1497 
1498     /* Handle transmitter data register empty interrupt */
1499     if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG))
1500     {
1501         if (Linflexd_Uart_Ip_IsInterruptEnabled(Base, LINFLEXD_DATA_TRANSMITTED_INT))
1502         {
1503             Linflexd_Uart_Ip_TxIRQHandler(Instance);
1504         }
1505         else
1506         {
1507             /* CPR_RTD_00664.uart Spurious interrupt*/
1508             /* Do nothing - Return immediately */
1509         }
1510     }
1511 
1512     /* Handle the error interrupts if no rx/tx interrupt was triggered */
1513     if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG))
1514     {
1515         if (Linflexd_Uart_Ip_IsInterruptEnabled(Base, LINFLEXD_FRAME_ERROR_INT))
1516         {
1517             Linflexd_Uart_Ip_ErrIRQHandler(Instance);
1518         }
1519         else
1520         {
1521             /* CPR_RTD_00664.uart Spurious interrupt*/
1522             /* Do nothing - Return immediately */
1523         }
1524     }
1525 
1526     if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG))
1527     {
1528         if (Linflexd_Uart_Ip_IsInterruptEnabled(Base, LINFLEXD_BUFFER_OVERRUN_INT))
1529         {
1530             Linflexd_Uart_Ip_ErrIRQHandler(Instance);
1531         }
1532         else
1533         {
1534             /* CPR_RTD_00664.uart Spurious interrupt*/
1535             /* Do nothing - Return immediately */
1536         }
1537     }
1538 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
1539         /* Handle the error interrupts if timeout error */
1540     if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_TIMEOUT_INTERRUPT_FLAG))
1541     {
1542         /* This checking also ensures that the feature is activated for the current instance
1543          * because the Interrupt can be enabled only in this case.
1544          */
1545         if (Linflexd_Uart_Ip_IsInterruptEnabled(Base, LINFLEXD_TIMEOUT_INT))
1546         {
1547             Linflexd_Uart_Ip_ErrIRQHandler(Instance);
1548         }
1549         else
1550         {
1551             /* CPR_RTD_00664.uart Spurious interrupt*/
1552             /* Do nothing - Return immediately */
1553         }
1554     }
1555 #endif
1556 }
1557 
1558 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
1559 /*FUNCTION**********************************************************************
1560  *
1561  * Function Name : Linflexd_Uart_Ip_StartSendUsingDma
1562  * Description   : Initiate (start) a transmit by beginning the process of
1563  * sending data using DMA transfers.
1564  * This is not a public API as it is called from other driver functions.
1565  *
1566  *END**************************************************************************/
Linflexd_Uart_Ip_StartSendUsingDma(const uint8 Instance,const uint8 * TxBuff,const uint32 TxSize)1567 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartSendUsingDma(const uint8 Instance,
1568                                                                       const uint8 * TxBuff,
1569                                                                       const uint32 TxSize)
1570 {
1571     LINFLEXD_Type * Base;
1572     Linflexd_Uart_Ip_StatusType RetVal;
1573     Linflexd_Uart_Ip_StateStructureType * UartState;
1574     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
1575     Dma_Ip_LogicChannelTransferListType DmaTransferList[LINFLEXD_UART_IP_DMA_CONFIG_LIST_DIMENSION];
1576     Dma_Ip_ReturnType DmaReturnStatus;
1577 
1578     Base = Linflexd_Uart_Ip_apBases[Instance];
1579     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1580     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1581 
1582     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_05();
1583     /* Check it's not busy transmitting data from a previous function call */
1584     if (!UartState->IsTxBusy)
1585     {
1586         /* Update state structure */
1587         UartState->IsTxBusy = TRUE;
1588         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_05();
1589         UartState->TxBuff = TxBuff;
1590 
1591         /* Check the validity of the parameters */
1592         LINFLEXD_UART_IP_DEV_ASSERT(TxSize > 0U);
1593         if (!((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength)))
1594         {
1595             /* The size of the buffer should be an even number for DMA transfers with 15/16 bits word length */
1596             LINFLEXD_UART_IP_DEV_ASSERT(0U == (TxSize & 1U));
1597         }
1598         UartState->TxSize = 0U;
1599         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_BUSY;
1600 
1601         /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
1602         DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
1603         DmaTransferList[0].Value = (uint32)TxBuff;
1604         DmaTransferList[1].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
1605         DmaTransferList[1].Value = LINFLEXD_UART_IP_LSBW_ADDR(Base->BDRL);
1606         DmaTransferList[2].Param = DMA_IP_CH_SET_SOURCE_SIGNED_OFFSET;
1607         DmaTransferList[3].Param = DMA_IP_CH_SET_DESTINATION_SIGNED_OFFSET;
1608         DmaTransferList[3].Value = 0;
1609         DmaTransferList[4].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1610         DmaTransferList[5].Param = DMA_IP_CH_SET_MINORLOOP_SIZE;
1611         DmaTransferList[6].Param = DMA_IP_CH_SET_DESTINATION_TRANSFER_SIZE;
1612         DmaTransferList[7].Param = DMA_IP_CH_SET_SOURCE_TRANSFER_SIZE;
1613         if ((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength))
1614         {
1615             DmaTransferList[2].Value = 1;
1616             DmaTransferList[4].Value = TxSize;
1617             DmaTransferList[5].Value = 1;
1618             DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
1619             DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
1620         }
1621         else
1622         {
1623             DmaTransferList[2].Value = 2;
1624             DmaTransferList[4].Value = TxSize/(uint32)2;
1625             DmaTransferList[5].Value = 2;
1626             DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_2_BYTE;
1627             DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_2_BYTE;
1628         }
1629 
1630         DmaTransferList[8].Param = DMA_IP_CH_SET_CONTROL_EN_MAJOR_INTERRUPT;
1631         DmaTransferList[8].Value = 1;
1632         DmaTransferList[9].Param = DMA_IP_CH_SET_CONTROL_DIS_AUTO_REQUEST;
1633         DmaTransferList[9].Value = 1;
1634 
1635         /* Configure the transfer control descriptor for the DMA channel */
1636         DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->TxDMAChannel, DmaTransferList, LINFLEXD_UART_IP_DMA_CONFIG_LIST_DIMENSION);
1637         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1638 
1639         /* Start the DMA channel */
1640         DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
1641         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1642         /* Enable the transmitter */
1643         Linflexd_Uart_Ip_SetTransmitterState(Base, TRUE);
1644 
1645         /* Enable tx DMA requests for the current instance */
1646         Linflexd_Uart_Ip_SetDmaTxEnable(Base, TRUE);
1647 
1648         RetVal = LINFLEXD_UART_IP_STATUS_SUCCESS;
1649     }
1650     else
1651     {
1652         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_05();
1653         RetVal = LINFLEXD_UART_IP_STATUS_BUSY;
1654     }
1655 
1656     return RetVal;
1657 }
1658 
1659 /*FUNCTION**********************************************************************
1660  *
1661  * Function Name : Linflexd_Uart_Ip_StartReceiveUsingDma
1662  * Description   : Initiate (start) a receive by beginning the process of
1663  * receiving data using DMA transfers.
1664  * This is not a public API as it is called from other driver functions.
1665  *
1666  *END**************************************************************************/
Linflexd_Uart_Ip_StartReceiveUsingDma(const uint8 Instance,uint8 * RxBuff,const uint32 RxSize)1667 static Linflexd_Uart_Ip_StatusType Linflexd_Uart_Ip_StartReceiveUsingDma(const uint8 Instance,
1668                                                                          uint8 * RxBuff,
1669                                                                          const uint32 RxSize)
1670 {
1671     LINFLEXD_Type * Base;
1672     Linflexd_Uart_Ip_StatusType RetVal;
1673     Linflexd_Uart_Ip_StateStructureType * UartState;
1674     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
1675     Dma_Ip_LogicChannelTransferListType DmaTransferList[LINFLEXD_UART_IP_DMA_CONFIG_LIST_DIMENSION];
1676     Dma_Ip_ReturnType DmaReturnStatus;
1677 
1678     Base = Linflexd_Uart_Ip_apBases[Instance];
1679     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1680     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1681 
1682 
1683     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_08();
1684     /* Check it's not busy transmitting data from a previous function call */
1685     if (!UartState->IsRxBusy)
1686     {
1687         /* Update the state structure */
1688         UartState->IsRxBusy = TRUE;
1689         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_08();
1690 
1691         LINFLEXD_UART_IP_DEV_ASSERT(RxSize > 0U);
1692         if (!((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength)))
1693         {
1694             /* The size of the buffer should be an even number for DMA transfers with 15/16 bits word length */
1695             LINFLEXD_UART_IP_DEV_ASSERT(0U == (RxSize & 1U));
1696         }
1697         UartState->RxBuff = RxBuff;
1698         UartState->RxSize = 0U;
1699         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_BUSY;
1700 
1701         /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
1702         DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
1703         DmaTransferList[0].Value = LINFLEXD_UART_IP_LSBW_ADDR(Base->BDRM);
1704         DmaTransferList[1].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
1705         DmaTransferList[1].Value = (uint32)RxBuff;
1706         DmaTransferList[2].Param = DMA_IP_CH_SET_SOURCE_SIGNED_OFFSET;
1707         DmaTransferList[2].Value = 0;
1708         DmaTransferList[3].Param = DMA_IP_CH_SET_DESTINATION_SIGNED_OFFSET;
1709         DmaTransferList[4].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1710         DmaTransferList[5].Param = DMA_IP_CH_SET_MINORLOOP_SIZE;
1711         DmaTransferList[6].Param = DMA_IP_CH_SET_DESTINATION_TRANSFER_SIZE;
1712         DmaTransferList[7].Param = DMA_IP_CH_SET_SOURCE_TRANSFER_SIZE;
1713         if ((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength))
1714         {
1715             DmaTransferList[3].Value = 1;
1716             DmaTransferList[4].Value = RxSize;
1717             DmaTransferList[5].Value = 1;
1718             DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
1719             DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_1_BYTE;
1720         }
1721         else
1722         {
1723             DmaTransferList[3].Value = 2;
1724             DmaTransferList[4].Value = RxSize/(uint32)2;
1725             DmaTransferList[5].Value = 2;
1726             DmaTransferList[6].Value = DMA_IP_TRANSFER_SIZE_2_BYTE;
1727             DmaTransferList[7].Value = DMA_IP_TRANSFER_SIZE_2_BYTE;
1728         }
1729         DmaTransferList[8].Param = DMA_IP_CH_SET_CONTROL_EN_MAJOR_INTERRUPT;
1730         DmaTransferList[8].Value = 1;
1731         DmaTransferList[9].Param = DMA_IP_CH_SET_CONTROL_DIS_AUTO_REQUEST;
1732         DmaTransferList[9].Value = 1;
1733 
1734         /* Configure the transfer control descriptor for the DMA channel */
1735         DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->RxDMAChannel, DmaTransferList, LINFLEXD_UART_IP_DMA_CONFIG_LIST_DIMENSION);
1736         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1737 
1738         /* Start the DMA channel */
1739         DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
1740 
1741         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1742         /* Flush the rx FIFO to discard any junk data received while the driver was idle */
1743         Linflexd_Uart_Ip_FlushRxFifo(Base, UartUserCfg->WordLength);
1744 
1745         /* Enable the receiver */
1746         Linflexd_Uart_Ip_SetReceiverState(Base, TRUE);
1747 
1748         /* Enable rx DMA requests for the current instance */
1749         Linflexd_Uart_Ip_SetDmaRxEnable(Base, TRUE);
1750 
1751         RetVal = LINFLEXD_UART_IP_STATUS_SUCCESS;
1752     }
1753     else
1754     {
1755         SchM_Exit_Uart_UART_EXCLUSIVE_AREA_08();
1756         RetVal = LINFLEXD_UART_IP_STATUS_BUSY;
1757     }
1758 
1759     return RetVal;
1760 }
1761 
1762 /*FUNCTION**********************************************************************
1763  *
1764  * Function Name : Linflexd_Uart_Ip_CompleteSendUsingDma
1765  * Description   : Finish up a transmit by completing the process of sending
1766  * data and disabling the DMA requests. This is a callback for DMA major loop
1767  * completion, so it must match the DMA callback signature.
1768  *
1769  *END**************************************************************************/
Linflexd_Uart_Ip_CompleteSendUsingDma(uint8 Instance)1770 void Linflexd_Uart_Ip_CompleteSendUsingDma(uint8 Instance)
1771 {
1772     LINFLEXD_Type * Base;
1773     Linflexd_Uart_Ip_StateStructureType * UartState;
1774     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
1775     Dma_Ip_LogicChannelTransferListType DmaTransferList[LINFLEXD_UART_DMA_LEAST_CONFIG_LIST_DIMENSION];
1776     Dma_Ip_ReturnType DmaReturnStatus;
1777     Dma_Ip_LogicChannelStatusType DmaStatus;
1778 
1779     Base = Linflexd_Uart_Ip_apBases[Instance];
1780     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1781     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1782     DmaStatus.ChStateValue = DMA_IP_CH_ERROR_STATE;
1783 
1784     /* Get Dma Ip Logic Channel Status */
1785     (void)Dma_Ip_GetLogicChannelStatus(UartUserCfg->TxDMAChannel, &DmaStatus);
1786     if (DMA_IP_CH_ERROR_STATE == DmaStatus.ChStateValue)
1787     {
1788         /* Reset the Dma Channel Error status. */
1789         DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_CLEAR_ERROR);
1790 
1791         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1792         /* Update transmit status */
1793         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_DMA_ERROR;
1794         /* Invoke callback if there is one */
1795         Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_ERROR);
1796     }
1797 
1798     /* Invoke the callback when the buffer is finished;
1799      * Application can provide another buffer inside the callback by calling Linflexd_Uart_Ip_SetTxBuffer */
1800     if (LINFLEXD_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
1801     {
1802         Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_TX_EMPTY);
1803     }
1804 
1805     /* If the callback has updated the tx buffer, update the DMA descriptor to continue the transfer;
1806      * otherwise, stop the current transfer.
1807      */
1808     if (UartState->TxSize > 0U)
1809     {
1810         /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
1811         DmaTransferList[0].Param = DMA_IP_CH_SET_SOURCE_ADDRESS;
1812         DmaTransferList[1].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1813         /* Update tx size and major loop count parameters for Dma_Ip_LogicChannelTransferListType */
1814         DmaTransferList[0].Value = (uint32)(UartState->TxBuff);
1815         if (!((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength)))
1816         {
1817             /* The size of the buffer should be an even number for DMA transfers with 15/16 bits word length */
1818             LINFLEXD_UART_IP_DEV_ASSERT(0U == (UartState->TxSize & 1U));
1819         }
1820         if ((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength))
1821         {
1822             DmaTransferList[1].Value = UartState->TxSize;
1823         }
1824         else
1825         {
1826             DmaTransferList[1].Value = (UartState->TxSize)/(uint32)2;
1827         }
1828 
1829         /* Re-configure the transfer control descriptor for the DMA channel */
1830         DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->TxDMAChannel, DmaTransferList, LINFLEXD_UART_DMA_LEAST_CONFIG_LIST_DIMENSION);
1831         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1832 
1833         /* Now that this tx is set up, clear remaining bytes count */
1834         UartState->TxSize = 0U;
1835 
1836         /* Re-start the channel */
1837         DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->TxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
1838         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1839     }
1840     else
1841     {
1842         /* Disable the transmitter */
1843         Linflexd_Uart_Ip_SetTransmitterState(Base, FALSE);
1844 
1845         /* Disable tx DMA requests for the current instance */
1846         Linflexd_Uart_Ip_SetDmaTxEnable(Base, FALSE);
1847 
1848         /* Update the busy flag */
1849         UartState->IsTxBusy = FALSE;
1850 
1851         /* If the current reception hasn't been aborted, update the status */
1852         if (LINFLEXD_UART_IP_STATUS_BUSY == UartState->TransmitStatus)
1853         {
1854             UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
1855             /* Call the callback to notify application that the transfer is complete */
1856             Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_END_TRANSFER);
1857         }
1858     }
1859 }
1860 
1861 
1862 /*FUNCTION**********************************************************************
1863  *
1864  * Function Name : Linflexd_Uart_Ip_CompleteReceiveUsingDma
1865  * Description   : Finish up a receive by completing the process of receiving data
1866  * and disabling the DMA requests. This is a callback for DMA major loop
1867  * completion, so it must match the DMA callback signature.
1868  *
1869  *END**************************************************************************/
Linflexd_Uart_Ip_CompleteReceiveUsingDma(uint8 Instance)1870 void Linflexd_Uart_Ip_CompleteReceiveUsingDma(uint8 Instance)
1871 {
1872     LINFLEXD_Type * Base;
1873     Linflexd_Uart_Ip_StateStructureType * UartState;
1874     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
1875     Dma_Ip_LogicChannelTransferListType DmaTransferList[LINFLEXD_UART_DMA_LEAST_CONFIG_LIST_DIMENSION];
1876     Dma_Ip_ReturnType DmaReturnStatus;
1877     Dma_Ip_LogicChannelStatusType DmaStatus;
1878     uint32 StartTime;
1879     uint32 TimeoutTicks;
1880     uint32 ElapsedTicks = 0;
1881 
1882     Base = Linflexd_Uart_Ip_apBases[Instance];
1883     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
1884     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
1885     DmaStatus.ChStateValue = DMA_IP_CH_ERROR_STATE;
1886 
1887     /* Get Dma Ip Logic Channel Status */
1888     (void)Dma_Ip_GetLogicChannelStatus(UartUserCfg->RxDMAChannel, &DmaStatus);
1889 
1890     if (DMA_IP_CH_ERROR_STATE == DmaStatus.ChStateValue)
1891     {
1892         /* Reset the Dma Channel Error status. */
1893         DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_ERROR);
1894 
1895         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1896         /* Update transmit status */
1897         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_DMA_ERROR;
1898         /* Invoke callback if there is one */
1899         Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_ERROR);
1900     }
1901 
1902     /* Invoke the callback when the buffer is finished */
1903     if (LINFLEXD_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
1904     {
1905         /* Application can provide another buffer inside the callback by calling Linflexd_Uart_Ip_SetRxBuffer */
1906         Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_RX_FULL);
1907     }
1908 
1909     /* If the callback has updated the rx buffer, update the DMA descriptor to continue the transfer;
1910      * otherwise, stop the current transfer.
1911      */
1912     if (UartState->RxSize > 0U)
1913     {
1914         /* Set up parameters for Dma_Ip_LogicChannelTransferListType */
1915         DmaTransferList[0].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
1916         DmaTransferList[1].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1917         DmaTransferList[0].Value = (uint32)(UartState->RxBuff);
1918         if ((LINFLEXD_UART_IP_7_BITS == UartUserCfg->WordLength) || (LINFLEXD_UART_IP_8_BITS == UartUserCfg->WordLength))
1919         {
1920             DmaTransferList[1].Value = UartState->RxSize;
1921         }
1922         else
1923         {
1924             DmaTransferList[1].Value = (UartState->RxSize)/(uint32)2;
1925         }
1926         /* Re-configure the transfer control descriptor for the DMA channel */
1927         DmaReturnStatus = Dma_Ip_SetLogicChannelTransferList(UartUserCfg->RxDMAChannel, DmaTransferList, LINFLEXD_UART_DMA_LEAST_CONFIG_LIST_DIMENSION);
1928         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1929         /* Now that this rx is set up, clear remaining bytes count */
1930         UartState->RxSize = 0U;
1931         /* Re-start the channel */
1932         DmaReturnStatus = Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
1933         LINFLEXD_UART_IP_DEV_ASSERT(DMA_IP_STATUS_SUCCESS == DmaReturnStatus);
1934     }
1935     else
1936     {
1937         /* Disable rx DMA requests for the current instance */
1938         Linflexd_Uart_Ip_SetDmaRxEnable(Base, FALSE);
1939 
1940         /* In Abort case, the transmission need to stop instantly */
1941         if (LINFLEXD_UART_IP_STATUS_ABORTED == UartState->ReceiveStatus)
1942         {
1943             /* Wait until the last transmission complete */
1944             Linflexd_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_VALUE_US, LINFLEXD_UART_IP_TIMEOUT_TYPE);
1945             while (!Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG) && \
1946                    !Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE) \
1947                   )
1948             {}
1949             if (Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
1950             {
1951               /* In case timeout occur */
1952                 UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_TIMEOUT;
1953             }
1954         }
1955         /* Disable the receiver */
1956         Linflexd_Uart_Ip_SetReceiverState(Base, FALSE);
1957 
1958         /* Update the information of the module driver state */
1959         UartState->IsRxBusy = FALSE;
1960 
1961         /* If the current reception hasn't been aborted, update the status and call the callback */
1962         if (LINFLEXD_UART_IP_STATUS_BUSY == UartState->ReceiveStatus)
1963         {
1964             UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
1965 
1966             /* Call the callback to notify application that the transfer is complete */
1967             Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_END_TRANSFER);
1968         }
1969         /* Disable error interrupts */
1970         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_FRAME_ERROR_INT, FALSE);
1971         Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_BUFFER_OVERRUN_INT, FALSE);
1972 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
1973         if (Linflexd_Uart_Ip_InstHasTimeoutInterruptEnabled[Instance])
1974         {
1975             /* Disable timeout interrupt */
1976             Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_TIMEOUT_INT, FALSE);
1977         }
1978 #endif
1979     }
1980 }
1981 
1982 /*FUNCTION**********************************************************************
1983  *
1984  * Function Name : Linflexd_Uart_Ip_FlushRxFifo
1985  * Description   : Flushes the rx FIFO.
1986  * This is not a public API as it is called from other driver functions.
1987  *
1988  *END**************************************************************************/
Linflexd_Uart_Ip_FlushRxFifo(const LINFLEXD_Type * Base,const Linflexd_Uart_Ip_WordLengthType WordLength)1989 static void Linflexd_Uart_Ip_FlushRxFifo(const LINFLEXD_Type *Base,const Linflexd_Uart_Ip_WordLengthType WordLength)
1990 {
1991     uint16 DummyData;
1992 
1993     if ((LINFLEXD_UART_IP_7_BITS == WordLength) || (LINFLEXD_UART_IP_8_BITS == WordLength))
1994     {
1995         volatile const uint8 *FifoBase;
1996 
1997         /* Get the address of the FIFO */
1998         FifoBase = (volatile const uint8 *)(&(Base->BDRM));
1999 #ifdef PARTITION_BIG_ENDIAN
2000         FifoBase = &FifoBase[3];
2001 #endif
2002 
2003         /* Four dummy reads, to flush the FIFO contents */
2004         DummyData = (uint16)(*FifoBase);
2005         DummyData = (uint16)(*FifoBase);
2006         DummyData = (uint16)(*FifoBase);
2007         DummyData = (uint16)(*FifoBase);
2008         (void)DummyData;
2009     }
2010     else
2011     {
2012         volatile const uint16 *u16FifoBase;
2013 
2014         /* Get the address of the FIFO */
2015         u16FifoBase = (volatile const uint16 *)(&(Base->BDRM));
2016 #ifdef PARTITION_BIG_ENDIAN
2017         u16FifoBase = &u16FifoBase[1];
2018 #endif
2019 
2020         /* Four dummy reads, to flush the FIFO contents */
2021         DummyData = *u16FifoBase;
2022         DummyData = *u16FifoBase;
2023         DummyData = *u16FifoBase;
2024         DummyData = *u16FifoBase;
2025         (void)DummyData;
2026     }
2027 }
2028 #endif
2029 
2030 /*FUNCTION**********************************************************************
2031  *
2032  * Function Name : Linflexd_Uart_Ip_SetUp_Init
2033  * Description   : Set up Linflexd Uart to Init Privileged.
2034  * This is not a public API as it is called from other driver functions.
2035  *
2036  *END**************************************************************************/
Linflexd_Uart_Ip_SetUp_Init(const uint8 Instance)2037 static void Linflexd_Uart_Ip_SetUp_Init(const uint8 Instance)
2038 {
2039     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
2040 
2041     /* Set UARTSR to Default Value. */
2042     Base->UARTSR = 0xFF;
2043 
2044     /* Set UART mode */
2045     Linflexd_Uart_Ip_SetMode(Base, LINFLEXD_UART_MODE);
2046 
2047     /* Set the baud rate */
2048     Linflexd_Uart_Ip_SetUp_Baudrate(Instance);
2049 
2050 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
2051     Linflexd_Uart_Ip_SetUp_SetupTimeoutParameters(Instance);
2052 #endif
2053 
2054 #if (LINFLEXD_UART_IP_ENABLE_INTERNAL_LOOPBACK == STD_ON)
2055     if (Linflexd_Uart_Ip_InstHasLoopbackEnabled[Instance])
2056     {
2057         Base->LINCR1 |= LINFLEXD_LINCR1_LBKM(1);
2058     }
2059 #endif
2060 
2061     /* Set word length */
2062     Linflexd_Uart_Ip_SetWordLength(Instance);
2063 
2064     /* Set parity */
2065     Linflexd_Uart_Ip_SetUp_Parity(Instance);
2066 
2067     /* Set stop bits count */
2068     Linflexd_Uart_Ip_SetUp_SetTxRxStopBitsCount(Instance);
2069 
2070     /* Enable FIFO for DMA based communication, or buffer mode for interrupt based communication */
2071     Linflexd_Uart_Ip_SetTxRxMode(Instance);
2072 }
2073 
2074 /*FUNCTION**********************************************************************
2075  *
2076  * Function Name : Linflexd_Uart_Ip_SetWordLength
2077  * Description   : Set up word length for Linflexd Uart.
2078  * This is not a public API as it is called from other driver functions.
2079  *
2080  *END**************************************************************************/
Linflexd_Uart_Ip_SetWordLength(const uint8 Instance)2081 static void Linflexd_Uart_Ip_SetWordLength(const uint8 Instance)
2082 {
2083     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
2084     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
2085 
2086     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2087     Linflexd_Uart_Ip_SetUartWordLength(Base, UartUserCfg->WordLength);
2088     Linflexd_Uart_Ip_SetTxDataFieldLength(Base, (uint8)((uint8)UartUserCfg->WordLength >> 1U));
2089     Linflexd_Uart_Ip_SetRxDataFieldLength(Base, (uint8)((uint8)UartUserCfg->WordLength >> 1U));
2090 }
2091 /*FUNCTION**********************************************************************
2092  *
2093  * Function Name : Linflexd_Uart_Ip_UpdateReceiver
2094  * Description   : Update status and clear the flag according to the error occurred.
2095  * This is not a public API as it is called from other driver functions.
2096  *
2097  *END**************************************************************************/
Linflexd_Uart_Ip_UpdateReceiver(const uint8 Instance,uint32 * StartTime,uint32 * ElapsedTicks,uint32 TimeoutTicks)2098 static void Linflexd_Uart_Ip_UpdateReceiver(const uint8 Instance, uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks)
2099 {
2100         LINFLEXD_Type * Base;
2101         Linflexd_Uart_Ip_StateStructureType * UartState;
2102         boolean IsError = FALSE;
2103 
2104         Base = Linflexd_Uart_Ip_apBases[Instance];
2105         UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
2106 
2107         /* To be updated with timeout when aProach is defined*/
2108         while ((UartState->RxSize > 0U) && !Linflexd_Uart_Ip_CheckTimeout(StartTime, ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
2109         {
2110             /* Wait until data reception flag is set or timeout occurs if there is an error during reception */
2111             while (!Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG) && \
2112                    !Linflexd_Uart_Ip_CheckTimeout(StartTime, ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE) \
2113                   )
2114             {}
2115             /* Update the receive status according to the error occurred */
2116             if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG))
2117             {
2118                 /* Update the status */
2119                 UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_RX_OVERRUN;
2120                 /* Clear the flag */
2121                 Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG);
2122                 IsError = TRUE;
2123             }
2124             if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG))
2125             {
2126                 /* Update the status */
2127                 UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_FRAMING_ERROR;
2128                 /* Clear the flag */
2129                 Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG);
2130                 IsError = TRUE;
2131             }
2132             if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_PARITY_ERROR_FLAG))
2133             {
2134                 /* Update the status */
2135                 UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_PARITY_ERROR;
2136                 /* Clear the flag */
2137                 Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_PARITY_ERROR_FLAG);
2138                 IsError = TRUE;
2139             }
2140             if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_NOISE_FLAG))
2141             {
2142                 /* Update the status */
2143                 UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_NOISE_ERROR;
2144                 /* Clear the flag */
2145                 Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_NOISE_FLAG);
2146                 IsError = TRUE;
2147             }
2148             /* Check if Timeout occur */
2149             if (Linflexd_Uart_Ip_CheckTimeout(StartTime, ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
2150             {
2151                 UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_TIMEOUT;
2152                 IsError = TRUE;
2153             }
2154 
2155             if (!IsError)
2156             {
2157                 /* Retrieve the data */
2158                 Linflexd_Uart_Ip_GetData(Instance);
2159                 /* Clear the flags */
2160                 Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG);
2161                 Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_MESSAGE_BUFFER_FULL_FLAG);
2162             }
2163             else
2164             {
2165                 break;
2166             }
2167         }
2168 }
2169 
2170 /*FUNCTION**********************************************************************
2171  *
2172  * Function Name : Linflexd_Uart_Ip_SetUp_Receiver
2173  * Description   : Disble transmission complete interrupt, Disable receive data full interrupt.
2174                    and Disable error interrupts to Enable the receiver.
2175  * This is not a public API as it is called from other driver functions.
2176  *
2177  *END**************************************************************************/
Linflexd_Uart_Ip_SetUp_Receiver(const uint8 Instance)2178 static void Linflexd_Uart_Ip_SetUp_Receiver(const uint8 Instance)
2179 {
2180     LINFLEXD_Type * Base;
2181 
2182     Base = Linflexd_Uart_Ip_apBases[Instance];
2183 
2184     /* Disble transmission complete interrupt */
2185     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_TRANSMITTED_INT, FALSE);
2186     /* Disable receive data full interrupt. */
2187     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_DATA_RECEPTION_COMPLETE_INT, FALSE);
2188     /* Disable error interrupts */
2189     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_FRAME_ERROR_INT, FALSE);
2190     Linflexd_Uart_Ip_SetInterruptMode(Base, LINFLEXD_BUFFER_OVERRUN_INT, FALSE);
2191 
2192     /* Enable the receiver */
2193     Linflexd_Uart_Ip_SetReceiverState(Base, TRUE);
2194 }
2195 
2196 /*FUNCTION**********************************************************************
2197  *
2198  * Function Name : Linflexd_Uart_Ip_GetRemainingBytes
2199  * Description   : Get the Remaining Bytes
2200  * This is not a public API as it is called from other driver functions.
2201  *
2202  *END**************************************************************************/
Linflexd_Uart_Ip_GetRemainingBytes(const uint8 Instance,uint32 * BytesRemaining,Linflexd_Uart_Ip_DataDirectionType Direction)2203 static void Linflexd_Uart_Ip_GetRemainingBytes(const uint8 Instance, uint32 * BytesRemaining, Linflexd_Uart_Ip_DataDirectionType Direction)
2204 {
2205     const Linflexd_Uart_Ip_UserConfigType *UartUserCfg;
2206     const Linflexd_Uart_Ip_StateStructureType * UartState;
2207 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
2208     const Dma_Ip_LogicChannelInfoParamType DmaLogicChnParam = DMA_IP_CH_GET_CURRENT_ITER_COUNT;
2209 #endif
2210 
2211     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2212     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
2213 
2214     /* Fill in the number of bytes yet to be received or transferred and update the return value if needed */
2215     if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
2216     {
2217         SchM_Enter_Uart_UART_EXCLUSIVE_AREA_09();
2218         /* In interrupt-based communication, the remaining bytes are retrieved
2219          * from the state structure
2220          */
2221         if (LINFLEXD_UART_IP_RECEIVE == Direction)
2222         {
2223             *BytesRemaining = UartState->RxSize;
2224             SchM_Exit_Uart_UART_EXCLUSIVE_AREA_09();
2225         }
2226         else
2227         {
2228             *BytesRemaining = UartState->TxSize;
2229             SchM_Exit_Uart_UART_EXCLUSIVE_AREA_09();
2230         }
2231     }
2232 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
2233     else
2234     {
2235         /* In DMA-based communication, the remaining bytes are retrieved
2236          * from the current DMA major loop count
2237          */
2238         if (LINFLEXD_UART_IP_RECEIVE == Direction)
2239         {
2240             (void)Dma_Ip_GetLogicChannelParam(UartUserCfg->RxDMAChannel, DmaLogicChnParam, BytesRemaining);
2241         }
2242         else
2243         {
2244             (void)Dma_Ip_GetLogicChannelParam(UartUserCfg->TxDMAChannel, DmaLogicChnParam, BytesRemaining);
2245         }
2246     }
2247 #endif
2248 }
2249 
2250 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
2251 
2252 /*FUNCTION**********************************************************************
2253  *
2254  * Function Name : Linflexd_Uart_Ip_GetActualWordLengthValue
2255  * Description   : Converting word length value from enum to unsigned type.
2256  * This is not a public API as it is called from other driver functions.
2257  *
2258  *END**************************************************************************/
Linflexd_Uart_Ip_GetActualWordLengthValue(const uint8 Instance)2259 static uint16 Linflexd_Uart_Ip_GetActualWordLengthValue(const uint8 Instance)
2260 {
2261     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2262     uint16 WordLengthValue = 7U;
2263 
2264     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2265     switch (UartUserCfg->WordLength)
2266     {
2267         case LINFLEXD_UART_IP_7_BITS:
2268             WordLengthValue = 7U;
2269             break;
2270         case LINFLEXD_UART_IP_8_BITS:
2271             WordLengthValue = 8U;
2272             break;
2273         case LINFLEXD_UART_IP_15_BITS:
2274             WordLengthValue = 15U;
2275             break;
2276         case LINFLEXD_UART_IP_16_BITS:
2277             WordLengthValue = 16U;
2278             break;
2279         default:
2280             /* Do nothing */
2281             break;
2282     }
2283     return WordLengthValue;
2284 }
2285 
2286 /*FUNCTION**********************************************************************
2287  *
2288  * Function Name : Linflexd_Uart_Ip_SetUp_SetupTimeoutParameters
2289  * Description   : Set up Linflexd Uart to enable timeout interrupt.
2290  * This is not a public API as it is called from other driver functions.
2291  *
2292  *END**************************************************************************/
Linflexd_Uart_Ip_SetUp_SetupTimeoutParameters(const uint8 Instance)2293 static void Linflexd_Uart_Ip_SetUp_SetupTimeoutParameters(const uint8 Instance)
2294 {
2295     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
2296     uint16 WordLengthValue = Linflexd_Uart_Ip_GetActualWordLengthValue(Instance);
2297 
2298     if (Linflexd_Uart_Ip_InstHasTimeoutInterruptEnabled[Instance])
2299     {
2300         Linflexd_Uart_Ip_EnableTimerReset(Base, TRUE);
2301         Linflexd_Uart_Ip_EnableMonitorIdleState(Base, TRUE);
2302         /* Reset the value of the PTO to default by the number of bits in a word + 2U (stop and start bit) */
2303         Linflexd_Uart_Ip_SetPresetValue(Base, WordLengthValue + 2U);
2304     }
2305 }
2306 #endif
2307 
2308 #if (STD_ON == LINFLEXD_UART_IP_SET_USER_ACCESS_ALLOWED_AVAILABLE)
2309 /**
2310 * @brief This function will set UAA bit in REG_PROT for UART unit
2311 */
Linflexd_Uart_Ip_SetUserAccess(const uint8 Instance)2312 void Linflexd_Uart_Ip_SetUserAccess(const uint8 Instance)
2313 {
2314     LINFLEXD_Type * Base;
2315 
2316     Base = Linflexd_Uart_Ip_apBases[Instance];
2317 
2318     SET_USER_ACCESS_ALLOWED((uint32)Base, LINFLEX_PROT_MEM_U32);
2319 }
2320 
2321 /**
2322 * @brief This function will enable writing all UART registers under protection in User mode by configuring REG_PROT
2323 */
Linflexd_Uart_Ip_SetUserAccessAllowed(const uint8 Instance)2324 static void Linflexd_Uart_Ip_SetUserAccessAllowed(const uint8 Instance)
2325 {
2326     OsIf_Trusted_Call1param(Linflexd_Uart_Ip_SetUserAccess, Instance);
2327 }
2328 #endif /* LINFLEXD_UART_IP_SET_USER_ACCESS_ALLOWED_AVAILABLE */
2329 
2330 /*FUNCTION**********************************************************************
2331  *
2332  * Function Name : Linflexd_Uart_Ip_SetTransmitterState
2333  * Description   : This function enables or disables the UART transmitter, Based on the parameter received.
2334  * Should be called only when the module is in UART mode.
2335  *
2336  *END**************************************************************************/
Linflexd_Uart_Ip_SetTransmitterState(LINFLEXD_Type * Base,boolean Enable)2337 static void Linflexd_Uart_Ip_SetTransmitterState(LINFLEXD_Type *Base, boolean Enable)
2338 {
2339     uint32 RegValTemp;
2340 
2341     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_00();
2342     RegValTemp = Base->UARTCR;
2343     RegValTemp &= ~(LINFLEXD_UARTCR_TxEn_MASK);
2344     RegValTemp |= LINFLEXD_UARTCR_TxEn(Enable ? 1UL : 0UL);
2345     Base->UARTCR = RegValTemp;
2346     SchM_Exit_Uart_UART_EXCLUSIVE_AREA_00();
2347 }
2348 
2349 /*FUNCTION**********************************************************************
2350  *
2351  * Function Name : Linflexd_Uart_Ip_SetReceiverState
2352  * Description   : This function enables or disables the UART receiver, Based on the parameter received.
2353  * Should be called only when the module is in UART mode.
2354  *
2355  *END**************************************************************************/
Linflexd_Uart_Ip_SetReceiverState(LINFLEXD_Type * Base,boolean Enable)2356 static void Linflexd_Uart_Ip_SetReceiverState(LINFLEXD_Type *Base, boolean Enable)
2357 {
2358     uint32 RegValTemp;
2359 
2360     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_01();
2361     RegValTemp = Base->UARTCR;
2362     RegValTemp &= ~(LINFLEXD_UARTCR_RxEn_MASK);
2363     RegValTemp |= LINFLEXD_UARTCR_RxEn(Enable ? 1UL : 0UL);
2364     Base->UARTCR = RegValTemp;
2365     SchM_Exit_Uart_UART_EXCLUSIVE_AREA_01();
2366 }
2367 
2368 /*FUNCTION**********************************************************************
2369  *
2370  * Function Name : Linflexd_Uart_Ip_SetInterruptMode
2371  * Description   : This function configures whether the UART Event will trigger an interrupt.
2372  *
2373  *END**************************************************************************/
Linflexd_Uart_Ip_SetInterruptMode(LINFLEXD_Type * Base,Linflexd_Uart_Ip_InterruptType IntSrc,boolean Enable)2374 static void Linflexd_Uart_Ip_SetInterruptMode(LINFLEXD_Type * Base, Linflexd_Uart_Ip_InterruptType IntSrc, boolean Enable)
2375 {
2376     uint32 RegValTemp;
2377 
2378     SchM_Enter_Uart_UART_EXCLUSIVE_AREA_02();
2379     RegValTemp = Base->LINIER;
2380     if (Enable)
2381     {
2382         RegValTemp |= (uint32)IntSrc;
2383     }
2384     else
2385     {
2386         RegValTemp &= ~(uint32)IntSrc;
2387     }
2388     Base->LINIER = RegValTemp;
2389     SchM_Exit_Uart_UART_EXCLUSIVE_AREA_02();
2390 }
2391 
2392 /*FUNCTION**********************************************************************
2393  *
2394  * Function Name : Linflexd_Uart_Ip_SetUp_Baudrate
2395  * Description   : Set up baudrate for Linflexd Uart.
2396  *
2397  *END**************************************************************************/
Linflexd_Uart_Ip_SetUp_Baudrate(const uint8 Instance)2398 static void Linflexd_Uart_Ip_SetUp_Baudrate(const uint8 Instance)
2399 {
2400     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2401     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
2402     Linflexd_Uart_Ip_StateStructureType * UartStatePtr;
2403 
2404     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2405     UartStatePtr = Linflexd_Uart_Ip_apStateStructuresArray[Instance];
2406 
2407     /* Check for Custom Baurate is enable or not */
2408     if (16U != UartUserCfg->BaudRateDivisor)
2409     {
2410         /* Reduced Oversampling is enabled */
2411         Base->UARTCR |= LINFLEXD_UARTCR_ROSE(1);
2412         Base->UARTCR |= LINFLEXD_UARTCR_OSR(UartUserCfg->BaudRateDivisor);
2413     }
2414     else
2415     {
2416         Base->UARTCR &= ~LINFLEXD_UARTCR_ROSE(1);
2417     }
2418 
2419     /* Set the baud rate */
2420     Linflexd_Uart_Ip_SetIntegerBaudRate(Base, UartUserCfg->BaudRateMantissa);
2421     Linflexd_Uart_Ip_SetFractionalBaudRate(Base, UartUserCfg->BaudRateFractionalDivisor);
2422 
2423     UartStatePtr->Baudrate = UartUserCfg->BaudRate;
2424 
2425 }
2426 
2427 /*FUNCTION**********************************************************************
2428  *
2429  * Function Name : Linflexd_Uart_Ip_SetTxRxMode
2430  * Description   : Set up Tx/Rx FIFO or buffer mode for Linflexd Uart.
2431  *
2432  *END**************************************************************************/
Linflexd_Uart_Ip_SetTxRxMode(const uint8 Instance)2433 static void Linflexd_Uart_Ip_SetTxRxMode(const uint8 Instance)
2434 {
2435     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2436     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
2437 
2438     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2439 
2440     /* Enable FIFO for DMA based communication, or buffer mode for interrupt based communication */
2441     if (LINFLEXD_UART_IP_USING_DMA == UartUserCfg->TransferType)
2442     {
2443         Linflexd_Uart_Ip_SetTxMode(Base, LINFLEXD_UART_RXTX_FIFO_MODE);
2444         Linflexd_Uart_Ip_SetRxMode(Base, LINFLEXD_UART_RXTX_FIFO_MODE);
2445     }
2446     else
2447     {
2448         Linflexd_Uart_Ip_SetTxMode(Base, LINFLEXD_UART_RXTX_BUFFER_MODE);
2449         Linflexd_Uart_Ip_SetRxMode(Base, LINFLEXD_UART_RXTX_BUFFER_MODE);
2450     }
2451 }
2452 
2453 /*FUNCTION**********************************************************************
2454  *
2455  * Function Name : Linflexd_Uart_Ip_SetUp_Parity
2456  * Description   : Set up parity for Linflexd Uart.
2457  *
2458  *END**************************************************************************/
Linflexd_Uart_Ip_SetUp_Parity(const uint8 Instance)2459 static void Linflexd_Uart_Ip_SetUp_Parity(const uint8 Instance)
2460 {
2461     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2462     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
2463 
2464     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2465 
2466     if (UartUserCfg->ParityCheck)
2467     {
2468         Linflexd_Uart_Ip_SetParityControl(Base, TRUE);
2469         Linflexd_Uart_Ip_SetParityType(Base, UartUserCfg->ParityType);
2470     }
2471     else
2472     {
2473         Linflexd_Uart_Ip_SetParityControl(Base, FALSE);
2474     }
2475 }
2476 
2477 /*FUNCTION**********************************************************************
2478  *
2479  * Function Name : Linflexd_Uart_Ip_SetUp_SetTxRxStopBitsCount
2480  * Description   : Set up stop bits count for Linflexd Uart.
2481  *
2482  *END**************************************************************************/
Linflexd_Uart_Ip_SetUp_SetTxRxStopBitsCount(const uint8 Instance)2483 static void Linflexd_Uart_Ip_SetUp_SetTxRxStopBitsCount(const uint8 Instance)
2484 {
2485     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2486     LINFLEXD_Type * Base = Linflexd_Uart_Ip_apBases[Instance];
2487 
2488     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2489 
2490     Linflexd_Uart_Ip_SetRxStopBitsCount(Base, UartUserCfg->StopBitsCount);
2491     Linflexd_Uart_Ip_SetTxStopBitsCount(Base, UartUserCfg->StopBitsCount, TRUE);
2492 }
2493 
2494 /*FUNCTION**********************************************************************
2495  *
2496  * Function Name : Linflexd_Uart_Ip_SyncSendData
2497  * Description   : Sync data sending process for Linflexd Uart.
2498  *
2499  *END**************************************************************************/
Linflexd_Uart_Ip_SyncSendData(const uint8 Instance,const uint32 Timeout)2500 static void Linflexd_Uart_Ip_SyncSendData(const uint8 Instance, const uint32 Timeout)
2501 {
2502     /* Check the validity of the parameters */
2503     LINFLEXD_UART_IP_DEV_ASSERT(Instance < LINFLEXD_IP_INSTANCE_COUNT);
2504 
2505     Linflexd_Uart_Ip_StateStructureType * UartState;
2506     LINFLEXD_Type * Base;
2507     uint32 StartTime;
2508     uint32 TimeoutTicks;
2509     uint32 ElapsedTicks = 0;
2510 
2511     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
2512     Base = Linflexd_Uart_Ip_apBases[Instance];
2513 
2514     LINFLEXD_UART_IP_DEV_ASSERT(UartState != NULL_PTR);
2515 
2516     Linflexd_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, Timeout, LINFLEXD_UART_IP_TIMEOUT_TYPE);
2517 
2518     while ((UartState->TxSize > 0U) && !Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE))
2519     {
2520         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
2521         Linflexd_Uart_Ip_PutData(Instance);
2522         /* Wait until data transmited flag is set or timeout occurs if there is an error during transmission */
2523         while (!Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG) && \
2524                !Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE) \
2525               )
2526         {}
2527     }
2528     Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_DATA_TRANSMITTED_FLAG);
2529 
2530     /* Check if Timeout occur */
2531     if (UartState->TxSize > 0U)
2532     {
2533         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_TIMEOUT;
2534     }
2535     else /* The transmit process is complete */
2536     {
2537         UartState->TransmitStatus = LINFLEXD_UART_IP_STATUS_SUCCESS;
2538     }
2539 }
2540 
2541 /*FUNCTION**********************************************************************
2542  *
2543  * Function Name : Linflexd_Uart_Ip_SetUp_EnterInitMode
2544  * Description   : Set up enter init mode for Linflexd Uart.
2545  *
2546  *END**************************************************************************/
Linflexd_Uart_Ip_SetUp_EnterInitMode(LINFLEXD_Type * Base)2547 static boolean Linflexd_Uart_Ip_SetUp_EnterInitMode(LINFLEXD_Type *Base)
2548 {
2549     uint32 StartTime;
2550     uint32 TimeoutTicks;
2551     uint32 ElapsedTicks = 0;
2552     boolean RetVal = FALSE;
2553 
2554     /* Request init mode and wait until the mode entry is complete */
2555     Linflexd_Uart_Ip_EnterInitMode(Base);
2556 
2557     Linflexd_Uart_Ip_StartTimeout(&StartTime, &TimeoutTicks, (uint32)LINFLEXD_UART_IP_TIMEOUT_VALUE_US, LINFLEXD_UART_IP_TIMEOUT_TYPE);
2558 
2559     while (!Linflexd_Uart_Ip_CheckTimeout(&StartTime, &ElapsedTicks, TimeoutTicks, LINFLEXD_UART_IP_TIMEOUT_TYPE) &&
2560           (Linflexd_Uart_Ip_GetLinState(Base) != LINFLEXD_STATE_INIT_MODE)
2561     )
2562     {}
2563 
2564     if (LINFLEXD_STATE_INIT_MODE == Linflexd_Uart_Ip_GetLinState(Base))
2565     {
2566         RetVal = TRUE;
2567     }
2568     return RetVal;
2569 }
2570 
2571 /*FUNCTION**********************************************************************
2572  *
2573  * Function Name : Linflexd_Uart_Ip_CompleteAsyncReceiveData
2574  * Description   : Aync data receiving process for Linflexd Uart.
2575  *
2576  *END**************************************************************************/
Linflexd_Uart_Ip_CompleteAsyncReceiveData(const uint8 Instance)2577 static void Linflexd_Uart_Ip_CompleteAsyncReceiveData(const uint8 Instance)
2578 {
2579     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2580 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
2581     const Linflexd_Uart_Ip_StateStructureType * UartState;
2582 
2583     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
2584 #endif
2585     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2586 
2587     if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
2588     {
2589         Linflexd_Uart_Ip_CompleteReceiveUsingInterrupts(Instance);
2590     }
2591 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
2592     else
2593     {
2594         /* Release the DMA channel */
2595         (void)Dma_Ip_SetLogicChannelCommand(UartUserCfg->RxDMAChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
2596         Linflexd_Uart_Ip_CompleteReceiveUsingDma(Instance);
2597     }
2598 #endif
2599 
2600     /* Invoke the callback, if any */
2601 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
2602     if (LINFLEXD_UART_IP_STATUS_RX_IDLE_STATE == UartState->ReceiveStatus)
2603     {
2604         Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_IDLE_STATE);
2605     }
2606     else
2607     {
2608 #endif
2609         Linflexd_Uart_Ip_Callback(Instance, LINFLEXD_UART_IP_EVENT_ERROR);
2610 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
2611     }
2612 #endif
2613 }
2614 
2615 /*FUNCTION**********************************************************************
2616  *
2617  * Function Name : Linflexd_Uart_Ip_UpdateErrorIRQHandler
2618  * Description   : Update the receive status according to the error occurred for Linflexd Uart.
2619  *
2620  *END**************************************************************************/
Linflexd_Uart_Ip_UpdateErrorIRQHandler(const uint8 Instance)2621 static void Linflexd_Uart_Ip_UpdateErrorIRQHandler(const uint8 Instance)
2622 {
2623     Linflexd_Uart_Ip_StateStructureType * UartState;
2624     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2625     LINFLEXD_Type * Base;
2626 
2627     Base = Linflexd_Uart_Ip_apBases[Instance];
2628     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2629     UartState = (Linflexd_Uart_Ip_StateStructureType *)Linflexd_Uart_Ip_apStateStructuresArray[Instance];
2630 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
2631     uint16 WordLengthValue = Linflexd_Uart_Ip_GetActualWordLengthValue(Instance);
2632 #endif
2633 
2634     if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG))
2635     {
2636         /* Update the status */
2637         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_RX_OVERRUN;
2638         /* The read dummy data not apply for DMA
2639             because reading the BDRM register in this mode IPS operation result will returns IPS transfer error status*/
2640         if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
2641         {
2642             /* Read dummy to take the byte that caused the overrun error and shifts it to the buffer */
2643             Linflexd_Uart_Ip_GetData(Instance);
2644         }
2645         /* Clear the flag */
2646         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_BUFFER_OVERRUN_FLAG);
2647     }
2648     else if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG))
2649     {
2650         /* Update the status */
2651         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_FRAMING_ERROR;
2652         /* The read dummy data not apply for DMA
2653            because reading the BDRM register in this mode IPS operation result will returns IPS transfer error status*/
2654         if (LINFLEXD_UART_IP_USING_INTERRUPTS == UartUserCfg->TransferType)
2655         {
2656             /* Read dummy to take the byte that caused the framing error and shifts it to the buffer */
2657             Linflexd_Uart_Ip_GetData(Instance);
2658         }
2659         /* Clear the flag */
2660         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_FRAME_ERROR_FLAG);
2661     }
2662 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
2663     else if (Linflexd_Uart_Ip_GetStatusFlag(Base, LINFLEXD_UART_TIMEOUT_INTERRUPT_FLAG))
2664     {
2665         /* Disable the receiver to stop timer counter */
2666         Linflexd_Uart_Ip_SetReceiverState(Base, FALSE);
2667         /* Update the status */
2668         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_RX_IDLE_STATE;
2669         /* Clear Timeout Interrupt Error flag */
2670         Linflexd_Uart_Ip_ClearStatusFlag(Base, LINFLEXD_UART_TIMEOUT_INTERRUPT_FLAG);
2671         /* Reset the value of the PTO to default by the number of bits in a word + 2U (stop and start bit) */
2672         Linflexd_Uart_Ip_SetPresetValue(Base, WordLengthValue + 2U);
2673     }
2674 #endif
2675     else
2676     {
2677         /* This branch should never be reached - avoid MISRA violations */
2678         UartState->ReceiveStatus = LINFLEXD_UART_IP_STATUS_ERROR;
2679     }
2680 }
2681 
2682 /*FUNCTION**********************************************************************
2683  *
2684  * Function Name : Linflexd_Uart_Ip_Callback
2685  * Description   : Enter callback function for Linflexd Uart.
2686  *
2687  *END**************************************************************************/
Linflexd_Uart_Ip_Callback(const uint8 Instance,const Linflexd_Uart_Ip_EventType Event)2688 static void Linflexd_Uart_Ip_Callback(const uint8 Instance, const Linflexd_Uart_Ip_EventType Event)
2689 {
2690     const Linflexd_Uart_Ip_UserConfigType * UartUserCfg;
2691 
2692     UartUserCfg = Linflexd_Uart_Ip_apUserConfig[Instance];
2693 
2694     if (UartUserCfg->Callback != NULL_PTR)
2695     {
2696         UartUserCfg->Callback(Instance, Event, UartUserCfg->CallbackParam);
2697     }
2698 }
2699 #define UART_STOP_SEC_CODE
2700 #include "Uart_MemMap.h"
2701 
2702 #ifdef __cplusplus
2703 }
2704 #endif
2705 
2706 /** @} */
2707