1 /*
2  * Copyright 2021-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef LINFLEXD_UART_IP_TYPES_H
8 #define LINFLEXD_UART_IP_TYPES_H
9 
10 /**
11 *   @file
12 *   @defgroup linflexd_uart_ip Linflexd UART IPL
13 *   @addtogroup  linflexd_uart_ip Linflexd UART IPL
14 *   @{
15 */
16 
17 #ifdef __cplusplus
18 extern "C"{
19 #endif
20 
21 /*==================================================================================================
22 *                                          INCLUDE FILES
23 * 1) system and project includes
24 * 2) needed interfaces from external units
25 * 3) internal and external interfaces from this unit
26 ==================================================================================================*/
27 #include "StandardTypes.h"
28 #include "Linflexd_Uart_Ip_HwAccess.h"
29 /*==================================================================================================
30 *                                 SOURCE FILE VERSION INFORMATION
31 ==================================================================================================*/
32 #define LINFLEXD_UART_IP_TYPES_VENDOR_ID                    43
33 #define LINFLEXD_UART_IP_TYPES_MODULE_ID                    255
34 #define LINFLEXD_UART_IP_TYPES_AR_RELEASE_MAJOR_VERSION     4
35 #define LINFLEXD_UART_IP_TYPES_AR_RELEASE_MINOR_VERSION     7
36 #define LINFLEXD_UART_IP_TYPES_AR_RELEASE_REVISION_VERSION  0
37 #define LINFLEXD_UART_IP_TYPES_SW_MAJOR_VERSION             1
38 #define LINFLEXD_UART_IP_TYPES_SW_MINOR_VERSION             0
39 #define LINFLEXD_UART_IP_TYPES_SW_PATCH_VERSION             0
40 
41 /*==================================================================================================
42 *                                       FILE VERSION CHECKS
43 ==================================================================================================*/
44 /* Checks against Linflexd_Uart_Ip_HwAccess.h */
45 #if (LINFLEXD_UART_IP_HWACCESS_VENDOR_ID != LINFLEXD_UART_IP_TYPES_VENDOR_ID)
46     #error "Linflexd_Uart_Ip_HwAccess.h and Linflexd_Uart_Ip_Types.h have different vendor ids"
47 #endif
48 #if ((LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MAJOR_VERSION    != LINFLEXD_UART_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
49      (LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_MINOR_VERSION    != LINFLEXD_UART_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
50      (LINFLEXD_UART_IP_HWACCESS_AR_RELEASE_REVISION_VERSION != LINFLEXD_UART_IP_TYPES_AR_RELEASE_REVISION_VERSION) \
51     )
52      #error "AUTOSAR Version Numbers of Linflexd_Uart_Ip_HwAccess.h and Linflexd_Uart_Ip_Types.h are different"
53 #endif
54 #if ((LINFLEXD_UART_IP_HWACCESS_SW_MAJOR_VERSION != LINFLEXD_UART_IP_TYPES_SW_MAJOR_VERSION) || \
55      (LINFLEXD_UART_IP_HWACCESS_SW_MINOR_VERSION != LINFLEXD_UART_IP_TYPES_SW_MINOR_VERSION) || \
56      (LINFLEXD_UART_IP_HWACCESS_SW_PATCH_VERSION != LINFLEXD_UART_IP_TYPES_SW_PATCH_VERSION) \
57     )
58     #error "Software Version Numbers of Linflexd_Uart_Ip_HwAccess.h and Linflexd_Uart_Ip_Types.h are different"
59 #endif
60 
61 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
62 /* Check if current file and StandardTypes.h header file are of the same Autosar version */
63     #if ((LINFLEXD_UART_IP_TYPES_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
64          (LINFLEXD_UART_IP_TYPES_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION) \
65         )
66         #error "Linflexd_Uart_Ip_Types.h and StandardTypes.h are different"
67     #endif
68 #endif
69 /*==================================================================================================
70 *                                            CONSTANTS
71 ==================================================================================================*/
72 
73 /*==================================================================================================
74 *                                       TYPES AND MACROS
75 ==================================================================================================*/
76 
77 /*==================================================================================================
78 *                                              ENUMS
79 ==================================================================================================*/
80 
81 /**
82  * @brief Type of UART a-sync transfer (based on interrupts or DMA).
83  *
84  *
85  */
86 typedef enum
87 {
88     LINFLEXD_UART_IP_USING_DMA         = 0U,    /**< @brief The driver will use DMA to perform UART transfer */
89     LINFLEXD_UART_IP_USING_INTERRUPTS  = 1U     /**< @brief The driver will use interrupts to perform UART transfer */
90 } Linflexd_Uart_Ip_TransferType;
91 
92 /**
93 * @brief          The type operation of an LinflexD Uart channel.
94 */
95 typedef enum
96 {
97     LINFLEXD_UART_IP_SEND    = (uint8)0x00U, /**< @brief The sending operation */
98     LINFLEXD_UART_IP_RECEIVE = (uint8)0x01U  /**< @brief The receiving operation */
99 } Linflexd_Uart_Ip_DataDirectionType;
100 
101 /**
102  * @brief Driver status type.
103  *
104  *
105  * */
106 typedef enum
107 {
108     LINFLEXD_UART_IP_STATUS_SUCCESS                    = 0x00U,  /**< @brief Generic operation success status */
109     LINFLEXD_UART_IP_STATUS_ERROR                      = 0x01U,  /**< @brief Generic operation failure status */
110     LINFLEXD_UART_IP_STATUS_BUSY                       = 0x02U,  /**< @brief Generic operation busy status */
111     LINFLEXD_UART_IP_STATUS_TIMEOUT                    = 0x03U,  /**< @brief Generic operation timeout status */
112     LINFLEXD_UART_IP_STATUS_TX_UNDERRUN                = 0x04U,  /**< @brief TX underrun error */
113     LINFLEXD_UART_IP_STATUS_RX_OVERRUN                 = 0x05U,  /**< @brief RX overrun error */
114     LINFLEXD_UART_IP_STATUS_ABORTED                    = 0x06U,  /**< @brief* A transfer was aborted */
115     LINFLEXD_UART_IP_STATUS_FRAMING_ERROR              = 0x07U,  /**< @brief Framing error */
116     LINFLEXD_UART_IP_STATUS_PARITY_ERROR               = 0x08U,  /**< @brief Parity error */
117     LINFLEXD_UART_IP_STATUS_NOISE_ERROR                = 0x09U,  /**< @brief Noise error */
118     LINFLEXD_UART_IP_STATUS_DMA_ERROR                  = 0x10U,  /**< @brief DMA error */
119 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
120     LINFLEXD_UART_IP_STATUS_RX_IDLE_STATE              = 0x11U,  /**< @brief The idle state of the reception line is generated */
121 #endif
122 } Linflexd_Uart_Ip_StatusType;
123 
124 /*==================================================================================================
125 *                                  STRUCTURES AND OTHER TYPEDEFS
126 ==================================================================================================*/
127 /**
128  * @brief Define the enum of the Events which can trigger UART callback
129  *
130  * @details This enum should include the Events for all platforms.
131  *
132  *
133  */
134 typedef enum
135 {
136     LINFLEXD_UART_IP_EVENT_RX_FULL          = 0x00U,    /**< @brief Rx buffer is full */
137     LINFLEXD_UART_IP_EVENT_TX_EMPTY         = 0x01U,    /**< @brief Tx buffer is empty */
138     LINFLEXD_UART_IP_EVENT_END_TRANSFER     = 0x02U,    /**< @brief The current transfer is ending */
139     LINFLEXD_UART_IP_EVENT_ERROR            = 0x03U,    /**< @brief An error occured during transfer */
140 #if (LINFLEXD_UART_IP_ENABLE_TIMEOUT_INTERRUPT == STD_ON)
141     LINFLEXD_UART_IP_EVENT_IDLE_STATE       = 0x04U    /**< @brief The idle state of the reception line is generated*/
142 #endif
143 } Linflexd_Uart_Ip_EventType;
144 
145 /**
146  * @brief Callback for all peripherals which support UART features
147  *
148  *
149  */
150 typedef void (*Linflexd_Uart_Ip_CallbackType)(const uint8 HwInstance,
151                                               const Linflexd_Uart_Ip_EventType Event,
152                                               void *UserData);
153 
154 
155 /**
156  * @brief Runtime State of the UART driver.
157  *
158  *
159  */
160 typedef struct
161 {
162     uint32 Baudrate;                                     /**< @brief Variable that indicates if structure belongs to an instance already initialized.*/
163     const uint8 * TxBuff;                                  /**< @brief The buffer of data being sent.*/
164     uint8 * RxBuff;                                        /**< @brief The buffer of received data.*/
165     volatile uint32 TxSize;                              /**< @brief The remaining number of bytes to be transmitted. */
166     volatile uint32 RxSize;                              /**< @brief The remaining number of bytes to be received. */
167     volatile boolean IsTxBusy;                             /**< @brief True if there is an active transmit.*/
168     volatile boolean IsRxBusy;                             /**< @brief True if there is an active receive.*/
169     volatile Linflexd_Uart_Ip_StatusType TransmitStatus;   /**< @brief Status of last driver transmit operation */
170     volatile Linflexd_Uart_Ip_StatusType ReceiveStatus;    /**< @brief Status of last driver receive operation */
171     boolean IsDriverInitialized;                           /**< @brief Variable that indicates if driver is initialized or not */
172 
173 } Linflexd_Uart_Ip_StateStructureType;
174 
175 /**
176  *  @brief LINFLEXD configuration structure
177  *
178  * Implements : Linflexd_Uart_Ip_UserConfigType
179  */
180 typedef struct
181 {
182     uint32 BaudRate;                                 /**< @brief Baudrate value*/
183     uint32 BaudRateMantissa;                         /**< @brief Baudrate mantissa*/
184     uint8 BaudRateDivisor;                           /**< @brief Baudrate Divisor*/
185     uint8 BaudRateFractionalDivisor;                 /**< @brief Fractional Baudrate*/
186     /**
187      *
188      * @brief    Parity control - enabled/disabled
189      * @details: This parameter is valid only for 8/16 bits words;
190      *           for 7/15 word length parity is always enabled
191      */
192     boolean ParityCheck;
193 
194     Linflexd_Uart_Ip_ParityType ParityType;            /**< @brief always 0/always 1/even/odd */
195     Linflexd_Uart_Ip_StopBitsCountType StopBitsCount;  /**< @brief number of stop bits, 1 stop bit (default) or 2 stop bits */
196     Linflexd_Uart_Ip_WordLengthType WordLength;        /**< @brief number of bits per transmitted/received word */
197     Linflexd_Uart_Ip_TransferType TransferType;        /**< @brief Type of UART transfer (interrupt/dma based) */
198     Linflexd_Uart_Ip_CallbackType Callback;         /**< @brief Callback to invoke for handling uart event */
199     void * CallbackParam;                            /**< @brief Receive callback parameter pointer.*/
200 #if (LINFLEXD_UART_IP_HAS_DMA_ENABLED == STD_ON)
201     uint32 RxDMAChannel;                               /**< @brief DMA channel number for DMA-based rx.
202                                                                     If DMA mode is not used this field will be ignored. */
203     uint32 TxDMAChannel;                               /**< @brief DMA channel number for DMA-based tx.
204                                                                     If DMA mode is not used this field will be ignored. */
205 #endif
206     Linflexd_Uart_Ip_StateStructureType* StateStruct;  /**< @brief Runtime state structure refference */
207 
208 } Linflexd_Uart_Ip_UserConfigType;
209 
210  /**
211 *
212 * @brief   Baudrate values supported by the driver
213 */
214 typedef enum
215 {
216     LINFLEXD_UART_BAUDRATE_1200   = 1200U,
217     LINFLEXD_UART_BAUDRATE_2400   = 2400U,
218     LINFLEXD_UART_BAUDRATE_4800   = 4800U,
219     LINFLEXD_UART_BAUDRATE_7200   = 7200U,
220     LINFLEXD_UART_BAUDRATE_9600   = 9600U,
221     LINFLEXD_UART_BAUDRATE_14400  = 14400U,
222     LINFLEXD_UART_BAUDRATE_19200  = 19200U,
223     LINFLEXD_UART_BAUDRATE_28800  = 28800U,
224     LINFLEXD_UART_BAUDRATE_38400  = 38400U,
225     LINFLEXD_UART_BAUDRATE_57600  = 57600U,
226     LINFLEXD_UART_BAUDRATE_115200 = 115200U,
227     LINFLEXD_UART_BAUDRATE_230400 = 230400U,
228     LINFLEXD_UART_BAUDRATE_460800 = 460800U,
229     LINFLEXD_UART_BAUDRATE_921600 = 921600U,
230     LINFLEXD_UART_BAUDRATE_1843200 = 1843200U
231 }
232 Linflexd_Uart_Ip_BaudrateType;
233 /*==================================================================================================
234 *                                  GLOBAL VARIABLE DECLARATIONS
235 ==================================================================================================*/
236 
237 /*==================================================================================================
238 *                                       FUNCTION PROTOTYPES
239 ==================================================================================================*/
240 
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 /**  @} */
247 
248 #endif /* LINFLEXD_UART_IP_TYPES_H */
249