1 /*
2 * Copyright 2021-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7
8 #ifndef LINFLEXD_HWACCESS_H
9 #define LINFLEXD_HWACCESS_H
10
11 /**
12 * @file
13 * @internal
14 * @defgroup linflexd_ip Linflexd IPL
15 * @addtogroup linflexd_ip Linflexd IPL
16 * @{
17 */
18
19 #ifdef __cplusplus
20 extern "C"{
21 #endif
22
23 /*==================================================================================================
24 * INCLUDE FILES
25 * 1) system and project includes
26 * 2) needed interfaces from external units
27 * 3) internal and external interfaces from this unit
28 ==================================================================================================*/
29 #include "StandardTypes.h"
30 #include "OsIf.h"
31 #include "Linflexd_Uart_Ip_Defines.h"
32 #include "SchM_Uart.h"
33 /*==================================================================================================
34 * SOURCE FILE VERSION INFORMATION
35 ==================================================================================================*/
36 #define LINFLEXD_UART_IP_HWACCESS_VENDOR_ID 43
37 #define LINFLEXD_UART_IP_HWACCESS_MODULE_ID 255
38 #define LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION 4
39 #define LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION 7
40 #define LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION 0
41 #define LINFLEXD_UART_IP_HWACCESS_SW_MAJOR_VERSION 1
42 #define LINFLEXD_UART_IP_HWACCESS_SW_MINOR_VERSION 0
43 #define LINFLEXD_UART_IP_HWACCESS_SW_PATCH_VERSION 0
44
45 /*==================================================================================================
46 * FILE VERSION CHECKS
47 ==================================================================================================*/
48 /* Checks against Linflexd_Uart_Ip_Defines.h */
49 #if (LINFLEXD_UART_IP_HWACCESS_VENDOR_ID != LINFLEXD_UART_IP_DEFINES_VENDOR_ID)
50 #error "Linflexd_Uart_Ip_HwAccess.h and Linflexd_Uart_Ip_Defines.h have different vendor ids"
51 #endif
52 #if ((LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != LINFLEXD_UART_IP_DEFINES_AR_RELEASE_MAJOR_VERSION) || \
53 (LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != LINFLEXD_UART_IP_DEFINES_AR_RELEASE_MINOR_VERSION) || \
54 (LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION != LINFLEXD_UART_IP_DEFINES_AR_RELEASE_REVISION_VERSION) \
55 )
56 #error "AUTOSAR Version Numbers of Linflexd_Uart_Ip_HwAccess.h and Linflexd_Uart_Ip_Defines.h are different"
57 #endif
58 #if ((LINFLEXD_UART_IP_HWACCESS_SW_MAJOR_VERSION != LINFLEXD_UART_IP_DEFINES_SW_MAJOR_VERSION) || \
59 (LINFLEXD_UART_IP_HWACCESS_SW_MINOR_VERSION != LINFLEXD_UART_IP_DEFINES_SW_MINOR_VERSION) || \
60 (LINFLEXD_UART_IP_HWACCESS_SW_PATCH_VERSION != LINFLEXD_UART_IP_DEFINES_SW_PATCH_VERSION) \
61 )
62 #error "Software Version Numbers of Linflexd_Uart_Ip_HwAccess.h and Linflexd_Uart_Ip_Defines.h are different"
63 #endif
64
65 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
66 /* Check if current file and StandardTypes.h header file are of the same Autosar version */
67 #if ((LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
68 (LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION) \
69 )
70 #error "Linflexd_Uart_Ip_HwAccess.h and StandardTypes.h are different"
71 #endif
72
73 /* Check if current file and OsIf.h header file are of the same Autosar version */
74 #if ((LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != OSIF_AR_RELEASE_MAJOR_VERSION) || \
75 (LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != OSIF_AR_RELEASE_MINOR_VERSION) \
76 )
77 #error "Linflexd_Uart_Ip_HwAccess.h and OsIf.h are different"
78 #endif
79
80 /* Check if current file and SchM_Uart.h header file are of the same Autosar version */
81 #if ((LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION != SCHM_UART_AR_RELEASE_MAJOR_VERSION) || \
82 (LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION != SCHM_UART_AR_RELEASE_MINOR_VERSION) \
83 )
84 #error "Linflexd_Uart_Ip_HwAccess.h and SchM_Uart.h are different"
85 #endif
86 #endif
87
88
89 /*==================================================================================================
90 * CONSTANTS
91 ==================================================================================================*/
92
93 /*==================================================================================================
94 * DEFINES AND MACROS
95 ==================================================================================================*/
96 #define DEFAULT_OSR 16U
97
98 #define LINFLEXD_BAUDRATE_FRACTION_WIDTH LINFLEXD_LINFBRR_FBR_WIDTH
99
100 #ifdef CPU_BYTE_ORDER
101 #if (LOW_BYTE_FIRST == CPU_BYTE_ORDER)
102 #define CORE_LITTLE_ENDIAN
103 #endif
104 #endif
105
106 #ifdef CORE_LITTLE_ENDIAN
107 #define SWAP_BYTES_UINT16(x) ((((x) >> 8U) & 0xFFU) | (((x) << 8U) & 0xFF00U))
108 #endif
109 /*==================================================================================================
110 * ENUMS
111 ==================================================================================================*/
112 /**
113 * @internal
114 *@brief Word length in UART mode.
115 *
116 *implements Linflexd_Uart_Ip_WordLengthType_enum
117 */
118 typedef enum
119 {
120 LINFLEXD_UART_IP_7_BITS = 0U,
121 LINFLEXD_UART_IP_8_BITS = 1U,
122 LINFLEXD_UART_IP_15_BITS = 2U,
123 LINFLEXD_UART_IP_16_BITS = 3U
124 } Linflexd_Uart_Ip_WordLengthType;
125
126 /**
127 * @internal
128 * @brief Number of stop bits.
129 *
130 *
131 */
132 typedef enum
133 {
134 LINFLEXD_UART_IP_ONE_STOP_BIT = 0U,
135 LINFLEXD_UART_IP_TWO_STOP_BIT = 1U
136 } Linflexd_Uart_Ip_StopBitsCountType;
137
138 /**
139 * @internal
140 * @brief Parity type.
141 *
142 *implements Linflexd_Uart_Ip_ParityType_enum
143 */
144 typedef enum
145 {
146 LINFLEXD_UART_IP_PARITY_EVEN = 0U,
147 LINFLEXD_UART_IP_PARITY_ODD = 1U,
148 LINFLEXD_UART_IP_PARITY_ZERO = 2U,
149 LINFLEXD_UART_IP_PARITY_ONE = 3U
150 } Linflexd_Uart_Ip_ParityType;
151
152
153 /**
154 * * @internal
155 * @brief LINFLEXD mode: UART/LIN.
156
157 */
158 typedef enum
159 {
160 LINFLEXD_LIN_MODE = 0U,
161 LINFLEXD_UART_MODE = 1U
162 } Linflexd_Uart_Ip_ModeType;
163
164
165 /**
166 * @internal
167 * @brief UART Mode: FIFO/BUFFER.
168 */
169 typedef enum
170 {
171 LINFLEXD_UART_RXTX_BUFFER_MODE = 0U,
172 LINFLEXD_UART_RXTX_FIFO_MODE = 1U
173 } Linflexd_Uart_Ip_RxTxModeType;
174
175 /**
176 * @internal
177 * @brief LINFLEXD state.
178 */
179 typedef enum
180 {
181 LINFLEXD_STATE_SLEEP_MODE = 0U,
182 LINFLEXD_STATE_INIT_MODE = 1U,
183 LINFLEXD_STATE_IDLE_MODE = 2U,
184 LINFLEXD_STATE_DATA_RX_TX = 8U
185 } Linflexd_Uart_Ip_StateType;
186
187 /**
188 * @internal
189 * @brief UART Status flags.
190 * @details These identifiers provide both mask and shift for status bits in UARTSR register.
191 */
192 typedef enum
193 {
194 LINFLEXD_UART_NOISE_FLAG = LINFLEXD_UARTSR_NF_MASK,
195 LINFLEXD_UART_DATA_TRANSMITTED_FLAG = LINFLEXD_UARTSR_DTFTFF_MASK,
196 LINFLEXD_UART_DATA_RECEPTION_COMPLETE_FLAG = LINFLEXD_UARTSR_DRFRFE_MASK,
197 LINFLEXD_UART_WAKEUP_FLAG = LINFLEXD_UARTSR_WUF_MASK,
198 LINFLEXD_UART_BUFFER_OVERRUN_FLAG = LINFLEXD_UARTSR_BOF_MASK,
199 LINFLEXD_UART_FRAME_ERROR_FLAG = LINFLEXD_UARTSR_FEF_MASK,
200 LINFLEXD_UART_MESSAGE_BUFFER_FULL_FLAG = LINFLEXD_UARTSR_RMB_MASK,
201 LINFLEXD_UART_PARITY_ERROR_FLAG = LINFLEXD_UARTSR_PE_MASK,
202 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
203 LINFLEXD_UART_TIMEOUT_INTERRUPT_FLAG = LINFLEXD_UARTSR_TO_MASK
204 #endif
205 } Linflexd_Uart_Ip_StatusFlagType;
206
207 /**
208 * @internal
209 * @brief LINFLEXD interrupts.
210 * @details These identifiers provide both mask and shift for the interrupt enable bits in LINIER register.
211 */
212 typedef enum
213 {
214 LINFLEXD_DATA_TRANSMITTED_INT = LINFLEXD_LINIER_DTIE_MASK,
215 LINFLEXD_DATA_RECEPTION_COMPLETE_INT = LINFLEXD_LINIER_DRIE_MASK,
216 LINFLEXD_BUFFER_OVERRUN_INT = LINFLEXD_LINIER_BOIE_MASK,
217 LINFLEXD_FRAME_ERROR_INT = LINFLEXD_LINIER_FEIE_MASK,
218 LINFLEXD_WAKEUP_INT = LINFLEXD_LINIER_WUIE_MASK,
219 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
220 LINFLEXD_TIMEOUT_INT = LINFLEXD_LINIER_TOIE_MASK
221 #endif
222 } Linflexd_Uart_Ip_InterruptType;
223
224 /*==================================================================================================
225 * STRUCTURES AND OTHER TYPEDEFS
226 ==================================================================================================*/
227
228 /*==================================================================================================
229 * GLOBAL VARIABLE DECLARATIONS
230 ==================================================================================================*/
231
232 /*==================================================================================================
233 * FUNCTION PROTOTYPES
234 ==================================================================================================*/
235 #define UART_START_SEC_CODE
236 #include "Uart_MemMap.h"
237
238 /**
239 * @internal
240 * @brief Requests LINFLEXD module to enter init mode.
241 *
242 * This function enters initialization mode.
243 *
244 * @param Base LINFLEXD Base pointer.
245 */
Linflexd_Uart_Ip_EnterInitMode(LINFLEXD_Type * Base)246 static inline void Linflexd_Uart_Ip_EnterInitMode(LINFLEXD_Type *Base)
247 {
248 uint32 RegValTemp;
249
250 RegValTemp = Base->LINCR1;
251 RegValTemp &= ~(LINFLEXD_LINCR1_SLEEP_MASK);
252 RegValTemp |= LINFLEXD_LINCR1_INIT(1UL);
253 Base->LINCR1 = RegValTemp;
254 }
255
256 /**
257 * @internal
258 * @brief Requests LINFLEXD module to enter normal mode.
259 *
260 * This function enters normal mode. *
261 *
262 * @param Base LINFLEXD Base pointer.
263 */
Linflexd_Uart_Ip_EnterNormalMode(LINFLEXD_Type * Base)264 static inline void Linflexd_Uart_Ip_EnterNormalMode(LINFLEXD_Type *Base)
265 {
266 uint32 RegValTemp;
267
268 RegValTemp = Base->LINCR1;
269 RegValTemp &= ~(LINFLEXD_LINCR1_SLEEP_MASK);
270 RegValTemp &= ~(LINFLEXD_LINCR1_INIT_MASK);
271 Base->LINCR1 = RegValTemp;
272 }
273
274 /**
275 * @internal
276 * @brief Sets the LINFLEXD mode.
277 *
278 * This function sets LIN or UART mode, Based on the parameter received.
279 *
280 * @param Base LINFLEXD Base pointer.
281 * @param mode LINFLEXD mode - UART/LIN.
282 */
Linflexd_Uart_Ip_SetMode(LINFLEXD_Type * Base,Linflexd_Uart_Ip_ModeType Mode)283 static inline void Linflexd_Uart_Ip_SetMode(LINFLEXD_Type *Base, Linflexd_Uart_Ip_ModeType Mode)
284 {
285 uint32 RegValTemp;
286
287 RegValTemp = Base->UARTCR;
288 RegValTemp &= ~(LINFLEXD_UARTCR_UART_MASK);
289 RegValTemp |= LINFLEXD_UARTCR_UART((uint32)Mode);
290 Base->UARTCR = RegValTemp;
291 }
292
293 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
294 /**
295 * @internal
296 * @brief Enable Monitor Idle State for UART module
297 *
298 * This function to enable monitor idle state of the reception line.
299 *
300 * @param Base LINFLEXD Base pointer.
301 * @param mode Enable enable/disable monitor idle state of the reception line.
302 */
Linflexd_Uart_Ip_EnableMonitorIdleState(LINFLEXD_Type * Base,boolean Enable)303 static inline void Linflexd_Uart_Ip_EnableMonitorIdleState(LINFLEXD_Type *Base, boolean Enable)
304 {
305 Base->UARTCR |= LINFLEXD_UARTCR_MIS(Enable);
306 }
307 #endif
308
309 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
310 /**
311 * @internal
312 * @brief Enable Timer Reset for UART module Disable Timeout in UART mode
313 * Note: Disable Timeout causes only the Timer to restart which enables Timeout again.
314 * Timer reset means it resets and starts counting again and the Timeout is enabled.
315 *
316 * @param Base LINFLEXD Base pointer.
317 * @param Enable enable/disable timeout in UART mode.
318 */
Linflexd_Uart_Ip_EnableTimerReset(LINFLEXD_Type * Base,boolean Enable)319 static inline void Linflexd_Uart_Ip_EnableTimerReset(LINFLEXD_Type *Base, boolean Enable)
320 {
321 Base->UARTCR |= LINFLEXD_UARTCR_DTU_PCETX(Enable);
322 }
323 #endif
324
325 /**
326 * @internal
327 * @brief Returns the current LINFLEXD state.
328 *
329 * This function returns the state of the LINFLEXD instance. The possible states are:
330 * - Sleep mode
331 * - Init mode
332 * - Idle mode
333 * - Sync Break Reception/Transmission
334 * - Sync Delimiter Reception/Transmission
335 * - Sync Field Reception/Transmission
336 * - Identifier Field Reception/Transmission
337 * - Header Reception/Transmission
338 * - Data Reception/Transmission
339 * - Checksum Reception/Transmission
340 *
341 * @param Base LINFLEXD Base pointer.
342 * @return LINFLEXD mode - UART/LIN.
343 */
Linflexd_Uart_Ip_GetLinState(const LINFLEXD_Type * Base)344 static inline Linflexd_Uart_Ip_StateType Linflexd_Uart_Ip_GetLinState(const LINFLEXD_Type * Base)
345 {
346 uint8 State = (uint8)((Base->LINSR & LINFLEXD_LINSR_LINS_MASK) >> LINFLEXD_LINSR_LINS_SHIFT);
347 return (Linflexd_Uart_Ip_StateType)State;
348 }
349
350 /**
351 * @internal
352 * @brief Sets the word length.
353 *
354 * This function sets the word length in UART mode.
355 * Should be called only when the module is in init mode.
356 *
357 * @param Base LINFLEXD Base pointer.
358 * @param Length UART mode word length.
359 */
Linflexd_Uart_Ip_SetUartWordLength(LINFLEXD_Type * Base,Linflexd_Uart_Ip_WordLengthType Length)360 static inline void Linflexd_Uart_Ip_SetUartWordLength(LINFLEXD_Type *Base, Linflexd_Uart_Ip_WordLengthType Length)
361 {
362 uint32 RegValTemp;
363
364 RegValTemp = Base->UARTCR;
365 RegValTemp &= ~(LINFLEXD_UARTCR_WL0_MASK);
366 RegValTemp |= LINFLEXD_UARTCR_WL0((uint32)Length & 1U);
367 RegValTemp &= ~(LINFLEXD_UARTCR_WL1_MASK);
368 RegValTemp |= LINFLEXD_UARTCR_WL1(((uint32)Length >> 1U) & 1U);
369 Base->UARTCR = RegValTemp;
370 }
371
372 /**
373 * @internal
374 * @brief Enables/disables parity bit.
375 *
376 * This function enables or disables the parity bit from UART bytes.
377 * Should be called only when the module is in init mode.
378 *
379 * @param Base LINFLEXD Base pointer.
380 * @param enable true - enable parity queuing/checking, false - disable parity queuing/checking.
381 */
Linflexd_Uart_Ip_SetParityControl(LINFLEXD_Type * Base,boolean Enable)382 static inline void Linflexd_Uart_Ip_SetParityControl(LINFLEXD_Type *Base, boolean Enable)
383 {
384 uint32 RegValTemp;
385
386 RegValTemp = Base->UARTCR;
387 RegValTemp &= ~(LINFLEXD_UARTCR_PCE_MASK);
388 RegValTemp |= LINFLEXD_UARTCR_PCE(Enable ? 1UL : 0UL);
389 Base->UARTCR = RegValTemp;
390 }
391
392 /**
393 * @internal
394 * @brief Sets parity type.
395 *
396 * This function sets the type of parity to be used for UART bytes. Available options are:
397 * - odd
398 * - even
399 * - always 0
400 * - always 1
401 * Should be called only when the module is in init mode.
402 *
403 * @param Base LINFLEXD Base pointer.
404 * @param ParityType the type of parity.
405 */
Linflexd_Uart_Ip_SetParityType(LINFLEXD_Type * Base,Linflexd_Uart_Ip_ParityType ParityType)406 static inline void Linflexd_Uart_Ip_SetParityType(LINFLEXD_Type *Base, Linflexd_Uart_Ip_ParityType ParityType)
407 {
408 uint32 RegValTemp;
409
410 RegValTemp = Base->UARTCR;
411 RegValTemp &= ~(LINFLEXD_UARTCR_PC0_MASK);
412 RegValTemp |= LINFLEXD_UARTCR_PC0((uint32)ParityType & 1U);
413 RegValTemp &= ~(LINFLEXD_UARTCR_PC1_MASK);
414 RegValTemp |= LINFLEXD_UARTCR_PC1(((uint32)ParityType >> 1U) & 1U);
415 Base->UARTCR = RegValTemp;
416 }
417
418 /**
419 * @internal
420 * @brief Sets the transmission mode (FIFO/Buffer).
421 *
422 * This function sets the transmission mode (FIFO/Buffer).
423 * Should be called only when the module is in init mode.
424 *
425 * @param Base LINFLEXD Base pointer.
426 * @param mode tx mode: FIFO/Buffer.
427 */
Linflexd_Uart_Ip_SetTxMode(LINFLEXD_Type * Base,Linflexd_Uart_Ip_RxTxModeType Mode)428 static inline void Linflexd_Uart_Ip_SetTxMode(LINFLEXD_Type *Base, Linflexd_Uart_Ip_RxTxModeType Mode)
429 {
430 uint32 RegValTemp;
431
432 RegValTemp = Base->UARTCR;
433 RegValTemp &= ~(LINFLEXD_UARTCR_TFBM_MASK);
434 RegValTemp |= LINFLEXD_UARTCR_TFBM((uint32)Mode);
435 Base->UARTCR = RegValTemp;
436 }
437
438 /**
439 * @internal
440 * @brief Sets the reception mode (FIFO/Buffer).
441 *
442 * This function sets the reception mode (FIFO/Buffer).
443 * Should be called only when the module is in init mode.
444 *
445 * @param Base LINFLEXD Base pointer.
446 * @param mode rx mode: FIFO/Buffer.
447 */
Linflexd_Uart_Ip_SetRxMode(LINFLEXD_Type * Base,Linflexd_Uart_Ip_RxTxModeType Mode)448 static inline void Linflexd_Uart_Ip_SetRxMode(LINFLEXD_Type *Base, Linflexd_Uart_Ip_RxTxModeType Mode)
449 {
450 uint32 RegValTemp;
451
452 RegValTemp = Base->UARTCR;
453 RegValTemp &= ~(LINFLEXD_UARTCR_RFBM_MASK);
454 RegValTemp |= LINFLEXD_UARTCR_RFBM((uint32)Mode);
455 Base->UARTCR = RegValTemp;
456 }
457
458 /**
459 * @internal
460 * @brief Sets the reception data field length/FIFO depth.
461 *
462 * This function sets either the reception data field length or the number of bytes in the Rx FIFO, according to
463 * the current reception mode.
464 *
465 * @param Base LINFLEXD Base pointer.
466 * @param Length data field length/FIFO depth.
467 */
Linflexd_Uart_Ip_SetRxDataFieldLength(LINFLEXD_Type * Base,uint8 Length)468 static inline void Linflexd_Uart_Ip_SetRxDataFieldLength(LINFLEXD_Type *Base, uint8 Length)
469 {
470 uint32 RegValTemp;
471
472 RegValTemp = Base->UARTCR;
473 RegValTemp &= ~(LINFLEXD_UARTCR_RDFL_RFC_MASK);
474 RegValTemp |= LINFLEXD_UARTCR_RDFL_RFC(Length);
475 Base->UARTCR = RegValTemp;
476 }
477
478 /**
479 * @internal
480 * @brief Sets the transmission data field length/FIFO depth.
481 *
482 * This function sets either the transmission data field length or the number of bytes in the Tx FIFO, according to
483 * the current transmission mode.
484 * Should be called only when the module is in init mode.
485 *
486 * @param Base LINFLEXD Base pointer.
487 * @param Length data field length/FIFO depth.
488 */
Linflexd_Uart_Ip_SetTxDataFieldLength(LINFLEXD_Type * Base,uint8 Length)489 static inline void Linflexd_Uart_Ip_SetTxDataFieldLength(LINFLEXD_Type *Base, uint8 Length)
490 {
491 uint32 RegValTemp;
492
493 RegValTemp = Base->UARTCR;
494 RegValTemp &= ~(LINFLEXD_UARTCR_TDFL_TFC_MASK);
495 RegValTemp |= LINFLEXD_UARTCR_TDFL_TFC(Length);
496 Base->UARTCR = RegValTemp;
497 }
498
499 /**
500 * @internal
501 * @brief Sets the number of stop bits for Rx.
502 *
503 * This function sets the number of stop bits for received bytes.
504 *
505 * @param Base LINFLEXD Base pointer.
506 * @param StopBitsCount number of stop bits.
507 */
Linflexd_Uart_Ip_SetRxStopBitsCount(LINFLEXD_Type * Base,Linflexd_Uart_Ip_StopBitsCountType StopBitsCount)508 static inline void Linflexd_Uart_Ip_SetRxStopBitsCount(LINFLEXD_Type *Base, Linflexd_Uart_Ip_StopBitsCountType StopBitsCount)
509 {
510 uint32 RegValTemp;
511 RegValTemp = Base->UARTCR;
512 RegValTemp &= ~(LINFLEXD_UARTCR_SBUR_MASK);
513 RegValTemp |= LINFLEXD_UARTCR_SBUR(StopBitsCount);
514 Base->UARTCR = RegValTemp;
515 }
516
517 /**
518 * @internal
519 * @brief Sets fractional baud rate.
520 *
521 * This function configures the bits that decide the fractional part of the LIN Baud Rate.
522 * Should be called only when the module is in init mode.
523 *
524 * @param Base LINFLEXD Base pointer.
525 * @param Fbr fractional baud rate.
526 */
Linflexd_Uart_Ip_SetFractionalBaudRate(LINFLEXD_Type * Base,uint8 Fbr)527 static inline void Linflexd_Uart_Ip_SetFractionalBaudRate(LINFLEXD_Type *Base, uint8 Fbr)
528 {
529 Base->LINFBRR = LINFLEXD_LINFBRR_FBR(Fbr);
530 }
531
532 /**
533 * @internal
534 * @brief Sets integer baud rate.
535 *
536 * This function configures the bits that decide the integer part of the LIN Baud Rate.
537 * Should be called only when the module is in init mode.
538 *
539 * @param Base LINFLEXD Base pointer.
540 * @param Ibr integer baud rate.
541 */
Linflexd_Uart_Ip_SetIntegerBaudRate(LINFLEXD_Type * Base,uint32 Ibr)542 static inline void Linflexd_Uart_Ip_SetIntegerBaudRate(LINFLEXD_Type *Base, uint32 Ibr)
543 {
544 Base->LINIBRR = LINFLEXD_LINIBRR_IBR(Ibr);
545 }
546
547 /**
548 * @internal
549 * @brief Sets the number of stop bits for Tx.
550 *
551 * This function sets the number of stop bits for transmitted bytes.
552 * Should be called only when the module is in init mode.
553 *
554 * @param Base LINFLEXD Base pointer.
555 * @param DefaultOffset - true - use the memory map defined in the header file to access the register;
556 * - false - use custom memory map to access the register.
557 * @param StopBitsCount number of stop bits.
558 */
Linflexd_Uart_Ip_SetTxStopBitsCount(LINFLEXD_Type * Base,Linflexd_Uart_Ip_StopBitsCountType StopBitsCount,boolean DefaultOffset)559 static inline void Linflexd_Uart_Ip_SetTxStopBitsCount(LINFLEXD_Type *Base, Linflexd_Uart_Ip_StopBitsCountType StopBitsCount, boolean DefaultOffset)
560 {
561 uint32 RegValTemp;
562
563 #if defined(FEATURE_LINFLEXD_HAS_DIFFERENT_MEM_MAP)
564 if (!DefaultOffset)
565 {
566 RegValTemp = ((LINFLEXD_0IFCR_Type *)Base)->GCR;
567 RegValTemp &= ~(LINFLEXD_GCR_STOP_MASK);
568 RegValTemp |= LINFLEXD_GCR_STOP(StopBitsCount);
569 ((LINFLEXD_0IFCR_Type *)Base)->GCR = RegValTemp;
570 }
571 else
572 {
573 RegValTemp = Base->GCR;
574 RegValTemp &= ~(LINFLEXD_GCR_STOP_MASK);
575 RegValTemp |= LINFLEXD_GCR_STOP(StopBitsCount);
576 Base->GCR = RegValTemp;
577 }
578 #else
579 (void)DefaultOffset;
580 RegValTemp = Base->GCR;
581 RegValTemp &= ~(LINFLEXD_GCR_STOP_MASK);
582 RegValTemp |= LINFLEXD_GCR_STOP(StopBitsCount);
583 Base->GCR = RegValTemp;
584 #endif
585 }
586
587 /**
588 * @internal
589 * @brief Clears an UART interrupt flag.
590 *
591 * This function clears the UART status flag received as parameter.
592 *
593 * @param Base LINFLEXD Base pointer.
594 * @param Flag UART status flag.
595 */
Linflexd_Uart_Ip_ClearStatusFlag(LINFLEXD_Type * Base,Linflexd_Uart_Ip_StatusFlagType Flag)596 static inline void Linflexd_Uart_Ip_ClearStatusFlag(LINFLEXD_Type * Base, Linflexd_Uart_Ip_StatusFlagType Flag)
597 {
598 Base->UARTSR = (uint32)Flag;
599 }
600
601 /**
602 * @internal
603 * @brief Returns an UART interrupt flag.
604 *
605 * This function returns the value of the UART status flag received as parameter.
606 *
607 * @param Base LINFLEXD Base pointer.
608 * @return true - UART status flag set, false - UART status flag reset.
609 */
Linflexd_Uart_Ip_GetStatusFlag(const LINFLEXD_Type * Base,Linflexd_Uart_Ip_StatusFlagType Flag)610 static inline boolean Linflexd_Uart_Ip_GetStatusFlag(const LINFLEXD_Type * Base, Linflexd_Uart_Ip_StatusFlagType Flag)
611 {
612 return ((Base->UARTSR & (uint32)Flag) != 0U);
613 }
614
615 #if defined (LINFLEXD_UART_IP_ORED_INT_LINES)
616 /**
617 * @internal
618 * @brief Returns the state of an UART interrupt.
619 *
620 * This function returns whether the UART Event will trigger an interrupt.
621 *
622 * @param Base LINFLEXD Base pointer.
623 * @param IntSrc UART interrupt source.
624 * @return true - interrupt enabled, false - interrupt disabled.
625 */
Linflexd_Uart_Ip_IsInterruptEnabled(const LINFLEXD_Type * Base,Linflexd_Uart_Ip_InterruptType IntSrc)626 static inline boolean Linflexd_Uart_Ip_IsInterruptEnabled(const LINFLEXD_Type * Base, Linflexd_Uart_Ip_InterruptType IntSrc)
627 {
628 return ((Base->LINIER & (uint32)IntSrc) != 0U);
629 }
630 #endif
631
632 /**
633 * @internal
634 * @brief Sets the first byte of the tx data buffer.
635 *
636 * This function writes one byte to the tx data buffer.
637 *
638 * @param Base LINFLEXD Base pointer.
639 * @param Data data byte.
640 */
Linflexd_Uart_Ip_SetTxDataBuffer1Byte(LINFLEXD_Type * Base,uint8 Data)641 static inline void Linflexd_Uart_Ip_SetTxDataBuffer1Byte(LINFLEXD_Type * Base, uint8 Data)
642 {
643 Base->BDRL = LINFLEXD_BDRL_DATA0(Data);
644 }
645
646 /**
647 * @internal
648 * @brief Sets the first half-word of the tx data buffer.
649 *
650 * This function writes two bytes to the tx data buffer.
651 *
652 * @param Base LINFLEXD Base pointer.
653 * @param Data data half-word.
654 */
Linflexd_Uart_Ip_SetTxDataBuffer2Bytes(LINFLEXD_Type * Base,uint16 Data)655 static inline void Linflexd_Uart_Ip_SetTxDataBuffer2Bytes(LINFLEXD_Type * Base, uint16 Data)
656 {
657 uint32 Mask;
658 uint16 DataTemp;
659 #ifdef CORE_LITTLE_ENDIAN
660 DataTemp = SWAP_BYTES_UINT16(Data);
661 #else
662 DataTemp = Data;
663 #endif
664 Mask = LINFLEXD_BDRL_DATA0_MASK | LINFLEXD_BDRL_DATA1_MASK;
665 Base->BDRL = ((uint32)DataTemp & Mask);
666 }
667
668 /**
669 * @brief Gets the first byte of the rx data buffer.
670 *
671 * This function retrieves one byte from the rx data buffer.
672 *
673 * @param Base LINFLEXD Base pointer.
674 * @return data byte.
675 */
Linflexd_Uart_Ip_GetRxDataBuffer1Byte(const LINFLEXD_Type * Base)676 static inline uint8 Linflexd_Uart_Ip_GetRxDataBuffer1Byte(const LINFLEXD_Type * Base)
677 {
678 return (uint8)((Base->BDRM & LINFLEXD_BDRM_DATA4_MASK) >> LINFLEXD_BDRM_DATA4_SHIFT);
679 }
680
681 /**
682 * @internal
683 * @brief Gets the first half-word of the rx data buffer.
684 *
685 * This function retrieves two bytes from the rx data buffer.
686 *
687 * @param Base LINFLEXD Base pointer.
688 * @return data half-word.
689 */
Linflexd_Uart_Ip_GetRxDataBuffer2Bytes(const LINFLEXD_Type * Base)690 static inline uint16 Linflexd_Uart_Ip_GetRxDataBuffer2Bytes(const LINFLEXD_Type * Base)
691 {
692 uint16 Data;
693 uint32 Mask = LINFLEXD_BDRM_DATA4_MASK | LINFLEXD_BDRM_DATA5_MASK;
694 Data = (uint16)(Base->BDRM & Mask);
695 #ifdef CORE_LITTLE_ENDIAN
696 Data = SWAP_BYTES_UINT16(Data);
697 #endif
698 return Data;
699 }
700
701 /**
702 * @internal
703 * @brief DMA Tx channel enable.
704 *
705 * This function configures the bit that decide the DMA Tx channel enable or disable.
706 *
707 * @param Base LINFLEXD Base pointer.
708 * @param Enable Set Dma Tx Enable/disable.
709 */
Linflexd_Uart_Ip_SetDmaTxEnable(LINFLEXD_Type * Base,boolean Enable)710 static inline void Linflexd_Uart_Ip_SetDmaTxEnable(LINFLEXD_Type *Base, boolean Enable)
711 {
712 Base->DMATXE = LINFLEXD_DMATXE_DTE0(Enable ? 1UL : 0UL);
713 }
714
715 /**
716 * @brief DMA Rx channel enable.
717 *
718 * This function configures the bit that decide the DMA Rx channel enable or disable.
719 *
720 * @param Base LINFLEXD Base pointer.
721 * @param Enable Set Dma Rx enable/disable.
722 */
Linflexd_Uart_Ip_SetDmaRxEnable(LINFLEXD_Type * Base,boolean Enable)723 static inline void Linflexd_Uart_Ip_SetDmaRxEnable(LINFLEXD_Type *Base, boolean Enable)
724 {
725 Base->DMARXE = LINFLEXD_DMARXE_DRE0(Enable ? 1UL : 0UL);
726 }
727
728 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
729 /**
730 * @brief Configures the preset value of the timeout register in UART mode.
731 *
732 * @param Base LINFLEXD Base pointer.
733 * @param PresetValue Preset value of the timeout register.
734 */
Linflexd_Uart_Ip_SetPresetValue(LINFLEXD_Type * Base,uint16 PresetValue)735 static inline void Linflexd_Uart_Ip_SetPresetValue(LINFLEXD_Type *Base, uint16 PresetValue)
736 {
737 Base->UARTPTO = LINFLEXD_UARTPTO_PTO(PresetValue);
738 }
739 #endif
740
741 /**
742 * @brief : Prepare for timeout checking
743 * @internal
744 * @return : None
745 */
Linflexd_Uart_Ip_StartTimeout(uint32 * StartTimeOut,uint32 * TimeoutTicksOut,uint32 TimeoutUs,OsIf_CounterType OsifCounter)746 static inline void Linflexd_Uart_Ip_StartTimeout(uint32 *StartTimeOut, uint32 *TimeoutTicksOut, uint32 TimeoutUs, OsIf_CounterType OsifCounter)
747 {
748 *StartTimeOut = OsIf_GetCounter(OsifCounter);
749 *TimeoutTicksOut = OsIf_MicrosToTicks(TimeoutUs, OsifCounter);
750 }
751
752 /**
753 * @brief : Checks for timeout condition
754 * @internal
755 * @return TRUE Timeout occurs
756 * FALSE Timeout does not occur
757 */
Linflexd_Uart_Ip_CheckTimeout(uint32 * StartTime,uint32 * ElapsedTicks,uint32 TimeoutTicks,OsIf_CounterType OsifCounter)758 static inline boolean Linflexd_Uart_Ip_CheckTimeout(uint32 * StartTime, uint32 * ElapsedTicks, uint32 TimeoutTicks, OsIf_CounterType OsifCounter)
759 {
760 uint32 CurrentElapsedTicks = OsIf_GetElapsed(StartTime, OsifCounter);
761 *ElapsedTicks += CurrentElapsedTicks;
762 boolean IsTimeout = FALSE;
763
764 if (*ElapsedTicks >= TimeoutTicks)
765 {
766 IsTimeout = TRUE;
767 }
768 else
769 {
770 IsTimeout = FALSE;
771 }
772 return IsTimeout;
773 }
774
775 #define UART_STOP_SEC_CODE
776 #include "Uart_MemMap.h"
777
778 #ifdef __cplusplus
779 }
780 #endif
781
782 /** @} */
783
784 #endif /* LINFLEXD_HWACCESS_H */
785