First commit XiUOS

This commit is contained in:
xuetest
2021-04-28 17:49:18 +08:00
commit 6001051eb7
1331 changed files with 433955 additions and 0 deletions
+267
View File
@@ -0,0 +1,267 @@
/*
* 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 bus.h
* @brief define bus driver framework function and common API
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_H
#define BUS_H
#include <xiuos.h>
#ifdef __cplusplus
extern "C" {
#endif
#define OPE_INT 0x0000
#define OPE_CFG 0x0001
#define OPER_WDT_SET_TIMEOUT 0x0002
#define OPER_WDT_KEEPALIVE 0x0003
typedef struct Bus *BusType;
typedef struct HardwareDev *HardwareDevType;
typedef struct Driver *DriverType;
/* need to add new bus type in ../tool/shell/letter-shell/cmd.c, ensure ShowBus cmd supported*/
enum BusType
{
TYPE_I2C_BUS = 0,
TYPE_SPI_BUS,
TYPE_HWTIMER_BUS,
TYPE_USB_BUS,
TYPE_CAN_BUS,
TYPE_WDT_BUS,
TYPE_SDIO_BUS,
TYPE_TOUCH_BUS,
TYPE_LCD_BUS,
TYPE_PIN_BUS,
TYPE_RTC_BUS,
TYPE_SERIAL_BUS,
TYPE_BUS_END,
};
enum BusState
{
BUS_INIT = 0,
BUS_INSTALL,
BUS_UNINSTALL,
};
enum DevType
{
TYPE_I2C_DEV = 0,
TYPE_SPI_DEV,
TYPE_HWTIMER_DEV,
TYPE_USB_DEV,
TYPE_CAN_DEV,
TYPE_WDT_DEV,
TYPE_SDIO_DEV,
TYPE_TOUCH_DEV,
TYPE_LCD_DEV,
TYPE_PIN_DEV,
TYPE_RTC_DEV,
TYPE_SERIAL_DEV,
TYPE_DEV_END,
};
enum DevState
{
DEV_INIT = 0,
DEV_INSTALL,
DEV_UNINSTALL,
};
enum DriverType
{
TYPE_I2C_DRV = 0,
TYPE_SPI_DRV,
TYPE_HWTIMER_DRV,
TYPE_USB_DRV,
TYPE_CAN_DRV,
TYPE_WDT_DRV,
TYPE_SDIO_DRV,
TYPE_TOUCH_DRV,
TYPE_LCD_DRV,
TYPE_PIN_DRV,
TYPE_RTC_DRV,
TYPE_SERIAL_DRV,
TYPE_DRV_END,
};
enum DriverState
{
DRV_INIT = 0,
DRV_INSTALL,
DRV_UNINSTALL,
};
struct BusConfigureInfo
{
int configure_cmd;
void *private_data;
};
struct BusBlockReadParam
{
x_OffPos pos;
void* buffer;
x_size_t size;
x_size_t read_length;
};
struct BusBlockWriteParam
{
x_OffPos pos;
const void* buffer;
x_size_t size;
};
struct HalDevBlockParam
{
uint32 cmd;
struct DeviceBlockArrange dev_block;
struct DeviceBlockAddr *dev_addr;
};
struct HalDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct HardwareDev
{
int8 dev_name[NAME_NUM_MAX];
enum DevType dev_type;
enum DevState dev_state;
const struct HalDevDone *dev_done;
int (*dev_recv_callback) (void *dev, x_size_t length);
int (*dev_block_control) (struct HardwareDev *dev, struct HalDevBlockParam *block_param);
struct Bus *owner_bus;
void *private_data;
int32 dev_sem;
DoubleLinklistType dev_link;
};
struct Driver
{
int8 drv_name[NAME_NUM_MAX];
enum DriverType driver_type;
enum DriverState driver_state;
uint32 (*configure)(void *drv, struct BusConfigureInfo *configure_info);
struct Bus *owner_bus;
void *private_data;
DoubleLinklistType driver_link;
};
struct Bus
{
int8 bus_name[NAME_NUM_MAX];
enum BusType bus_type;
enum BusState bus_state;
int32 (*match)(struct Driver *driver, struct HardwareDev *device);
int bus_lock;
struct HardwareDev *owner_haldev;
struct Driver *owner_driver;
void *private_data;
/*manage the drv of the bus*/
uint8 driver_cnt;
uint8 bus_drvlink_flag;
DoubleLinklistType bus_drvlink;
/*manage the dev of the bus*/
uint8 haldev_cnt;
uint8 bus_devlink_flag;
DoubleLinklistType bus_devlink;
uint8 bus_cnt;
uint8 bus_link_flag;
DoubleLinklistType bus_link;
};
/*Register the BUS,manage with the double linklist*/
int BusRegister(struct Bus *bus);
/*Release the BUS framework*/
int BusRelease(struct Bus *bus);
/*Unregister a certain kind of BUS*/
int BusUnregister(struct Bus *bus);
/*Register the driver to the bus*/
int DriverRegisterToBus(struct Bus *bus, struct Driver *driver);
/*Register the device to the bus*/
int DeviceRegisterToBus(struct Bus *bus, struct HardwareDev *device);
/*Delete the driver from the bus*/
int DriverDeleteFromBus(struct Bus *bus, struct Driver *driver);
/*Delete the device from the bus*/
int DeviceDeleteFromBus(struct Bus *bus, struct HardwareDev *device);
/*Find the bus with bus name*/
BusType BusFind(const char *bus_name);
/*Find the driver of cetain bus*/
DriverType BusFindDriver(struct Bus *bus, const char *driver_name);
/*Find the device of certain bus*/
HardwareDevType BusFindDevice(struct Bus *bus, const char *device_name);
/*Dev receive data callback function*/
uint32 BusDevRecvCallback(struct HardwareDev *dev, int (*dev_recv_callback) (void *dev, x_size_t length));
/*Open the device of the bus*/
uint32 BusDevOpen(struct HardwareDev *dev);
/*Close the device of the bus*/
uint32 BusDevClose(struct HardwareDev *dev);
/*Write data to the device*/
uint32 BusDevWriteData(struct HardwareDev *dev, struct BusBlockWriteParam *write_param);
/*Read data from the device*/
uint32 BusDevReadData(struct HardwareDev *dev, struct BusBlockReadParam *read_param);
/*Configure the driver of the bus*/
uint32 BusDrvConfigure(struct Driver *drv, struct BusConfigureInfo *configure_info);
/*Obtain the bus using a certain dev*/
int DeviceObtainBus(struct Bus *bus, struct HardwareDev *dev, const char *drv_name, struct BusConfigureInfo *configure_info);
#ifdef __cplusplus
}
#endif
#endif
+67
View File
@@ -0,0 +1,67 @@
/*
* 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 bus_can.h
* @brief define can bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_CAN_H
#define BUS_CAN_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct CanDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
void *private_data;
};
struct CanBus
{
struct Bus bus;
void *private_data;
};
/*Register the CAN bus*/
int CanBusInit(struct CanBus *can_bus, const char *bus_name);
/*Register the CAN driver*/
int CanDriverInit(struct CanDriver *can_driver, const char *driver_name);
/*Release the CAN device*/
int CanReleaseBus(struct CanBus *can_bus);
/*Register the CAN driver to the CAN bus*/
int CanDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int CanDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType CanDriverFind(const char *drv_name, enum DriverType drv_type);
#ifdef __cplusplus
}
#endif
#endif
+65
View File
@@ -0,0 +1,65 @@
/*
* 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 bus_hwtimer.h
* @brief define hwtimer bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_HWTIMER_H
#define BUS_HWTIMER_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct HwtimerDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
};
struct HwtimerBus
{
struct Bus bus;
void *private_data;
};
/*Register the hwtimer bus*/
int HwtimerBusInit(struct HwtimerBus *hwtimer_bus, const char *bus_name);
/*Register the hwtimer driver*/
int HwtimerDriverInit(struct HwtimerDriver *hwtimer_driver, const char *driver_name);
/*Release the hwtimer device*/
int HwtimerReleaseBus(struct HwtimerBus *hwtimer_bus);
/*Register the hwtimer driver to the hwtimer bus*/
int HwtimerDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int HwtimerDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType HwtimerDriverFind(const char *drv_name);
#ifdef __cplusplus
}
#endif
#endif
+90
View File
@@ -0,0 +1,90 @@
/*
* 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 bus_i2c.h
* @brief define i2c bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_I2C_H
#define BUS_I2C_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct I2cHalDrvDone
{
void *data;
void (*SetSdaState) (void *data, uint8 sda_state);
void (*SetSclState) (void *data, uint8 scl_state);
uint8 (*GetSdaState) (void *data);
uint8 (*GetSclState) (void *data);
#ifdef ARCH_RISCV
int (*udelay)(uint64 us);
#endif
#ifdef ARCH_ARM
int (*udelay)(uint32 us);
#endif
uint32 delay_us;
uint32 timeout;
};
typedef struct
{
uint8 i2c_sda_pin;
uint8 i2c_scl_pin;
}I2cBusParam;
struct I2cDriver
{
struct Driver driver;
void *private_data;
};
struct I2cBus
{
struct Bus bus;
void *private_data;
};
/*Register the I2C bus*/
int I2cBusInit(struct I2cBus *i2c_bus, const char *bus_name);
/*Register the I2C driver*/
int I2cDriverInit(struct I2cDriver *i2c_driver, const char *driver_name);
/*Release the I2C device*/
int I2cReleaseBus(struct I2cBus *i2c_bus);
/*Register the I2C driver to the I2C bus*/
int I2cDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int I2cDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType I2cDriverFind(const char *drv_name, enum DriverType drv_type);
#ifdef __cplusplus
}
#endif
#endif
+65
View File
@@ -0,0 +1,65 @@
/*
* 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 bus_lcd.h
* @brief define lcd bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_LCD_H
#define BUS_LCD_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct LcdDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
};
struct LcdBus
{
struct Bus bus;
void *private_data;
};
/*Register the lcd bus*/
int LcdBusInit(struct LcdBus *lcd_bus , const char *bus_name);
/*Register the lcd driver*/
int LcdDriverInit(struct LcdDriver *lcd_driver, const char *driver_name);
/*Release the lcd device*/
int LcdReleaseBus(struct LcdBus *lcd_bus );
/*Register the lcd driver to the lcd bus*/
int LcdDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int LcdDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType LcdDriverFind(const char *drv_name, enum DriverType drv_type);
#ifdef __cplusplus
}
#endif
#endif
+68
View File
@@ -0,0 +1,68 @@
/*
* 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 bus_pin.h
* @brief define pin bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_PIN_H
#define BUS_PIN_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct PinDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *ConfigureInfo);
};
struct PinBus
{
struct Bus bus;
void *private_data;
};
/*Register the Pin bus*/
int PinBusInit(struct PinBus *pin_bus, const char *bus_name);
/*Register the Pin driver*/
int PinDriverInit(struct PinDriver *pin_driver, const char *driver_name, void *data);
/*Release the Pin device*/
int PinReleaseBus(struct PinBus *pin_bus);
/*Register the Pin driver to the Pin bus*/
int PinDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int PinDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType PinDriverFind(const char *drv_name, enum DriverType drv_type);
/*Get the initialized Pin bus*/
BusType PinBusInitGet(void);
#ifdef __cplusplus
}
#endif
#endif
+98
View File
@@ -0,0 +1,98 @@
/*
* 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 bus_rtc.h
* @brief define rtc bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_RTC_H
#define BUS_RTC_H
#include <bus.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
struct RtcDateParam
{
uint32 year;
uint32 month;
uint32 day;
};
struct RtcTimeParam
{
uint32 hour;
uint32 minute;
uint32 second;
};
struct RtcSetParam
{
int rtc_set_cmd;
time_t *time;
struct RtcDateParam date_param;
struct RtcTimeParam time_param;
};
struct RtcDrvConfigureParam
{
int rtc_operation_cmd;
time_t *time;
};
struct RtcDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
};
struct RtcBus
{
struct Bus bus;
void *private_data;
};
/*Register the rtc bus*/
int RtcBusInit(struct RtcBus *rtc_bus, const char *bus_name);
/*Register the rtc driver*/
int RtcDriverInit(struct RtcDriver *rtc_driver, const char *driver_name);
/*Release the rtc device*/
int RtcReleaseBus(struct RtcBus *rtc_bus);
/*Register the rtc driver to the rtc bus*/
int RtcDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int RtcDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType RtcDriverFind(const char *drv_name, enum DriverType drv_type);
/*Set Rtc time and date*/
int RtcDrvSetFunction(char *driver_name, struct RtcSetParam *rtc_set_param);
#ifdef __cplusplus
}
#endif
#endif
+64
View File
@@ -0,0 +1,64 @@
/*
* 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 bus_sdio.h
* @brief define sdio bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_SDIO_H
#define BUS_SDIO_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct SdioDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
};
struct SdioBus
{
struct Bus bus;
void *private_data;
};
/*Register the sdio bus*/
int SdioBusInit(struct SdioBus *sdio_bus, const char *bus_name);
/*Register the sdio driver*/
int SdioDriverInit(struct SdioDriver *sdio_driver, const char *driver_name);
/*Release the sdio device*/
int SdioReleaseBus(struct SdioBus *sdio_bus);
/*Register the sdio driver to the sdio bus*/
int SdioDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int SdioDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType SdioDriverFind(const char *drv_name);
#ifdef __cplusplus
}
#endif
#endif
+112
View File
@@ -0,0 +1,112 @@
/*
* 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 bus_serial.h
* @brief define serial bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_SERIAL_H
#define BUS_SERIAL_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
enum ExtSerialPortConfigure
{
PORT_CFG_INIT = 0,
PORT_CFG_PARITY_CHECK,
PORT_CFG_DISABLE,
PORT_CFG_DIV,
};
struct SerialDataCfg
{
uint32 serial_baud_rate;
uint8 serial_data_bits;
uint8 serial_stop_bits;
uint8 serial_parity_mode;
uint8 serial_bit_order;
uint8 serial_invert_mode;
uint16 serial_buffer_size;
uint8 ext_uart_no;
enum ExtSerialPortConfigure port_configure;
};
struct SerialHwCfg
{
uint32 serial_register_base;
uint32 serial_irq_interrupt;
void *private_data;
};
struct SerialCfgParam
{
struct SerialDataCfg data_cfg;
struct SerialHwCfg hw_cfg;
};
struct SerialDriver;
struct SerialDrvDone
{
uint32 (*init) (struct SerialDriver *serial_drv, struct BusConfigureInfo *configure_info);
uint32 (*configure) (struct SerialDriver *serial_drv, int serial_operation_cmd);
};
struct SerialDriver
{
struct Driver driver;
const struct SerialDrvDone *drv_done;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
void *private_data;
};
struct SerialBus
{
struct Bus bus;
void *private_data;
};
/*Register the serial bus*/
int SerialBusInit(struct SerialBus *serial_bus, const char *bus_name);
/*Register the serial driver*/
int SerialDriverInit(struct SerialDriver *serial_driver, const char *driver_name);
/*Release the serial bus*/
int SerialReleaseBus(struct SerialBus *serial_bus);
/*Register the serial driver to the serial bus*/
int SerialDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int SerialDriverRegister(struct Driver *driver);
/*Find the regiter driver*/
DriverType SerialDriverFind(const char *drv_name, enum DriverType drv_type);
#ifdef __cplusplus
}
#endif
#endif
+66
View File
@@ -0,0 +1,66 @@
/*
* 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 bus_spi.h
* @brief define spi bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_SPI_H
#define BUS_SPI_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct SpiDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
};
struct SpiBus
{
struct Bus bus;
void *private_data;
};
/*Register the spi bus*/
int SpiBusInit(struct SpiBus *spi_bus, const char *bus_name);
/*Register the spi driver*/
int SpiDriverInit(struct SpiDriver *spi_driver, const char *driver_name);
/*Release the spi device*/
int SpiReleaseBus(struct SpiBus *spi_bus);
/*Register the spi driver to the spi bus*/
int SpiDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int SpiDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType SpiDriverFind(const char *drv_name, enum DriverType drv_type);
#ifdef __cplusplus
}
#endif
#endif
+65
View File
@@ -0,0 +1,65 @@
/*
* 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 bus_touch.h
* @brief define touch bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_TOUCH_H
#define BUS_TOUCH_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct TouchDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
};
struct TouchBus
{
struct Bus bus;
void *private_data;
};
/*Register the touch bus*/
int TouchBusInit(struct TouchBus *touch_bus, const char *bus_name);
/*Register the touch driver*/
int TouchDriverInit(struct TouchDriver *touch_driver, const char *driver_name);
/*Release the touch device*/
int TouchReleaseBus(struct TouchBus *touch_bus);
/*Register the touch driver to the touch bus*/
int TouchDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int TouchDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType TouchDriverFind(const char *drv_name, enum DriverType drv_type);
#ifdef __cplusplus
}
#endif
#endif
+68
View File
@@ -0,0 +1,68 @@
/*
* 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 bus_usb.h
* @brief define usb bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_USB_H
#define BUS_USB_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct UsbDriver
{
struct Driver driver;
uint32 (*configure)(void *drv, struct BusConfigureInfo *configure_info);
void *private_data;
};
struct UsbBus
{
struct Bus bus;
void *private_data;
};
/*Register the USB bus*/
int UsbBusInit(struct UsbBus *usb_bus, const char *bus_name);
/*Register the USB driver*/
int UsbDriverInit(struct UsbDriver *usb_driver, const char *driver_name);
/*Release the USB device*/
int UsbReleaseBus(struct UsbBus *usb_bus);
/*Register the USB driver to the USB bus*/
int UsbDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int UsbDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType UsbDriverFind(const char *drv_name, enum DriverType drv_type);
#ifdef __cplusplus
}
#endif
#endif
+66
View File
@@ -0,0 +1,66 @@
/*
* 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 bus_wdt.h
* @brief define wdt bus and drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef BUS_WDT_H
#define BUS_WDT_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct WdtDriver
{
struct Driver driver;
uint32 (*configure) (void *drv, struct BusConfigureInfo *ConfigureInfo);
void *private_data;
};
struct WdtBus
{
struct Bus bus;
void *private_data;
};
/*Register the wdt bus*/
int WdtBusInit(struct WdtBus *wdt_bus, const char *bus_name);
/*Register the wdt driver*/
int WdtDriverInit(struct WdtDriver *wdt_driver, const char *driver_name);
/*Release the wdt device*/
int WdtReleaseBus(struct WdtBus *wdt_bus);
/*Register the wdt driver to the wdt bus*/
int WdtDriverAttachToBus(const char *drv_name, const char *bus_name);
/*Register the driver, manage with the double linklist*/
int WdtDriverRegister(struct Driver *driver);
/*Find the register driver*/
DriverType WdtDriverFind(const char *drv_name);
#ifdef __cplusplus
}
#endif
#endif
+79
View File
@@ -0,0 +1,79 @@
/*
* 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 dev_can.h
* @brief define can dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_CAN_H
#define DEV_CAN_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct CanDriverConfigure
{
uint8 tsjw;
uint8 tbs2 ;
uint8 tbs1;
uint8 mode;
uint16 brp;
};
struct CanSendConfigure
{
uint32 stdid;
uint32 exdid;
uint8 ide;
uint8 rtr;
uint8 data_lenth;
uint8 *data;
};
struct CanDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev,struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct CanHardwareDevice
{
struct HardwareDev haldev;
const struct CanDevDone *dev_done;
void *private_data;
};
/*Register the CAN device*/
int CanDeviceRegister(struct CanHardwareDevice *can_device, void *can_param, const char *device_name);
/*Register the CAN device to the CAN bus*/
int CanDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register CAN device*/
HardwareDevType CanDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
+74
View File
@@ -0,0 +1,74 @@
/*
* 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 dev_hwtimer.h
* @brief define hwtimer dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_HWTIMER_H
#define DEV_HWTIMER_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct HwtimerCallBackInfo
{
void (*TimeoutCb) (void* param);
void *param;
};
struct HwtimerDeviceParam
{
uint32 period_millisecond;
uint32 repeat;
struct HwtimerCallBackInfo cb_info;
};
struct HwtimerDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev,struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct HwtimerHardwareDevice
{
struct HardwareDev haldev;
struct HwtimerDeviceParam hwtimer_param;
const struct HwtimerDevDone *dev_done;
void *private_data;
};
/*Register the hwtimer device*/
int HwtimerDeviceRegister(struct HwtimerHardwareDevice *hwtimer_device, void *hwtimer_param, const char *device_name);
/*Register the hwtimer device to the hwtimer bus*/
int HwtimerDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register hwtimer device*/
HardwareDevType HwtimerDeviceFind(const char *dev_name);
#ifdef __cplusplus
}
#endif
#endif
+80
View File
@@ -0,0 +1,80 @@
/*
* 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 dev_i2c.h
* @brief define i2c dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_I2C_H
#define DEV_I2C_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
#define I2C_SLAVE_ADDR 0x44
#define I2C_WR 0x0000
#define I2C_RD (1u << 0)
#define I2C_ADDR_10BIT (1u << 2)
#define I2C_NO_START (1u << 4)
#define I2C_IGNORE_NACK (1u << 5)
#define I2C_NO_READ_ACK (1u << 6)
struct I2cDataStandard
{
uint16 addr;
uint16 flags;
uint16 len;
uint16 retries;
uint8 *buf;
struct I2cDataStandard *next;
};
struct I2cHardwareDevice;
struct I2cDevDone
{
uint32 (*open) (struct I2cHardwareDevice *i2c_device);
uint32 (*close) (struct I2cHardwareDevice *i2c_device);
uint32 (*write) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg);
uint32 (*read) (struct I2cHardwareDevice *i2c_device, struct I2cDataStandard *msg);
};
struct I2cHardwareDevice
{
struct HardwareDev haldev;
const struct I2cDevDone *i2c_dev_done;
void *private_data;
};
/*Register the I2C device*/
int I2cDeviceRegister(struct I2cHardwareDevice *i2c_device, void *i2c_param, const char *device_name);
/*Register the I2C device to the I2C bus*/
int I2cDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register I2C device*/
HardwareDevType I2cDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
+97
View File
@@ -0,0 +1,97 @@
/*
* 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 dev_lcd.h
* @brief define lcd dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_LCD_H
#define DEV_LCD_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
/*set the pen color*/
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0xF81F
#define GRED 0xFFE0
#define GBLUE 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0xBC40
#define BRRED 0xFC07
#define GRAY 0x8430
#define DARKBLUE 0x01CF//Navy blue
#define LIGHTBLUE 0x7D7C//Light blue
#define GRAYBLUE 0x5458//Gray blue
#define LIGHTGREEN 0x841F
#define LGRAY 0xC618
#define LGRAYBLUE 0xA651
#define LBBLUE 0x2B12
typedef struct
{
uint16 x_pos;
uint16 y_pos;
uint16 width;
uint16 height;
uint8 font_size;
uint8 *addr;
uint16 font_color;
uint16 back_color;
}LcdStringParam;
struct LcdDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct LcdHardwareDevice
{
struct HardwareDev haldev;
const struct LcdDevDone *dev_done;
void *private_data;
};
/*Register the lcd device*/
int LcdDeviceRegister(struct LcdHardwareDevice *lcd_device, void *lcd_param, const char *device_name);
/*Register the lcd device to the lcd bus*/
int LcdDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register lcd device*/
HardwareDevType LcdDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
+111
View File
@@ -0,0 +1,111 @@
/*
* 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 dev_pin.h
* @brief define pin dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_PIN_H
#define DEV_PIN_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GPIO_LOW 0x00
#define GPIO_HIGH 0x01
#define GPIO_CFG_OUTPUT 0x00
#define GPIO_CFG_INPUT 0x01
#define GPIO_CFG_INPUT_PULLUP 0x02
#define GPIO_CFG_INPUT_PULLDOWN 0x03
#define GPIO_CFG_OUTPUT_OD 0x04
#define GPIO_IRQ_EDGE_RISING 0x00
#define GPIO_IRQ_EDGE_FALLING 0x01
#define GPIO_IRQ_EDGE_BOTH 0x02
#define GPIO_IRQ_LEVEL_HIGH 0x03
#define GPIO_IRQ_LEVEL_LOW 0x04
#define GPIO_CONFIG_MODE 0xffffffff
#define GPIO_IRQ_REGISTER 0xfffffffe
#define GPIO_IRQ_FREE 0xfffffffd
#define GPIO_IRQ_DISABLE 0xfffffffc
#define GPIO_IRQ_ENABLE 0xfffffffb
struct PinDevIrq
{
int irq_mode;//< RISING/FALLING/HIGH/LOW
void (*hdr) (void *args);//< callback function
void *args;//< the params of callback function
};
struct PinParam
{
int cmd;//< cmd:GPIO_CONFIG_MODE/GPIO_IRQ_REGISTER/GPIO_IRQ_FREE/GPIO_IRQ_DISABLE/GPIO_IRQ_ENABLE
x_base pin;//< pin number
int mode;//< pin mode: input/output
struct PinDevIrq irq_set;//< pin irq set
uint64 arg;
};
struct PinStat
{
x_base pin;//< pin number
uint16 val;//< pin level
};
struct PinIrqHdr
{
int16 pin;
uint16 mode;
void (*hdr) (void *args);
void *args;
};
struct PinDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct PinHardwareDevice
{
struct HardwareDev haldev;
const struct PinDevDone *dev_done;
void *private_data;
};
/*Register the Pin device*/
int PinDeviceRegister(struct PinHardwareDevice *pin_device, void *pin_param, const char *device_name);
/*Register the Pin Device to the Pin bus*/
int PinDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register Pin device*/
HardwareDevType PinDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
+60
View File
@@ -0,0 +1,60 @@
/*
* 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 dev_rtc.h
* @brief define rtc dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_RTC_H
#define DEV_RTC_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct RtcDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *datacfg);
uint32 (*read) (void *dev, struct BusBlockReadParam *datacfg);
};
struct RtcHardwareDevice
{
struct HardwareDev haldev;
const struct RtcDevDone *dev_done;
void *private_data;
};
/*Register the rtc device*/
int RtcDeviceRegister(struct RtcHardwareDevice *rtc_device, void *rtc_param, const char *device_name);
/*Register the rtc device to the rtc bus*/
int RtcDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register rtc device*/
HardwareDevType RtcDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
+60
View File
@@ -0,0 +1,60 @@
/*
* 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 dev_sdio.h
* @brief define sdio dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_SDIO_H
#define DEV_SDIO_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct SdioDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct SdioHardwareDevice
{
struct HardwareDev haldev;
struct SdioDevDone *dev_done;
void *private_data;
};
/*Register the sdio device*/
int SdioDeviceRegister(struct SdioHardwareDevice *sdio_device, const char *device_name);
/*Register the sdio device to the sdio bus*/
int SdioDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register sdio device*/
HardwareDevType SdioDeviceFind(const char *dev_name);
#ifdef __cplusplus
}
#endif
#endif
+157
View File
@@ -0,0 +1,157 @@
/*
* 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 dev_serial.h
* @brief define serial dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_SERIAL_H
#define DEV_SERIAL_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
#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
#define SERIAL_EVENT_RX_IND 0x01
#define SERIAL_event_id_tX_DONE 0x02
#define SERIAL_EVENT_RX_DMADONE 0x03
#define SERIAL_event_id_tX_DMADONE 0x04
#define SERIAL_EVENT_RX_TIMEOUT 0x05
#define SERIAL_DMA_RX 0x01
#define SERIAL_DMA_TX 0x02
struct SerialTx
{
int32 serial_txfifo_sem;
x_bool serial_dma_enable;
queue serial_dma_queue;
};
struct SerialRx
{
uint8 *serial_rx_buffer;
uint16 serial_send_num;
uint16 serial_recv_num;
x_bool serial_rx_full;
x_bool serial_dma_enable;
};
struct SerialDataTransferParam
{
struct SerialTx *serial_tx;
struct SerialRx *serial_rx;
};
struct SerialDevParam
{
uint8 ext_uart_no;
uint16 serial_work_mode;
uint16 serial_set_mode;
uint16 serial_stream_mode;
};
struct SerialHardwareDevice;
struct SerialHwDevDone
{
int (*put_char) (struct SerialHardwareDevice *serial_dev, char c);
int (*get_char) (struct SerialHardwareDevice *serial_dev);
int (*dmatransfer) (struct SerialHardwareDevice *serial_dev, uint8 *buf, x_size_t size, int direction);
};
struct SerialDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *datacfg);
uint32 (*read) (void *dev, struct BusBlockReadParam *datacfg);
};
struct SerialHardwareDevice
{
struct HardwareDev haldev;
struct SerialHwDevDone *hwdev_done;
struct SerialDataTransferParam serial_fifo;
uint32 ext_serial_mode;
const struct SerialDevDone *dev_done;
void *private_data;
};
/*Register the serial device*/
int SerialDeviceRegister(struct SerialHardwareDevice *serial_device, void *serial_param, const char *device_name);
/*Register the serial device to the serial bus*/
int SerialDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register serial device*/
HardwareDevType SerialDeviceFind(const char *dev_name, enum DevType dev_type);
/*Set serial isr function*/
void SerialSetIsr(struct SerialHardwareDevice *serial_dev, int event);
#ifdef __cplusplus
}
#endif
#endif
+139
View File
@@ -0,0 +1,139 @@
/*
* 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 dev_spi.h
* @brief define spi dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_SPI_H
#define DEV_SPI_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SPI_MAX_CLOCK 40000000
#define spi_device_max_num 4
#define SPI_LINE_CPHA (1<<0)
#define SPI_LINE_CPOL (1<<1)
#define SPI_LSB (0<<2)
#define SPI_MSB (1<<2)
#define SPI_MASTER (0<<3)
#define DEV_SPI_SLAVE (1<<3)
#define SPI_MODE_0 (0 | 0)
#define SPI_MODE_1 (0 | SPI_LINE_CPHA)
#define SPI_MODE_2 (SPI_LINE_CPOL | 0)
#define SPI_MODE_3 (SPI_LINE_CPOL | SPI_LINE_CPHA)
#define SPI_MODE_MASK (SPI_LINE_CPHA | SPI_LINE_CPOL | SPI_MSB)
#define SPI_CS_HIGH (1<<4)
#define SPI_NO_CS (1<<5)
#define SPI_3WIRE (1<<6)
#define SPI_READY (1<<7)
struct SpiDataStandard
{
uint8 spi_chip_select;
uint8 spi_cs_release;
const uint8 *tx_buff;
uint32 tx_len;
const uint8 *rx_buff;
uint32 rx_len;
uint32 length;
struct SpiDataStandard *next;
};
struct SpiMasterParam
{
uint8 spi_work_mode;//CPOL CPHA
uint8 spi_frame_format;//frame format
uint8 spi_data_bit_width;//bit width
uint8 spi_data_endian;//little endian0big endian1
uint32 spi_maxfrequency;//work frequency
};
struct SpiDmaParam
{
uint8 spi_master_id;
uint8 spi_dmac_txchannel;
uint8 spi_dmac_rxchannel;
};
struct SpiSlaveParam
{
uint8 spi_slave_id;
uint8 spi_cs_gpio_pin;
uint8 spi_cs_select_id;
};
typedef struct
{
struct SpiDmaParam *spi_dma_param;
struct SpiSlaveParam *spi_slave_param;
struct SpiMasterParam *spi_master_param;
}SpiDeviceParam;
struct SpiHardwareDevice;
struct SpiDevDone
{
uint32 (*open) (struct SpiHardwareDevice *dev);
uint32 (*close) (struct SpiHardwareDevice *dev);
uint32 (*write) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg);
uint32 (*read) (struct SpiHardwareDevice *dev, struct SpiDataStandard *msg);
};
struct SpiHardwareDevice
{
struct HardwareDev haldev;
SpiDeviceParam spi_param;
x_bool spi_dev_flag;
const struct SpiDevDone *spi_dev_done;
void *private_data;
};
/*Register the spi device*/
int SpiDeviceRegister(struct SpiHardwareDevice *spi_device, void *spi_param, const char *device_name);
/*Register the spi device to the spi bus*/
int SpiDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register spi device*/
HardwareDevType SpiDeviceFind(const char *dev_name, enum DevType dev_type);
/*Configure the cs pin of spi dev*/
int SpiDevConfigureCs(struct HardwareDev *dev, uint8 spi_chip_select, uint8 spi_cs_release);
#ifdef __cplusplus
}
#endif
#endif
+66
View File
@@ -0,0 +1,66 @@
/*
* 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 dev_touch.h
* @brief define touch dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_TOUCH_H
#define DEV_TOUCH_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct TouchDataStandard
{
uint16 x;
uint16 y;
};
struct TouchDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev,struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct TouchHardwareDevice
{
struct HardwareDev haldev;
const struct TouchDevDone *dev_done;
void *private_data;
};
/*Register the touch device*/
int TouchDeviceRegister(struct TouchHardwareDevice *touch_device, void *touch_param, const char *device_name);
/*Register the touch device to the touch bus*/
int TouchDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register touch device*/
HardwareDevType TouchDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
+62
View File
@@ -0,0 +1,62 @@
/*
* 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 dev_usb.h
* @brief define usb dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_USB_H
#define DEV_USB_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
#define UDISK_USB_BUS_NAME USB_BUS_NAME
#define UDISK_USB_DEVICE_NAME USB_DEVICE_NAME
struct UsbDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct UsbHardwareDevice
{
struct HardwareDev haldev;
const struct UsbDevDone *dev_done;
void *private_data;
};
/*Register the USB device*/
int USBDeviceRegister(struct UsbHardwareDevice *usb_device, void *usb_param, const char *device_name);
/*Register the USB device to the USB bus*/
int USBDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register USB device*/
HardwareDevType USBDeviceFind(const char *dev_name, enum DevType dev_type);
#ifdef __cplusplus
}
#endif
#endif
+60
View File
@@ -0,0 +1,60 @@
/*
* 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 dev_wdt.h
* @brief define wdt dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEV_WDT_H
#define DEV_WDT_H
#include <bus.h>
#ifdef __cplusplus
extern "C" {
#endif
struct WdtDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct WdtHardwareDevice
{
struct HardwareDev haldev;
const struct WdtDevDone *dev_done;
void *private_data;
};
/*Register the wdt device*/
int WdtDeviceRegister(struct WdtHardwareDevice *wdt_device, const char *device_name);
/*Register the wdt device to the wdt bus*/
int WdtDeviceAttachToBus(const char *dev_name, const char *bus_name);
/*Find the register wdt device*/
HardwareDevType WdtDeviceFind(const char *dev_name);
#ifdef __cplusplus
}
#endif
#endif
+97
View File
@@ -0,0 +1,97 @@
/*
* 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 device.h
* @brief support to include RESOURCES of all drivers
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef DEVICE_H
#define DEVICE_H
#include <xiuos.h>
#include <xs_avltree.h>
#include <xs_circular_area.h>
#include <xs_dataqueue.h>
#include <xs_workqueue.h>
#include <xs_waitqueue.h>
#ifdef RESOURCES_RTC
#include <bus_rtc.h>
#include <dev_rtc.h>
#endif
#ifdef RESOURCES_SPI
#include <bus_spi.h>
#include <dev_spi.h>
#endif
#ifdef RESOURCES_TOUCH
#include <bus_touch.h>
#include <dev_touch.h>
#endif
#ifdef RESOURCES_LCD
#include <bus_lcd.h>
#include <dev_lcd.h>
#endif
#ifdef RESOURCES_USB
#include <bus_usb.h>
#include <dev_usb.h>
#ifdef RESOURCES_USB_HOST
#include <usb_host.h>
#endif
#endif
#ifdef RESOURCES_SERIAL
#include <bus_serial.h>
#include <dev_serial.h>
HardwareDevType InstallConsole(const char *bus_name, const char *drv_name, const char *dev_name);
HardwareDevType ObtainConsole(void);
#endif
#ifdef RESOURCES_I2C
#include <bus_i2c.h>
#include <dev_i2c.h>
#endif
#ifdef RESOURCES_WDT
#include <bus_wdt.h>
#include <dev_wdt.h>
#endif
#ifdef RESOURCES_SDIO
#include <bus_sdio.h>
#include <dev_sdio.h>
#endif
#ifdef RESOURCES_PIN
#include <bus_pin.h>
#include <dev_pin.h>
#endif
#ifdef RESOURCES_CAN
#include <bus_can.h>
#include <dev_can.h>
#endif
#ifdef RESOURCES_HWTIMER
#include <bus_hwtimer.h>
#include <dev_hwtimer.h>
#endif
#endif
+40
View File
@@ -0,0 +1,40 @@
/*
* 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 flash_spi.h
* @brief define spi-flash dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef FLASH_SPI_H
#define FLASH_SPI_H
#include <sfud_port.h>
#ifdef __cplusplus
extern "C" {
#endif
SpiFlashDeviceType SpiFlashInit(char *bus_name, char *dev_name, char *drv_name, char *flash_name);
uint32 SpiFlashRelease(SpiFlashDeviceType spi_flash_dev);
sfud_flash_t SpiFlashFind(char *flash_name);
#ifdef __cplusplus
}
#endif
#endif
+155
View File
@@ -0,0 +1,155 @@
/*
* 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 sd_spi.h
* @brief define spi-sd dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#ifndef SD_SPI_H
#define SD_SPI_H
#include <bus_spi.h>
#include <dev_spi.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SPI_SD_FREQUENCY 400000
#define SPI_SD_TIMEOUT_NUM 100
#define SD_CMD_RESPONE_LENGTH 5
#define SD_CMD_CSD_LENGTH 16
#define SD_BLOCK_LENGTH 512
#define SD_TIMEOUT(cnt, time) \
do \
{ \
cnt++; \
if(cnt >= time) \
{ \
KPrintf("SD_TMEOUT %s %d\n", __FUNCTION__, __LINE__); \
return ETIMEOUT; \
} \
}while(0)
typedef struct SpiSdDevice *SpiSdDeviceType;
typedef enum
{
SD_CMD_0 = 0,
SD_CMD_1,
SD_CMD_8 = 8,
SD_CMD_9,
SD_CMD_12 = 12,
SD_CMD_16 = 16,
SD_CMD_17,
SD_CMD_18,
SD_ACMD_23 = 23,
SD_CMD_24,
SD_CMD_25,
SD_ACMD_41 = 41,
SD_CMD_55 = 55,
SD_CMD_58 = 58,
}SdCmd;
typedef enum
{
SD_Respone_1 = 1,
SD_Respone_1b,
SD_Respone_2,
SD_Respone_3,
SD_Respone_7,
}SdRespone;
struct SdCmdParam
{
SdCmd sd_cmd_type;
uint8 sd_cmd_crc;
uint32 sd_cmd_args;
SdRespone sd_respone_type;
uint8 sd_respone_data[SD_CMD_RESPONE_LENGTH];
};
struct SdRespone1
{
uint8 sd_respone_r1;
};
struct SdRespone2
{
uint16 sd_respone_r2;
};
typedef enum
{
SD_TYPE_UNKNOW = 0,
SD_TYPE_MMC,
SD_TYPE_V1,
SD_TYPE_V2,
SD_TYPE_SDHC,
SD_TYPE_SDXC,
}SdType;
struct BlockDevParam
{
uint32 sector_num;
uint32 sector_bytes;
uint32 block_size;
};
struct CSDRegData
{
uint8 sd_csd_data[SD_CMD_CSD_LENGTH];
uint8 sd_csd_structure;
uint32 sd_csd_csize;
uint8 sd_csd_csize_multi;
uint8 sd_csd_readbl_len;
uint8 sd_csd_transpeed;
uint8 sd_csd_sectorsize;
uint32 sd_csd_capacity;
};
struct SdDevParam
{
SdType sd_type;
uint32 sd_spi_maxfreq;
struct BlockDevParam block_param;
struct CSDRegData csd_data;
};
struct SdDevDone
{
uint32 (*open) (void *dev);
uint32 (*close) (void *dev);
uint32 (*write) (void *dev, struct BusBlockWriteParam *write_param);
uint32 (*read) (void *dev, struct BusBlockReadParam *read_param);
};
struct SpiSdDevice
{
struct SpiHardwareDevice *spi_dev;
struct SdDevParam sd_param;
struct SpiHardwareDevice sd_dev;
};
SpiSdDeviceType SpiSdInit(struct Bus *bus, const char *dev_name, const char *drv_name, const char *sd_name);
#ifdef __cplusplus
}
#endif
#endif
+574
View File
@@ -0,0 +1,574 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2012-10-01 Yi Qiu first version
* 2013-04-26 aozima add DEVICEQUALIFIER support.
* 2017-11-15 ZYH fix ep0 transform error
*/
/**
* @file usb_common.h
* @brief define usb function and struct
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
/*************************************************
File name: usb_common.h
Description: define usb function and common struct
Others: take RT-Thread v4.0.2/components/drivers/include/drivers/usb_common.h for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
Modification:
1. define usb common configure, function and struct
2. support bus driver framework
*************************************************/
#ifndef USB_COMMON_H
#define USB_COMMON_H
#include <xiuos.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SYS_DEBUG_USB 0x00
#define USB_DYNAMIC 0x00
#define USB_CLASS_DEVICE 0x00
#define USB_CLASS_AUDIO 0x01
#define USB_CLASS_CDC 0x02
#define USB_CLASS_HID 0x03
#define USB_CLASS_PHYSICAL 0x05
#define USB_CLASS_IMAGE 0x06
#define USB_CLASS_PRINTER 0x07
#define USB_CLASS_MASS_STORAGE 0x08
#define USB_CLASS_HUB 0x09
#define USB_CLASS_CDC_DATA 0x0a
#define USB_CLASS_SMART_CARD 0x0b
#define USB_CLASS_SECURITY 0x0d
#define USB_CLASS_VIDEO 0x0e
#define USB_CLASS_HEALTHCARE 0x0f
#define USB_CLASS_DIAG_DEVICE 0xdc
#define USB_CLASS_WIRELESS 0xe0
#define USB_CLASS_MISC 0xef
#define USB_CLASS_APP_SPECIFIC 0xfe
#define USB_CLASS_VEND_SPECIFIC 0xff
#define USB_DESC_TYPE_DEVICE 0x01
#define USB_DESC_TYPE_CONFIGURATION 0x02
#define USB_DESC_TYPE_STRING 0x03
#define USB_DESC_TYPE_INTERFACE 0x04
#define USB_DESC_TYPE_ENDPOINT 0x05
#define USB_DESC_TYPE_DEVICEQUALIFIER 0x06
#define USB_DESC_TYPE_OTHERSPEED 0x07
#define USB_DESC_TYPE_IAD 0x0b
#define USB_DESC_TYPE_HID 0x21
#define USB_DESC_TYPE_REPORT 0x22
#define USB_DESC_TYPE_PHYSICAL 0x23
#define USB_DESC_TYPE_HUB 0x29
#define USB_DESC_LENGTH_DEVICE 0x12
#define USB_DESC_LENGTH_CONFIG 0x9
#define USB_DESC_LENGTH_IAD 0x8
#define USB_DESC_LENGTH_STRING 0x4
#define USB_DESC_LENGTH_INTERFACE 0x9
#define USB_DESC_LENGTH_ENDPOINT 0x7
#define USB_REQ_TYPE_STANDARD 0x00
#define USB_REQ_TYPE_CLASS 0x20
#define USB_REQ_TYPE_VENDOR 0x40
#define USB_REQ_TYPE_MASK 0x60
#define USB_REQ_TYPE_DIR_OUT 0x00
#define USB_REQ_TYPE_DIR_IN 0x80
#define USB_REQ_TYPE_DEVICE 0x00
#define USB_REQ_TYPE_INTERFACE 0x01
#define USB_REQ_TYPE_ENDPOINT 0x02
#define USB_REQ_TYPE_OTHER 0x03
#define USB_REQ_TYPE_RECIPIENT_MASK 0x1f
#define USB_FEATURE_ENDPOINT_HALT 0x00
#define USB_FEATURE_DEV_REMOTE_WAKEUP 0x01
#define USB_FEATURE_TEST_MODE 0x02
#define USB_REQ_GET_STATUS 0x00
#define USB_REQ_CLEAR_FEATURE 0x01
#define USB_REQ_SET_FEATURE 0x03
#define USB_REQ_SET_ADDRESS 0x05
#define USB_REQ_GET_DESCRIPTOR 0x06
#define USB_REQ_SET_DESCRIPTOR 0x07
#define USB_REQ_GET_CONFIGURATION 0x08
#define USB_REQ_SET_CONFIGURATION 0x09
#define USB_REQ_GET_INTERFACE 0x0A
#define USB_REQ_SET_INTERFACE 0x0B
#define USB_REQ_SYNCH_FRAME 0x0C
#define USB_REQ_SET_ENCRYPTION 0x0D
#define USB_REQ_GET_ENCRYPTION 0x0E
#define USB_REQ_RPIPE_ABORT 0x0E
#define USB_REQ_SET_HANDSHAKE 0x0F
#define USB_REQ_RPIPE_RESET 0x0F
#define USB_REQ_GET_HANDSHAKE 0x10
#define USB_REQ_SET_CONNECTION 0x11
#define USB_REQ_SET_SECURITY_DATA 0x12
#define USB_REQ_GET_SECURITY_DATA 0x13
#define USB_REQ_SET_WUSB_DATA 0x14
#define USB_REQ_LOOPBACK_DATA_WRITE 0x15
#define USB_REQ_LOOPBACK_DATA_READ 0x16
#define USB_REQ_SET_INTERFACE_DS 0x17
#define USB_STRING_LANGID_INDEX 0x00
#define USB_STRING_MANU_INDEX 0x01
#define USB_STRING_PRODUCT_INDEX 0x02
#define USB_STRING_SERIAL_INDEX 0x03
#define USB_STRING_CONFIG_INDEX 0x04
#define USB_STRING_INTERFACE_INDEX 0x05
#define USB_STRING_OS_INDEX 0x06
#define USB_STRING_MAX USB_STRING_OS_INDEX
#define USB_STRING_OS "MSFT100A"
#define USB_PID_OUT 0x01
#define USB_PID_ACK 0x02
#define USB_PID_DATA0 0x03
#define USB_PID_SOF 0x05
#define USB_PID_IN 0x09
#define USB_PID_NACK 0x0A
#define USB_PID_DATA1 0x0B
#define USB_PID_PRE 0x0C
#define USB_PID_SETUP 0x0D
#define USB_PID_STALL 0x0E
#define USB_EP_DESC_OUT 0x00
#define USB_EP_DESC_IN 0x80
#define USB_EP_DESC_NUM_MASK 0x0f
#define USB_EP_ATTR_CONTROL 0x00
#define USB_EP_ATTR_ISOC 0x01
#define USB_EP_ATTR_BULK 0x02
#define USB_EP_ATTR_INT 0x03
#define USB_EP_ATTR_TYPE_MASK 0x03
#define USB_EPNO_MASK 0x7f
#define USB_DIR_OUT 0x00
#define USB_DIR_IN 0x80
#define USB_DIR_INOUT 0x40
#define USB_DIR_MASK 0x80
#define ID_UNASSIGNED 0
#define ID_ASSIGNED 1
#define RH_GET_PORT_STATUS 0
#define RH_SET_PORT_STATUS 1
#define RH_CLEAR_PORT_FEATURE 2
#define RH_SET_PORT_FEATURE 3
#define USB_BUS_POWERED 0
#define USB_SELF_POWERED 1
#define USB_REMOTE_WAKEUP 1
#define USB_EP_HALT 0
#define PORT_FEAT_CONNECTION 0
#define PORT_FEAT_ENABLE 1
#define PORT_FEAT_SUSPEND 2
#define PORT_FEAT_OVER_CURRENT 3
#define PORT_FEAT_RESET 4
#define PORT_FEAT_POWER 8
#define PORT_FEAT_LOWSPEED 9
#define PORT_FEAT_HIGHSPEED 10
#define PORT_FEAT_C_CONNECTION 16
#define PORT_FEAT_C_ENABLE 17
#define PORT_FEAT_C_SUSPEND 18
#define PORT_FEAT_C_OVER_CURRENT 19
#define PORT_FEAT_C_RESET 20
#define PORT_CCS 0x00000001UL
#define PORT_PES 0x00000002UL
#define PORT_PSS 0x00000004UL
#define PORT_POCI 0x00000008UL
#define PORT_PRS 0x00000010UL
#define PORT_PPS 0x00000100UL
#define PORT_LSDA 0x00000200UL
#define PORT_CCSC 0x00010000UL
#define PORT_PESC 0x00020000UL
#define PORT_PSSC 0x00040000UL
#define PORT_POCIC 0x00080000UL
#define PORT_PRSC 0x00100000UL
#define HUB_STATUS_LOCAL_POWER 0x0001
#define HUB_STATUS_OVERCURRENT 0x0002
#define HUB_CHANGE_LOCAL_POWER 0x0001
#define HUB_CHANGE_OVERCURRENT 0x0002
#define USB_EP_ATTR(attr) (attr & USB_EP_ATTR_TYPE_MASK)
#define USB_EP_DESC_NUM(addr) (addr & USB_EP_DESC_NUM_MASK)
#define USB_EP_DIR(addr) ((addr & USB_DIR_MASK)>>7)
#define HID_REPORT_ID_KEYBOARD1 1
#define HID_REPORT_ID_KEYBOARD2 2
#define HID_REPORT_ID_KEYBOARD3 3
#define HID_REPORT_ID_KEYBOARD4 7
#define HID_REPORT_ID_MEDIA 4
#define HID_REPORT_ID_GENERAL 5
#define HID_REPORT_ID_MOUSE 6
#ifndef USB_TIMEOUT_BASIC
#define USB_TIMEOUT_BASIC (TICK_PER_SECOND)
#endif
#ifndef USB_TIMEOUT_LONG
#define USB_TIMEOUT_LONG (TICK_PER_SECOND * 5)
#endif
#ifndef USB_DEBOUNCE_TIME
#define USB_DEBOUNCE_TIME (TICK_PER_SECOND / 5)
#endif
#define uswap_32(x) \
((((x) & 0xff000000) >> 24) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24))
#define Uswap8(x) \
(((uint16)(*((uint8 *)(x)))) + \
(((uint16)(*(((uint8 *)(x)) + 1))) << 8))
typedef void (*FuncCallback) (void *context);
typedef enum
{
USB_STATE_NOTATTACHED = 0,
USB_STATE_ATTACHED,
USB_STATE_POWERED,
USB_STATE_RECONNECTING,
USB_STATE_UNAUTHENTICATED,
USB_STATE_DEFAULT,
USB_STATE_ADDRESS,
USB_STATE_CONFIGURED,
USB_STATE_SUSPENDED
}UdeviceStatePointer;
typedef enum
{
STAGE_IDLE,
STAGE_SETUP,
STAGE_STATUS_IN,
STAGE_STATUS_OUT,
STAGE_DIN,
STAGE_DOUT
} Uep0StagePointer;
#pragma pack(1)
struct UsbDescriptor
{
uint8 bLength;
uint8 type;
};
typedef struct UsbDescriptor* UdescPointer;
struct UdeviceDescriptor
{
uint8 bLength;
uint8 type;
uint16 bcdUSB;
uint8 bDeviceClass;
uint8 bDeviceSubClass;
uint8 bDeviceProtocol;
uint8 bMaxPacketSize0;
uint16 idVendor;
uint16 idProduct;
uint16 bcdDevice;
uint8 iManufacturer;
uint8 iProduct;
uint8 iSerialNumber;
uint8 bNumConfigurations;
};
typedef struct UdeviceDescriptor* UdevDescPointer;
struct UconfigDescriptor
{
uint8 bLength;
uint8 type;
uint16 wTotalLength;
uint8 bNumInterfaces;
uint8 bConfigurationValue;
uint8 iConfiguration;
uint8 bmAttributes;
uint8 MaxPower;
uint8 data[256];
};
typedef struct UconfigDescriptor* UcfgDescPointer;
struct UinterfaceDescriptor
{
uint8 bLength;
uint8 type;
uint8 bInterfaceNumber;
uint8 bAlternateSetting;
uint8 bNumEndpoints;
uint8 bInterfaceClass;
uint8 bInterfaceSubClass;
uint8 bInterfaceProtocol;
uint8 iInterface;
};
typedef struct UinterfaceDescriptor* UintfDescPointer;
struct UiadDescriptor
{
uint8 bLength;
uint8 bDescriptorType;
uint8 bFirstInterface;
uint8 bInterfaceCount;
uint8 bFunctionClass;
uint8 bFunctionSubClass;
uint8 bFunctionProtocol;
uint8 iFunction;
};
typedef struct UiadDescriptor* UiadDescPointer;
struct UendpointDescriptor
{
uint8 bLength;
uint8 type;
uint8 bEndpointAddress;
uint8 bmAttributes;
uint16 wMaxPacketSize;
uint8 bInterval;
};
typedef struct UendpointDescriptor* UepDescPointer;
struct UstringDescriptor
{
uint8 bLength;
uint8 type;
uint8 String[64];
};
typedef struct UstringDescriptor* UstrDescPointer;
struct UhubDescriptor
{
uint8 length;
uint8 type;
uint8 NumPorts;
uint16 characteristics;
uint8 PwronToGood;
uint8 current;
uint8 removable[8];
uint8 PwrCtl[8];
};
typedef struct UhubDescriptor* UhubDescPointer;
struct UsbQualifierDescriptor
{
uint8 bLength;
uint8 bDescriptorType;
uint16 bcdUSB;
uint8 bDeviceClass;
uint8 bDeviceSubClass;
uint8 bDeviceProtocol;
uint8 bMaxPacketSize0;
uint8 bNumConfigurations;
uint8 bRESERVED;
} __attribute__ ((packed));
struct UsbOsHeaderCompIdDescriptor
{
uint32 dwLength;
uint16 bcdVersion;
uint16 wIndex;
uint8 bCount;
uint8 reserved[7];
};
typedef struct UsbOsHeaderCompIdDescriptor * UsbOsHeaderDescPointer;
struct UsbOsFunctionCompIdDescriptor
{
DoubleLinklistType list;
uint8 bFirstInterfaceNumber;
uint8 reserved1;
uint8 compatibleID[8];
uint8 subCompatibleID[8];
uint8 reserved2[6];
};
typedef struct UsbOsFunctionCompIdDescriptor * UsbOsFuncCompIdDescPointer;
struct UsbOsCompIdDescriptor
{
struct UsbOsHeaderCompIdDescriptor HeadDesc;
DoubleLinklistType FuncDesc;
};
typedef struct UsbOsCompIdDescriptor * UsbOsCompIdDescPointer;
struct UsbOsPropertyHeader
{
uint32 dwLength;
uint16 bcdVersion;
uint16 wIndex;
uint16 wCount;
};
typedef struct UsbOsPropertyHeader * UsbOsPropertyHeaderPointer;
struct UsbOsProerty
{
uint32 dwSize;
uint32 dwPropertyDataType;
uint16 wPropertyNameLength;
const char * bPropertyName;
uint32 dwPropertyDataLength;
const char * bPropertyData;
};
typedef struct UsbOsProerty * UsbOsProertyPointer;
#define USB_OS_PROERTY_TYPE_REG_SZ 0x01UL
#define USB_OS_PROERTY_TYPE_REG_EXPAND_SZ 0x02UL
#define USB_OS_PROERTY_TYPE_REG_BINARY 0x03UL
#define USB_OS_PROERTY_TYPE_REG_DWORD_LITTLE_ENDIAN 0x04UL
#define USB_OS_PROERTY_TYPE_REG_DWORD_BIG_ENDIAN 0x05UL
#define USB_OS_PROERTY_TYPE_REG_LINK 0x06UL
#define USB_OS_PROERTY_TYPE_REG_MULTI_SZ 0x07UL
#define USB_OS_PROERTY_DESC(PropertyDataType,PropertyName,PropertyData) \
{\
.dwSize = sizeof(struct UsbOsProerty)-sizeof(const char *)*2\
+sizeof(PropertyName)*2+sizeof(PropertyData)*2,\
.dwPropertyDataType = PropertyDataType,\
.wPropertyNameLength = sizeof(PropertyName)*2,\
.bPropertyName = PropertyName,\
.dwPropertyDataLength = sizeof(PropertyData)*2,\
.bPropertyData = PropertyData\
}
#ifndef HID_SUB_DESCRIPTOR_MAX
#define HID_SUB_DESCRIPTOR_MAX 1
#endif
struct UhidDescriptor
{
uint8 bLength;
uint8 type;
uint16 bcdHID;
uint8 bCountryCode;
uint8 bNumDescriptors;
struct HidDescriptorList
{
uint8 type;
uint16 wLength;
}Descriptor[HID_SUB_DESCRIPTOR_MAX];
};
typedef struct UhidDescriptor* UhidDescPointer;
struct HidReport
{
uint8 ReportId;
uint8 report[63];
uint8 size;
};
typedef struct HidReport* HidReportPointer;
extern void HIDReportReceived(HidReportPointer report);
struct urequest
{
uint8 RequestType;
uint8 bRequest;
uint16 wValue;
uint16 wIndex;
uint16 wLength;
};
typedef struct urequest* UreqPointer;
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#define USBREQ_GET_MAX_LUN 0xfe
#define USBREQ_MASS_STORAGE_RESET 0xff
#define SIZEOF_CSW 0x0d
#define SIZEOF_CBW 0x1f
#define SIZEOF_INQUIRY_CMD 0x24
#define SIZEOF_MODE_SENSE_6 0x4
#define SIZEOF_READ_CAPACITIES 0xc
#define SIZEOF_READ_CAPACITY 0x8
#define SIZEOF_REQUEST_SENSE 0x12
#define CBWFLAGS_DIR_M 0x80
#define CBWFLAGS_DIR_IN 0x80
#define CBWFLAGS_DIR_OUT 0x00
#define SCSI_TEST_UNIT_READY 0x00
#define SCSI_REQUEST_SENSE 0x03
#define SCSI_INQUIRY_CMD 0x12
#define SCSI_ALLOW_REMOVAL 0x1e
#define SCSI_MODE_SENSE_6 0x1a
#define SCSI_START_STOP 0x1b
#define SCSI_READ_CAPACITIES 0x23
#define SCSI_READ_CAPACITY 0x25
#define SCSI_READ_10 0x28
#define SCSI_WRITE_10 0x2a
#define SCSI_VERIFY_10 0x2f
#define CBW_SIGNATURE 0x43425355
#define CSW_SIGNATURE 0x53425355
#define CBW_TAG_VALUE 0x12345678
struct UstorageCbw
{
uint32 signature;
uint32 tag;
uint32 XferLen;
uint8 dflags;
uint8 lun;
uint8 CbLen;
uint8 cb[16];
};
typedef struct UstorageCbw* UstorageCbwPointer;
struct UstorageCsw
{
uint32 signature;
uint32 tag;
int32 DataReside;
uint8 status;
};
typedef struct UstorageCsw* UstorageCswPointer;
#pragma pack()
#ifndef USBD_THREAD_STACK_SZ
#define USBD_THREAD_STACK_SZ 512
#endif
#ifndef USBD_THREAD_PRIO
#define USBD_THREAD_PRIO 8
#endif
#ifdef __cplusplus
}
#endif
#endif
+283
View File
@@ -0,0 +1,283 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-3-12 Yi Qiu first version
*/
/**
* @file usb_host.h
* @brief define usb host function and struct
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
/*************************************************
File name: usb_host.h
Description: define usb host function and struct
Others: take RT-Thread v4.0.2/components/drivers/include/drivers/usb_host.h for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
Modification:
1. define usb host configure, function and struct
2. support bus driver framework
*************************************************/
#ifndef USB_HOST_H
#define USB_HOST_H
#include <xiuos.h>
#include <usb_common.h>
#ifdef __cplusplus
extern "C" {
#endif
#define USB_MAX_DEVICE 0x20
#define USB_MAX_INTERFACE 0x08
#define USB_HUB_PORT_NUM 0x04
#define SIZEOF_USB_REQUEST 0x08
#define DEV_STATUS_IDLE 0x00
#define DEV_STATUS_BUSY 0x01
#define DEV_STATUS_ERROR 0x02
#define UPIPE_STATUS_OK 0x00
#define UPIPE_STATUS_STALL 0x01
#define UPIPE_STATUS_ERROR 0x02
#define USBH_PID_SETUP 0x00
#define USBH_PID_DATA 0x01
struct uhcd;
struct uhintf;
struct uhub;
struct upipe;
struct UclassDriver
{
DoubleLinklistType list;
int ClassCode;
int subclass_code;
x_err_t (*enable)(void* arg);
x_err_t (*disable)(void* arg);
void* UserData;
};
typedef struct UclassDriver* UcdPointer;
struct uprotocal
{
DoubleLinklistType list;
int ProId;
x_err_t (*init)(void* arg);
x_err_t (*callback)(void* arg);
};
typedef struct uprotocal* UprotocalPointer;
struct uinstance
{
struct UdeviceDescriptor DevDesc;
UcfgDescPointer CfgDesc;
struct uhcd *hcd;
struct upipe * PipeEp0Out;
struct upipe * PipeEp0In;
DoubleLinklistType pipe;
uint8 status;
uint8 type;
uint8 index;
uint8 address;
uint8 speed;
uint8 MaxPacketSize;
uint8 port;
struct uhub* parent_hub;
struct uhintf* intf[USB_MAX_INTERFACE];
};
typedef struct uinstance* UinstPointer;
struct uhintf
{
struct uinstance* device;
UintfDescPointer IntfDesc;
UcdPointer drv;
void *UserData;
};
struct upipe
{
DoubleLinklistType list;
uint8 pipe_index;
uint32 status;
struct UendpointDescriptor ep;
UinstPointer inst;
FuncCallback callback;
void* UserData;
};
typedef struct upipe* upipe_t;
struct uhub
{
struct UhubDescriptor HubDesc;
uint8 NumPorts;
uint32 PortStatus[USB_HUB_PORT_NUM];
struct uinstance* child[USB_HUB_PORT_NUM];
x_bool IsRoothub;
uint8 buffer[8];
struct uinstance* self;
struct uhcd *hcd;
};
typedef struct uhub* UhubPointer;
struct uhcd_ops
{
x_err_t (*reset_port) (uint8 port);
int (*pipe_xfer) (upipe_t pipe, uint8 token, void* buffer, int nbytes, int timeout);
x_err_t (*open_pipe) (upipe_t pipe);
x_err_t (*close_pipe) (upipe_t pipe);
};
typedef struct uhcd_ops* uhcd_ops_t;
struct uhcd
{
uhcd_ops_t ops;
uint8 NumPorts;
UhubPointer roothub;
};
typedef struct uhcd* UhcdPointer;
enum uhost_msg_type
{
USB_MSG_CONNECT_CHANGE,
USB_MSG_CALLBACK,
};
typedef enum uhost_msg_type uhost_msg_type;
struct UhostMsg
{
uhost_msg_type type;
union
{
struct uhub* hub;
struct
{
FuncCallback function;
void *context;
}cb;
}content;
};
typedef struct UhostMsg* uhost_msg_t;
/* usb host system interface */
x_err_t UsbHostInit(struct uhcd *hcd);
void UsbhHubInit(struct uhcd *hcd);
/* usb host core interface */
struct uinstance* UsbhAllocInstance(UhcdPointer uhcd);
x_err_t UsbhAttatchInstance(struct uinstance* device);
x_err_t UsbhDetachInstance(struct uinstance* device);
x_err_t UsbhGetDescriptor(struct uinstance* device, uint8 type, void* buffer, int nbytes);
x_err_t UsbhSetConfigure(struct uinstance* device, int config);
x_err_t UsbhSetAddress(struct uinstance* device);
x_err_t UsbhSetInterface(struct uinstance* device, int intf);
x_err_t UsbhClearFeature(struct uinstance* device, int endpoint, int feature);
x_err_t UsbhGetInterfaceDescriptor(UcfgDescPointer CfgDesc, int num, UintfDescPointer* IntfDesc);
x_err_t UsbhGetEndpointDescriptor(UintfDescPointer IntfDesc, int num, UepDescPointer* EpDesc);
/* usb class driver interface */
x_err_t UsbhClassDriverInit(void);
x_err_t UsbhClassDriverRegister(UcdPointer drv);
x_err_t UsbhClassDriverUnregister(UcdPointer drv);
x_err_t UsbhClassDriverEnable(UcdPointer drv, void* args);
x_err_t UsbhClassDriverDisable(UcdPointer drv, void* args);
UcdPointer UsbhClassDriverFind(int ClassCode, int subclass_code);
/* usb class driver implement */
UcdPointer UsbhClassDriverHub(void);
UcdPointer UsbhClassDriverStorage(void);
/* usb hub interface */
x_err_t UsbhHubGetDescriptor(struct uinstance* device, uint8 *buffer,
x_size_t size);
x_err_t UsbhHubGetStatus(struct uinstance* device, uint32* buffer);
x_err_t UsbhHubGetPortStatus(UhubPointer uhub, uint16 port,
uint32* buffer);
x_err_t UsbhHubClearPortFeature(UhubPointer uhub, uint16 port,
uint16 feature);
x_err_t UsbhHubSetPortFeature(UhubPointer uhub, uint16 port,
uint16 feature);
x_err_t UsbhHubResetPort(UhubPointer uhub, uint16 port);
x_err_t UsbhEventSignal(struct UhostMsg* msg);
void UsbhRootHubConnectHandler(struct uhcd *hcd, uint8 port, x_bool isHS);
void UsbhRootHubDisconnectHandler(struct uhcd *hcd, uint8 port);
/* usb host controller driver interface */
static __inline x_err_t usb_instance_add_pipe(UinstPointer inst, upipe_t pipe)
{
NULL_PARAM_CHECK(inst);
NULL_PARAM_CHECK(pipe);
DoubleLinkListInsertNodeBefore(&inst->pipe, &pipe->list);
return EOK;
}
static __inline upipe_t UsbInstanceFindPipe(UinstPointer inst,uint8 ep_address)
{
DoubleLinklistType * l;
for(l = inst->pipe.node_next;l != &inst->pipe;l = l->node_next)
{
if(SYS_DOUBLE_LINKLIST_ENTRY(l,struct upipe,list)->ep.bEndpointAddress == ep_address)
{
return SYS_DOUBLE_LINKLIST_ENTRY(l,struct upipe,list);
}
}
return NONE;
}
static __inline x_err_t UsbHcdAllocPipe(UhcdPointer hcd, upipe_t* pipe, UinstPointer inst, UepDescPointer ep)
{
*pipe = (upipe_t)x_malloc(sizeof(struct upipe));
if(*pipe == NONE)
{
return ERROR;
}
memset(*pipe,0,sizeof(struct upipe));
(*pipe)->inst = inst;
memcpy(&(*pipe)->ep,ep,sizeof(struct UendpointDescriptor));
return hcd->ops->open_pipe(*pipe);
}
static __inline void UsbPipeAddCallback(upipe_t pipe, FuncCallback callback)
{
pipe->callback = callback;
}
static __inline x_err_t UsbHcdFreePipe(UhcdPointer hcd, upipe_t pipe)
{
NULL_PARAM_CHECK(pipe);
hcd->ops->close_pipe(pipe);
x_free(pipe);
return EOK;
}
int UsbHcdPipeXfer(UhcdPointer hcd, upipe_t pipe, void* buffer, int nbytes, int timeout);
static __inline int UsbHcdSetupXfer(UhcdPointer hcd, upipe_t pipe, UreqPointer setup, int timeout)
{
return hcd->ops->pipe_xfer(pipe, USBH_PID_SETUP, (void *)setup, 8, timeout);
}
#ifdef __cplusplus
}
#endif
#endif