From dc455ac70d271d35a278ad911d8c9cb658dae4b3 Mon Sep 17 00:00:00 2001 From: Liu_Weichao Date: Tue, 8 Jun 2021 14:32:58 +0800 Subject: [PATCH] add driver posix transform --- APP_Framework/Framework/transform.c | 73 +++++++++++++++++++ APP_Framework/Framework/transform.h | 107 ++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) diff --git a/APP_Framework/Framework/transform.c b/APP_Framework/Framework/transform.c index e69de29b..b36b55a7 100644 --- a/APP_Framework/Framework/transform.c +++ b/APP_Framework/Framework/transform.c @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file transform.c + * @brief support to transform the application interface from private api to posix api + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.06.07 + */ + +#include "transform.h" + +//for test +#define XIUOS_OS + +#ifdef XIUOS_OS +/************************Kernel Posix Transform***********************/ + + +/************************Driver Posix Transform***********************/ +int PrivOpen(const char *path, int flags, ...) +{ + return open(path, flags, ...); +} + +int PrivClose(int fd, void *buf, size_t len) +{ + return close(fd); +} + +int PrivRead(int fd, void *buf, size_t len) +{ + return read(fd, buf, len); +} + +int PrivWrite(int fd, const void *buf, size_t len) +{ + return write(fd, buf, len); +} + +static int PrivSerialIoctl(int fd, void *args) +{ + struct SerialDataCfg *serial_cfg = (struct SerialDataCfg *)args; + + return ioctl(fd, OPE_INT, &serial_cfg); +} + +int PrivIoctl(int fd, int cmd, void *args) +{ + struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args; + + switch (ioctl_cfg->ioctl_driver_type) + { + case SERIAL_TYPE: + PrivSerialIoctl(fd, ioctl_cfg->args); + break; + default: + break; + } +} + +#endif + diff --git a/APP_Framework/Framework/transform.h b/APP_Framework/Framework/transform.h index e69de29b..44939299 100644 --- a/APP_Framework/Framework/transform.h +++ b/APP_Framework/Framework/transform.h @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file transform.h + * @brief define the struct and transform function + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.06.07 + */ + +#include +#include + +//for test +#define XIUOS_OS + +#define OPE_INT 0x0000 +#define OPE_CFG 0x0001 + +#ifdef XIUOS_OS + +/************************Serial Configure define***********************/ +#define BAUD_RATE_2400 2400 +#define BAUD_RATE_4800 4800 +#define BAUD_RATE_9600 9600 +#define BAUD_RATE_19200 19200 +#define BAUD_RATE_38400 38400 +#define BAUD_RATE_57600 57600 +#define BAUD_RATE_115200 115200 +#define BAUD_RATE_230400 230400 +#define BAUD_RATE_460800 460800 +#define BAUD_RATE_921600 921600 +#define BAUD_RATE_2000000 2000000 +#define BAUD_RATE_3000000 3000000 + +#define DATA_BITS_5 5 +#define DATA_BITS_6 6 +#define DATA_BITS_7 7 +#define DATA_BITS_8 8 +#define DATA_BITS_9 9 + +#define STOP_BITS_1 1 +#define STOP_BITS_2 2 +#define STOP_BITS_3 3 +#define STOP_BITS_4 4 + +#define PARITY_NONE 1 +#define PARITY_ODD 2 +#define PARITY_EVEN 3 + +#define BIT_ORDER_LSB 1 +#define BIT_ORDER_MSB 2 + +#define NRZ_NORMAL 1 +#define NRZ_INVERTED 2 + +#ifndef SERIAL_RB_BUFSZ +#define SERIAL_RB_BUFSZ 128 +#endif + +struct SerialDataCfg +{ + uint32_t serial_baud_rate; + uint8_t serial_data_bits; + uint8_t serial_stop_bits; + uint8_t serial_parity_mode; + uint8_t serial_bit_order; + uint8_t serial_invert_mode; + uint16_t serial_buffer_size; +}; + +/************************Driver Posix Transform***********************/ +enum IoctlDriverType +{ + SERIAL_TYPE = 0, + SPI_TYPE, + I2C_TYPE, + DEFAULT_TYPE, +} + +struct PrivIoctlCfg +{ + enum IoctlDriverType ioctl_driver_type; + void *args; +} + +int PrivOpen(const char *path, int flags, ...); + +int PrivClose(int fd, void *buf, size_t len); + +int PrivRead(int fd, void *buf, size_t len); + +int PrivWrite(int fd, const void *buf, size_t len); + +int PrivIoctl(int fd, int cmd, void *args); + +#endif