1 /* 2 * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. 3 * 4 * This file is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef __UART_BES_H__ 10 #define __UART_BES_H__ 11 12 #include "uart_if.h" 13 #include "uart_core.h" 14 #include "hal_uart.h" 15 #include "kfifo.h" 16 #include "osal_sem.h" 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d" 22 #define MAX_DEV_NAME_SIZE 32 23 24 struct UartResource { 25 uint32_t num; /* UART port num */ 26 uint32_t baudRate; /* Default baudrate */ 27 uint32_t wLen; /* Default word length */ 28 uint32_t parity; /* Default parity */ 29 uint32_t stopBit; /* Default stop bits */ 30 bool txDMA; 31 bool rxDMA; 32 }; 33 34 enum UartDeviceState { 35 UART_DEVICE_UNINITIALIZED = 0x0u, 36 UART_DEVICE_INITIALIZED = 0x1u, 37 }; 38 39 struct UART_CTX_OBJ { 40 uint8_t *buffer; 41 bool txDMA; 42 bool rxDMA; 43 bool isBlock; 44 struct kfifo fifo; 45 struct OsalSem rxSem; 46 struct OsalSem txSem; 47 void (*UartDmaRxHandler)(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status); 48 void (*UartDmaTxHandler)(uint32_t xferSize, int dmaError); 49 }; 50 51 struct UartDevice { 52 struct IDeviceIoService ioService; 53 struct UartResource resource; 54 struct HAL_UART_CFG_T config; 55 uint32_t uartId; 56 bool initFlag; 57 uint32_t transMode; 58 }; 59 60 enum { 61 UART_READ = 0, 62 UART_WRITE 63 }; 64 65 int32_t UartDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply); 66 67 #ifdef __cplusplus 68 } 69 #endif 70 71 #endif 72