support Ch376 for xidatong-riscv64 in XiZi Kernel

it is OK
This commit is contained in:
xuedongliang 2022-10-07 11:30:00 +08:00
commit 0b4a3ec960
9 changed files with 350 additions and 20 deletions

View File

@ -39,9 +39,9 @@ menu "xidatong-riscv64 feature"
config MOUNT_SDCARD
bool "mount cd card"
default n
select BSP_USING_SPI
select BSP_USING_SPI1
select RESOURCES_SPI_SD
config MOUNT_USB
bool "mount usb"
default n
endmenu
endmenu

View File

@ -58,32 +58,42 @@ extern int IoConfigInit(void);
extern int HwI2cInit(void);
extern int HwTouchInit(void);
extern int HwCh438Init(void);
extern int HwCh376Init(void);
#if defined(FS_VFS) && defined (MOUNT_SDCARD)
#ifdef FS_CH376
#include <iot-vfs.h>
#include <sd_spi.h>
extern SpiSdDeviceType SpiSdInit(struct Bus *bus, const char *dev_name, const char *drv_name, const char *sd_name);
#ifdef MOUNT_USB
/**
* @description: Mount USB
* @return 0
*/
int MountUSB(void)
{
if (MountFilesystem(USB_BUS_NAME, USB_DEVICE_NAME, USB_DRIVER_NAME, FSTYPE_CH376, "/") == 0)
KPrintf("usb mount to '/'\n");
else
KPrintf("usb mount to '/' failed!\n");
return 0;
}
#endif
#ifdef MOUNT_SDCARD
/**
* @description: Mount SD card
* @return 0
*/
int MountSDCard(void)
int MountSDCard(void)
{
struct Bus *spi_bus;
spi_bus = BusFind(SPI_BUS_NAME_1);
if (NONE == SpiSdInit(spi_bus, SPI_1_DEVICE_NAME_0, SPI_1_DRV_NAME, SPI_SD_NAME)) {
KPrintf("MountSDCard SpiSdInit error!\n");
return 0;
}
if (MountFilesystem(SDIO_BUS_NAME,SDIO_DEVICE_NAME ,SDIO_DRIVER_NAME , FSTYPE_CH376, "/") == 0)
KPrintf("sd card mount to '/'\n");
else
KPrintf("sd card mount to '/' failed!\n");
if (EOK == MountFilesystem(SPI_BUS_NAME_1, SPI_SD_NAME, SPI_1_DRV_NAME, FSTYPE_FATFS, "/"))
KPrintf("SPI SD card fatfs mounted\n");
return 0;
}
#endif
#endif
void InitBss(void)
{
@ -164,6 +174,12 @@ struct InitSequenceDesc _board_init[] =
#ifdef BSP_USING_I2C
{ "hw_i2c", HwI2cInit },
#endif
#ifdef BSP_USING_SDIO
{ "hw_sdio", HwCh376Init},
#endif
#ifdef BSP_USING_USB
{ "hw_usb", HwCh376Init},
#endif
#ifdef BSP_USING_TOUCH
{"touch", HwTouchInit },
#endif

View File

@ -1,3 +1,12 @@
menuconfig BSP_USING_CH376
bool "Using CH376 device"
default n
select FS_VFS
select FS_CH376
if BSP_USING_CH376
source "$BSP_DIR/third_party_driver/ch376/Kconfig"
endif
menuconfig BSP_USING_CH438
bool "Using CH438 device"
default n

View File

@ -1,5 +1,9 @@
SRC_FILES := sleep.c
ifeq ($(CONFIG_BSP_USING_CH376),y)
SRC_DIR += ch376
endif
ifeq ($(CONFIG_BSP_USING_CH438),y)
SRC_DIR += ch438
endif

View File

@ -0,0 +1,37 @@
menuconfig BSP_USING_SDIO
bool "Using CH376 SD card"
default n
select RESOURCES_SDIO
select MOUNT_SDCARD
if BSP_USING_SDIO
config SDIO_BUS_NAME
string "sdio bus name"
default "sdio"
config SDIO_DRIVER_NAME
string "sdio driver name"
default "sdio_drv"
config SDIO_DEVICE_NAME
string "sdio device name"
default "sdio_dev"
endif
menuconfig BSP_USING_USB
bool "Using CH376 USB"
default n
select RESOURCES_USB
select MOUNT_USB
if BSP_USING_USB
config USB_BUS_NAME
string "USB bus name"
default "usb"
config USB_DRIVER_NAME
string "USB driver name"
default "usb_drv"
config USB_DEVICE_NAME
string "USB device name"
default "usb_dev"
endif

View File

@ -0,0 +1,4 @@
SRC_FILES := connect_ch376.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,224 @@
/*
* 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 connect_ch376.c
* @brief support to register ch376 pointer and function
* @version 2.0
* @author AIIT XUOS Lab
* @date 2022-09-28
*/
#include <ch376fs.h>
#include <connect_ch376.h>
static struct HwCh376 ch376;
static uint32 Ch376Configure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
uint8 temp[2];
temp[0] = 0x57;
temp[1] = 0xab;
MdelayKTask(100);
struct BusBlockWriteParam write_param;
write_param.pos = 0;
write_param.buffer = (void *)temp;
write_param.size = 2;
BusDevWriteData(ch376.dev, &write_param);
write_param.pos = 0;
write_param.buffer = &configure_info->configure_cmd;
write_param.size = 1;
BusDevWriteData(ch376.dev, &write_param);
return EOK;
}
static int HwCh376RxInd(void *dev, x_size_t length)
{
ch376.msg_len += length;
KSemaphoreAbandon(ch376.sem);
return EOK;
}
static uint32 Ch376Open(void *dev)
{
NULL_PARAM_CHECK(dev);
ch376.sem = KSemaphoreCreate(0);
if (ch376.sem < 0) {
KPrintf("CH376 open fail\n");
return -ERROR;
}
struct Bus *bus = BusFind(SERIAL_BUS_NAME_3);
struct Driver *bus_driver = BusFindDriver(bus, SERIAL_DRV_NAME_3);
ch376.dev = BusFindDevice(bus, SERIAL_3_DEVICE_NAME_0);
if (!ch376.dev) {
KPrintf("CH376 open fail\n");
return -ERROR;
}
struct SerialCfgParam serial_cfg;
memset(&serial_cfg, 0, sizeof(struct SerialCfgParam));
serial_cfg.data_cfg.serial_buffer_size = 512;
struct BusConfigureInfo cfg;
cfg.configure_cmd = OPE_INT;
cfg.private_data = &serial_cfg;
BusDrvConfigure(bus_driver, &cfg);
bus->match(bus_driver, ch376.dev);
struct SerialDevParam *serial_dev_param = (struct SerialDevParam *)ch376.dev->private_data;
serial_dev_param->serial_set_mode = SIGN_OPER_INT_RX;
BusDevOpen(ch376.dev);
BusDevRecvCallback(ch376.dev, HwCh376RxInd);
KPrintf("CH376 open done\n");
return EOK;
}
static uint32 Ch376Close(void *dev)
{
BusDevClose(ch376.dev);
KSemaphoreDelete(ch376.sem);
return EOK;
}
static uint32 Ch376Write(void *dev, struct BusBlockWriteParam *write_param)
{
if (EOK == BusDevWriteData(ch376.dev, write_param))
return EOK;
return -ERROR;
}
static uint32 Ch376Read(void *dev, struct BusBlockReadParam *read_param)
{
if (KSemaphoreObtain(ch376.sem, WAITING_FOREVER) == EOK) {
while(KSemaphoreObtain(ch376.sem, TICK_PER_SECOND) != -ETIMEOUT);
read_param->size = ch376.msg_len;
BusDevReadData(ch376.dev, read_param);
ch376.msg_len = 0;
}
return read_param->read_length;
}
#ifdef BSP_USING_SDIO
static struct SdioDevDone sdio_done =
{
Ch376Open,
Ch376Close,
Ch376Write,
Ch376Read,
};
#endif
#ifdef BSP_USING_USB
static struct UsbDevDone usb_done =
{
Ch376Open,
Ch376Close,
Ch376Write,
Ch376Read,
};
#endif
int HwCh376Init(void)
{
x_err_t ret = EOK;
#ifdef BSP_USING_SDIO
static struct SdioBus sdio_bus;
static struct SdioDriver sdio_drv;
static struct SdioHardwareDevice sdio_dev;
ret = SdioBusInit(&sdio_bus,SDIO_BUS_NAME );
if (ret != EOK) {
KPrintf("Sdio bus init error %d\n", ret);
return -ERROR;
}
sdio_drv.configure = &Ch376Configure;
ret = SdioDriverInit(&sdio_drv, SDIO_DRIVER_NAME);
if (ret != EOK) {
KPrintf("Sdio driver init error %d\n", ret);
return -ERROR;
}
ret = SdioDriverAttachToBus( SDIO_DRIVER_NAME, SDIO_BUS_NAME);
if (ret != EOK) {
KPrintf("Sdio driver attach error %d\n", ret);
return -ERROR;
}
sdio_dev.dev_done = &sdio_done;
ret = SdioDeviceRegister(&sdio_dev, SDIO_DEVICE_NAME);
if (ret != EOK) {
KPrintf("Sdio device register error %d\n", ret);
return -ERROR;
}
ret = SdioDeviceAttachToBus(SDIO_DEVICE_NAME, SDIO_BUS_NAME);
if (ret != EOK) {
KPrintf("Sdio device register error %d\n", ret);
return -ERROR;
}
#endif
#ifdef BSP_USING_USB
static struct UsbBus usb_bus;
static struct UsbDriver usb_drv;
static struct UsbHardwareDevice usb_dev;
ret = UsbBusInit(&usb_bus, USB_BUS_NAME);
if (ret != EOK) {
KPrintf("USB bus init error %d\n", ret);
return -ERROR;
}
usb_drv.configure = &Ch376Configure;
ret = UsbDriverInit(&usb_drv, USB_DRIVER_NAME);
if (ret != EOK) {
KPrintf("USB driver init error %d\n", ret);
return -ERROR;
}
ret = UsbDriverAttachToBus(USB_DRIVER_NAME, USB_BUS_NAME);
if (ret != EOK) {
KPrintf("USB driver attach error %d\n", ret);
return -ERROR;
}
usb_dev.dev_done = &usb_done;
ret = USBDeviceRegister(&usb_dev, NONE, USB_DEVICE_NAME);
if (ret != EOK) {
KPrintf("USB device register error %d\n", ret);
return -ERROR;
}
ret = USBDeviceAttachToBus(USB_DEVICE_NAME, USB_BUS_NAME);
if (ret != EOK) {
KPrintf("USB device register error %d\n", ret);
return -ERROR;
}
#endif
return ret;
}

View File

@ -71,8 +71,8 @@ static struct io_config
IOCONFIG(BSP_UART2_RXD_PIN, FUNC_UART2_RX),
#endif
#ifdef BSP_USING_UART3
IOCONFIG(BSP_UART3_TXD_PIN, FUNC_UART3_TX),
IOCONFIG(BSP_UART3_RXD_PIN, FUNC_UART3_RX),
IOCONFIG(BSP_UART3_TXD_PIN, FUNC_UART3_RX),
IOCONFIG(BSP_UART3_RXD_PIN, FUNC_UART3_TX),
#endif
#ifdef BSP_USING_I2C1
IOCONFIG(BSP_I2C_SDA, FUNC_GPIO3),

View File

@ -0,0 +1,36 @@
/*
* 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 connect_ch376.h
* @brief define xidatong-riscv64 ch376 function and struct
* @version 2.0
* @author AIIT XUOS Lab
* @date 2022-09-28
*/
#ifndef CONNECT_CH376_H
#define CONNECT_CH376_H
#include <device.h>
struct HwCh376
{
HardwareDevType dev;
x_size_t msg_len;
int sem;
KTaskDescriptorType task;
};
int HwCh376Init(void);
#endif