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