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