change esp8266 to wifi, ec200 to lte, w5500 to enet

This commit is contained in:
wlyu 2022-09-16 19:29:52 +08:00
parent 95667a74d2
commit 50c21fe298
23 changed files with 704 additions and 758 deletions

View File

@ -129,9 +129,9 @@ endmenu
endif # BSP_USING_CH438 endif # BSP_USING_CH438
menuconfig BSP_USING_EC200 menuconfig BSP_USING_LTE
depends on U16550_UART2 depends on U16550_UART2
bool "Using EC200 device" bool "Using LTE device"
default n default n
menuconfig BSP_USING_CAN menuconfig BSP_USING_CAN
@ -139,13 +139,13 @@ menuconfig BSP_USING_CAN
bool "Using CAN device" bool "Using CAN device"
default n default n
menuconfig BSP_USING_ESP8266 menuconfig BSP_USING_WIFI
depends on U16550_UART2 depends on U16550_UART2
bool "Using ESP8266 device" bool "Using WIFI device"
default n default n
menuconfig BSP_USING_W5500 menuconfig BSP_USING_ENET
bool "Using W5500 device" bool "Using ENET device"
default n default n
endif # ARCH_BOARD_XIDATONG_RISCV64 endif # ARCH_BOARD_XIDATONG_RISCV64

View File

@ -58,4 +58,4 @@ CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORK=y
CONFIG_DEV_GPIO=y CONFIG_DEV_GPIO=y
CONFIG_BOARDCTL_RESET=y CONFIG_BOARDCTL_RESET=y
CONFIG_BSP_USING_W5500=y CONFIG_BSP_USING_ENET=y

View File

@ -1,78 +0,0 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_NSH_DISABLE_LOSMART is not set
# CONFIG_STANDARD_SERIAL is not set
CONFIG_ADD_NUTTX_FETURES=y
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="xidatong-riscv64"
CONFIG_ARCH_BOARD_XIDATONG_RISCV64=y
CONFIG_ARCH_CHIP="k210"
CONFIG_ARCH_CHIP_K210=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BINFMT_DISABLE=y
CONFIG_BOARD_LOOPSPERMSEC=46000
CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_DISABLE_IFUPDOWN=y
CONFIG_NSH_DISABLE_MKDIR=y
CONFIG_NSH_DISABLE_RM=y
CONFIG_NSH_DISABLE_RMDIR=y
CONFIG_NSH_DISABLE_UMOUNT=y
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=2097152
CONFIG_RAM_START=0x80400000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_CMD_HISTORY_LEN=100
CONFIG_READLINE_CMD_HISTORY_LINELEN=120
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_STACK_COLORATION=y
CONFIG_START_DAY=28
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=20
CONFIG_TESTING_GETPRIME=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SCHED_HPWORK=y
CONFIG_DEV_GPIO=y
CONFIG_BOARDCTL_RESET=y
CONFIG_U16550_UART=y
CONFIG_U16550_UART2=y
CONFIG_U16550_UART2_BASE=0x50220000
CONFIG_U16550_UART2_CLOCK=195000000
CONFIG_U16550_UART2_IRQ=39
CONFIG_U16550_UART2_BAUD=115200
CONFIG_U16550_UART2_PARITY=0
CONFIG_U16550_UART2_BITS=8
CONFIG_U16550_UART2_2STOP=0
CONFIG_U16550_UART2_RXBUFSIZE=256
CONFIG_U16550_UART2_TXBUFSIZE=256
CONFIG_U16550_NO_SERIAL_CONSOLE=y
CONFIG_U16550_SUPRESS_INITIAL_CONFIG=y
CONFIG_SERIAL_UART_ARCH_MMIO=y
CONFIG_U16550_REGINCR=4
CONFIG_U16550_REGWIDTH=32
CONFIG_U16550_ADDRWIDTH=32
CONFIG_BSP_USING_ESP8266=y

View File

@ -75,4 +75,4 @@ CONFIG_SERIAL_UART_ARCH_MMIO=y
CONFIG_U16550_REGINCR=4 CONFIG_U16550_REGINCR=4
CONFIG_U16550_REGWIDTH=32 CONFIG_U16550_REGWIDTH=32
CONFIG_U16550_ADDRWIDTH=32 CONFIG_U16550_ADDRWIDTH=32
CONFIG_BSP_USING_EC200=y CONFIG_BSP_USING_LTE=y

View File

@ -1,61 +0,0 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_NSH_DISABLE_LOSMART is not set
# CONFIG_STANDARD_SERIAL is not set
CONFIG_ADD_NUTTX_FETURES=y
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="xidatong-riscv64"
CONFIG_ARCH_BOARD_XIDATONG_RISCV64=y
CONFIG_ARCH_CHIP="k210"
CONFIG_ARCH_CHIP_K210=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BINFMT_DISABLE=y
CONFIG_BOARD_LOOPSPERMSEC=46000
CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_DISABLE_IFUPDOWN=y
CONFIG_NSH_DISABLE_MKDIR=y
CONFIG_NSH_DISABLE_RM=y
CONFIG_NSH_DISABLE_RMDIR=y
CONFIG_NSH_DISABLE_UMOUNT=y
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=2097152
CONFIG_RAM_START=0x80400000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_CMD_HISTORY_LEN=100
CONFIG_READLINE_CMD_HISTORY_LINELEN=120
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_STACK_COLORATION=y
CONFIG_START_DAY=28
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=20
CONFIG_TESTING_GETPRIME=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SCHED_HPWORK=y
CONFIG_DEV_GPIO=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BSP_USING_W5500=y

View File

@ -75,4 +75,4 @@ CONFIG_SERIAL_UART_ARCH_MMIO=y
CONFIG_U16550_REGINCR=4 CONFIG_U16550_REGINCR=4
CONFIG_U16550_REGWIDTH=32 CONFIG_U16550_REGWIDTH=32
CONFIG_U16550_ADDRWIDTH=32 CONFIG_U16550_ADDRWIDTH=32
CONFIG_BSP_USING_ESP8266=y CONFIG_BSP_USING_WIFI=y

View File

@ -50,20 +50,20 @@ ifeq ($(CONFIG_BSP_USING_CH376),y)
CSRCS += k210_ch376.c ch376_demo.c CSRCS += k210_ch376.c ch376_demo.c
endif endif
ifeq ($(CONFIG_BSP_USING_EC200),y) ifeq ($(CONFIG_BSP_USING_LTE),y)
CSRCS += k210_ec200.c ec200_demo.c CSRCS += k210_lte.c lte_demo.c
endif endif
ifeq ($(CONFIG_BSP_USING_CAN),y) ifeq ($(CONFIG_BSP_USING_CAN),y)
CSRCS += k210_can.c can_demo.c CSRCS += k210_can.c can_demo.c
endif endif
ifeq ($(CONFIG_BSP_USING_ESP8266),y) ifeq ($(CONFIG_BSP_USING_WIFI),y)
CSRCS += k210_esp8266.c esp8266_demo.c CSRCS += k210_wifi.c wifi_demo.c
endif endif
ifeq ($(CONFIG_BSP_USING_W5500),y) ifeq ($(CONFIG_BSP_USING_ENET),y)
CSRCS += k210_w5500.c w5500.c w5500_demo.c CSRCS += k210_enet.c w5500.c enet_demo.c
endif endif
include $(TOPDIR)/boards/Board.mk include $(TOPDIR)/boards/Board.mk

View File

@ -11,19 +11,19 @@
*/ */
/** /**
* @file w5500_demo.c * @file enet_demo.c
* @brief xidatong-riscv64 w5500_demo.c * @brief xidatong-riscv64 enet_demo.c
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022.08.22 * @date 2022.9.16
*/ */
#include "k210_w5500.h" #include "k210_enet.h"
#include "w5500.h" #include "w5500.h"
#define w_print printf #define w_print printf
void W5500Demo(void) void EnetDemo(void)
{ {
w_print("start %s\n", __func__); w_print("start %s\n", __func__);
w5500_net_test(); w5500_net_test();

View File

@ -45,20 +45,20 @@
# include "k210_ch376.h" # include "k210_ch376.h"
#endif #endif
#ifdef CONFIG_BSP_USING_EC200 #ifdef CONFIG_BSP_USING_LTE
# include "k210_ec200.h" # include "k210_lte.h"
#endif #endif
#ifdef CONFIG_BSP_USING_CAN #ifdef CONFIG_BSP_USING_CAN
# include "k210_can.h" # include "k210_can.h"
#endif #endif
#ifdef CONFIG_BSP_USING_ESP8266 #ifdef CONFIG_BSP_USING_WIFI
# include "k210_esp8266.h" # include "k210_wifi.h"
#endif #endif
#ifdef CONFIG_BSP_USING_W5500 #ifdef CONFIG_BSP_USING_ENET
# include "k210_w5500.h" # include "k210_enet.h"
#endif #endif
#include "k210_sysctl.h" #include "k210_sysctl.h"
@ -114,11 +114,11 @@ int k210_bringup(void)
board_ch376_initialize(); board_ch376_initialize();
#endif #endif
#ifdef CONFIG_BSP_USING_EC200 #ifdef CONFIG_BSP_USING_LTE
k210_sysctl_init(); k210_sysctl_init();
sysctl_clock_enable(SYSCTL_CLOCK_UART2); sysctl_clock_enable(SYSCTL_CLOCK_UART2);
sysctl_reset(SYSCTL_RESET_UART2); sysctl_reset(SYSCTL_RESET_UART2);
board_ec200_initialize(); board_lte_initialize();
#endif #endif
#ifdef CONFIG_BSP_USING_CAN #ifdef CONFIG_BSP_USING_CAN
@ -128,16 +128,16 @@ int k210_bringup(void)
board_can_initialize(); board_can_initialize();
#endif #endif
#ifdef CONFIG_BSP_USING_ESP8266 #ifdef CONFIG_BSP_USING_WIFI
k210_sysctl_init(); k210_sysctl_init();
sysctl_clock_enable(SYSCTL_CLOCK_UART3); sysctl_clock_enable(SYSCTL_CLOCK_UART3);
sysctl_reset(SYSCTL_RESET_UART3); sysctl_reset(SYSCTL_RESET_UART3);
board_esp8266_initialize(); board_wifi_initialize();
#endif #endif
#ifdef CONFIG_BSP_USING_W5500 #ifdef CONFIG_BSP_USING_ENET
k210_sysctl_init(); k210_sysctl_init();
board_w5500_initialize(); board_enet_initialize();
#endif #endif
return ret; return ret;

View File

@ -11,8 +11,8 @@
*/ */
/** /**
* @file k210_w5500.c * @file k210_enet.c
* @brief support to register w5500 pointer and function * @brief support to register enet pointer and function
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022-9-14 * @date 2022-9-14
@ -22,18 +22,18 @@
#include <nuttx/wqueue.h> #include <nuttx/wqueue.h>
#include <sys/poll.h> #include <sys/poll.h>
#include "ctype.h" #include "ctype.h"
#include "k210_w5500.h" #include "k210_enet.h"
#define w_print printf #define w_print printf
/******************************************************************************/ /******************************************************************************/
struct w5500_dev_s g_w5500dev; struct enet_dev_s g_enetdev;
static char *w5500_dev_name = "/dev/w5500"; static char *enet_dev_name = "/dev/enet";
/******************************************************************************/ /******************************************************************************/
void w5500_print_buf(int size, uint8_t *buf) void enet_print_buf(int size, uint8_t *buf)
{ {
char ch[10] = {0}; char ch[10] = {0};
char temp[256] = {0}; char temp[256] = {0};
@ -63,65 +63,51 @@ void w5500_print_buf(int size, uint8_t *buf)
} }
} }
if(size) if(size)
w_print("w5500 read %d data: %s\n", size, temp); w_print("enet read %d data: %s\n", size, temp);
} }
//int w5500_read_buf(void *dev, int *size, uint8_t *buf)
//{
// uart_dev_t *uart_dev = (uart_dev_t *)dev;
// int cur_size = uart_dev->recv.head - uart_dev->recv.tail;
// *size = *size > cur_size ? cur_size : *size;
// memcpy(buf, uart_dev->recv.buffer, *size);
// uart_dev->recv.head = uart_dev->recv.tail;
// w5500_print_buf(*size, buf);
// return *size;
//}
/**************************************************************************** /****************************************************************************
* Name: w5500_data_work * Name: enet_data_work
* *
* Description: * Description:
* thread task w5500_data_work * thread task enet_data_work
* *
****************************************************************************/ ****************************************************************************/
static FAR void w5500_data_work(FAR void *arg) static FAR void enet_data_work(FAR void *arg)
{ {
struct w5500_dev_s *w5500_dev = (struct w5500_dev_s *)arg; struct enet_dev_s *enet_dev = (struct enet_dev_s *)arg;
// uart_dev_t *uart_dev = w5500_dev->uart_dev; nxsem_wait(&enet_dev->waitsem);
nxsem_wait(&w5500_dev->waitsem); enet_dev->recv_size = ENET_RECV_BUF_SIZE;
w5500_dev->recv_size = W5500_RECV_BUF_SIZE; work_queue(HPWORK, &enet_dev->irqwork, enet_data_work, enet_dev, ENET_INCREMENT);
// w5500_read_buf(uart_dev, &w5500_dev->recv_size, w5500_dev->recv_buf); enetinfo("uart size %d ok!\n", enet_dev->recv_size);
work_queue(HPWORK, &w5500_dev->irqwork, w5500_data_work, w5500_dev, W5500_INCREMENT);
// w5500info("uart size %d ok!\n", w5500_dev->recv_size);
} }
static int w5500_bringup(struct w5500_dev_s *dev) static int enet_bringup(struct enet_dev_s *dev)
{ {
// struct w5500_dev_s *w5500_dev = &g_w5500dev;
dev->uart_fd = open(dev->dev_name, O_RDWR); dev->uart_fd = open(dev->dev_name, O_RDWR);
w5500info("open %s fd = %d\n", dev->dev_name, dev->uart_fd); enetinfo("open %s fd = %d\n", dev->dev_name, dev->uart_fd);
work_queue(HPWORK, &dev->irqwork, w5500_data_work, dev, W5500_INCREMENT); work_queue(HPWORK, &dev->irqwork, enet_data_work, dev, ENET_INCREMENT);
return OK; return OK;
} }
static int w5500_write_config(struct w5500_dev_s *dev) static int enet_write_config(struct enet_dev_s *dev)
{ {
return OK; return OK;
} }
static int w5500_shutdown(struct w5500_dev_s *dev) static int enet_shutdown(struct enet_dev_s *dev)
{ {
close(dev->uart_fd); close(dev->uart_fd);
return OK; return OK;
} }
static int w5500_open(FAR struct file *filep) static int enet_open(FAR struct file *filep)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct w5500_dev_s *priv; FAR struct enet_dev_s *priv;
uint8_t ref_cnt; uint8_t ref_cnt;
@ -131,14 +117,14 @@ static int w5500_open(FAR struct file *filep)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct w5500_dev_s *)inode->i_private; priv = (FAR struct enet_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: nxsem_wait failed: %d\n", ret); eneterr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -158,20 +144,20 @@ static int w5500_open(FAR struct file *filep)
if(ref_cnt == 1) if(ref_cnt == 1)
{ {
ret = w5500_bringup(priv); ret = enet_bringup(priv);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: w5500_bringup failed: %d\n", ret); eneterr("ERROR: enet_bringup failed: %d\n", ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
ret = w5500_write_config(priv); ret = enet_write_config(priv);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: w5500_write_config failed: %d\n", ret); eneterr("ERROR: enet_write_config failed: %d\n", ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
@ -185,13 +171,13 @@ static int w5500_open(FAR struct file *filep)
} }
/**************************************************************************** /****************************************************************************
* Name: w5500_close * Name: enet_close
****************************************************************************/ ****************************************************************************/
static int w5500_close(FAR struct file *filep) static int enet_close(FAR struct file *filep)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct w5500_dev_s *priv; FAR struct enet_dev_s *priv;
int ret; int ret;
@ -199,14 +185,14 @@ static int w5500_close(FAR struct file *filep)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct w5500_dev_s *)inode->i_private; priv = (FAR struct enet_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: nxsem_wait failed: %d\n", ret); eneterr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -220,12 +206,12 @@ static int w5500_close(FAR struct file *filep)
} }
/* When the count decrements to zero, there are no further open references /* When the count decrements to zero, there are no further open references
* to the driver and it w5500 be uninitialized. * to the driver and it enet be uninitialized.
*/ */
if(priv->crefs == 0) if(priv->crefs == 0)
{ {
w5500_shutdown(priv); enet_shutdown(priv);
} }
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
@ -233,26 +219,26 @@ static int w5500_close(FAR struct file *filep)
} }
/**************************************************************************** /****************************************************************************
* Name: w5500_read * Name: enet_read
****************************************************************************/ ****************************************************************************/
static ssize_t w5500_read(FAR struct file *filep, FAR char *buffer, size_t len) static ssize_t enet_read(FAR struct file *filep, FAR char *buffer, size_t len)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct w5500_dev_s *priv; FAR struct enet_dev_s *priv;
int ret, buf_size = len; int ret, buf_size = len;
DEBUGASSERT(filep); DEBUGASSERT(filep);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct w5500_dev_s *)inode->i_private; priv = (FAR struct enet_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: nxsem_wait failed: %d\n", ret); eneterr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -264,42 +250,42 @@ static ssize_t w5500_read(FAR struct file *filep, FAR char *buffer, size_t len)
/**************************************************************************** /****************************************************************************
* Name: w5500_write * Name: enet_write
****************************************************************************/ ****************************************************************************/
static ssize_t w5500_write(FAR struct file *filep, FAR const char *buffer, size_t len) static ssize_t enet_write(FAR struct file *filep, FAR const char *buffer, size_t len)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct w5500_dev_s *priv; FAR struct enet_dev_s *priv;
int ret; int ret;
DEBUGASSERT(filep); DEBUGASSERT(filep);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct w5500_dev_s *)inode->i_private; priv = (FAR struct enet_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: nxsem_wait failed: %d\n", ret); eneterr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
ret = write(priv->uart_fd, buffer, len); ret = write(priv->uart_fd, buffer, len);
w5500info("write fd %d len %ld ret = %d\n", priv->uart_fd, len, ret); enetinfo("write fd %d len %ld ret = %d\n", priv->uart_fd, len, ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
/**************************************************************************** /****************************************************************************
* Name: w5500_ioctl * Name: enet_ioctl
****************************************************************************/ ****************************************************************************/
static int w5500_ioctl(FAR struct file *filep, int cmd, unsigned long arg) static int enet_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct w5500_dev_s *priv; FAR struct enet_dev_s *priv;
FAR uint32_t *ptr; FAR uint32_t *ptr;
int ret; int ret;
@ -308,14 +294,14 @@ static int w5500_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct w5500_dev_s *)inode->i_private; priv = (FAR struct enet_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: nxsem_wait failed: %d\n", ret); eneterr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -323,7 +309,7 @@ static int w5500_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
switch(cmd) switch(cmd)
{ {
case W5500IOC_SETFREQUENCY: /* arg: Pointer to uint32_t frequency value */ case ENETIOC_SETFREQUENCY: /* arg: Pointer to uint32_t frequency value */
ptr = (FAR uint32_t *)((uintptr_t)arg); ptr = (FAR uint32_t *)((uintptr_t)arg);
DEBUGASSERT(priv->config != NULL && ptr != NULL); DEBUGASSERT(priv->config != NULL && ptr != NULL);
break; break;
@ -337,36 +323,36 @@ static int w5500_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
return ret; return ret;
} }
void w5500_notify(uart_dev_t *dev) void enet_notify(uart_dev_t *dev)
{ {
nxsem_post(&g_w5500dev.waitsem); nxsem_post(&g_enetdev.waitsem);
} }
/**************************************************************************** /****************************************************************************
* Name: w5500_poll * Name: enet_poll
****************************************************************************/ ****************************************************************************/
static int w5500_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) static int enet_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct w5500_dev_s *priv; FAR struct enet_dev_s *priv;
int ret; int ret;
w5500info("setup: %d\n", (int)setup); enetinfo("setup: %d\n", (int)setup);
DEBUGASSERT(filep && fds); DEBUGASSERT(filep && fds);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct w5500_dev_s *)inode->i_private; priv = (FAR struct enet_dev_s *)inode->i_private;
/* Are we setting up the poll? Or tearing it down? */ /* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
w5500err("ERROR: nxsem_wait failed: %d\n", ret); eneterr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -375,11 +361,11 @@ static int w5500_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup
/* Ignore waits that do not include POLLIN */ /* Ignore waits that do not include POLLIN */
if((fds->events & POLLIN) == 0) if((fds->events & POLLIN) == 0)
{ {
w5500err("ERROR: Missing POLLIN: revents: %08x\n", fds->revents); eneterr("ERROR: Missing POLLIN: revents: %08x\n", fds->revents);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return -EDEADLK; return -EDEADLK;
} }
w5500_notify(priv->uart_dev); enet_notify(priv->uart_dev);
} }
else if(fds->priv) else if(fds->priv)
{ {
@ -396,28 +382,28 @@ static int w5500_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup
} }
static const struct file_operations w5500_fops = static const struct file_operations enet_fops =
{ {
w5500_open, /* open */ enet_open, /* open */
w5500_close, /* close */ enet_close, /* close */
w5500_read, /* read */ enet_read, /* read */
w5500_write, /* write */ enet_write, /* write */
NULL, /* seek */ NULL, /* seek */
w5500_ioctl, /* ioctl */ enet_ioctl, /* ioctl */
w5500_poll /* poll */ enet_poll /* poll */
}; };
/**************************************************************************** /****************************************************************************
* Name: w5500_register * Name: enet_register
* *
* Description: * Description:
* Register /dev/ext_uartN * Register /dev/ext_uartN
* *
****************************************************************************/ ****************************************************************************/
static int w5500_register(FAR const char *devpath) static int enet_register(FAR const char *devpath)
{ {
FAR struct w5500_dev_s *priv = &g_w5500dev; FAR struct enet_dev_s *priv = &g_enetdev;
int ret = 0; int ret = 0;
nxsem_init(&priv->devsem, 0, 1); nxsem_init(&priv->devsem, 0, 1);
@ -425,7 +411,7 @@ static int w5500_register(FAR const char *devpath)
nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE); nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE);
/* Register the driver */ /* Register the driver */
ret = register_driver(devpath, &w5500_fops, 0666, priv); ret = register_driver(devpath, &enet_fops, 0666, priv);
if(ret < 0) if(ret < 0)
{ {
kmm_free(priv); kmm_free(priv);
@ -435,36 +421,36 @@ static int w5500_register(FAR const char *devpath)
} }
/**************************************************************************** /****************************************************************************
* Name: w5500_init * Name: enet_init
* *
* Description: * Description:
* Ch376 default initialization function * Ch376 default initialization function
* *
****************************************************************************/ ****************************************************************************/
void board_w5500_initialize(void) void board_enet_initialize(void)
{ {
//simluate SPI bus //simluate SPI bus
k210_fpioa_config(BSP_W5500_SCLK, HS_GPIO(FPIOA_W5500_SCLK) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_SCLK, HS_GPIO(FPIOA_ENET_SCLK) | K210_IOFLAG_GPIOHS);
k210_fpioa_config(BSP_W5500_NRST, HS_GPIO(FPIOA_W5500_NRST) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_NRST, HS_GPIO(FPIOA_ENET_NRST) | K210_IOFLAG_GPIOHS);
k210_fpioa_config(BSP_W5500_MOSI, HS_GPIO(FPIOA_W5500_MOSI) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_MOSI, HS_GPIO(FPIOA_ENET_MOSI) | K210_IOFLAG_GPIOHS);
k210_fpioa_config(BSP_W5500_MISO, HS_GPIO(FPIOA_W5500_MISO) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_MISO, HS_GPIO(FPIOA_ENET_MISO) | K210_IOFLAG_GPIOHS);
k210_fpioa_config(BSP_W5500_NCS, HS_GPIO(FPIOA_W5500_NCS) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_NCS, HS_GPIO(FPIOA_ENET_NCS) | K210_IOFLAG_GPIOHS);
k210_fpioa_config(BSP_W5500_NINT, HS_GPIO(FPIOA_W5500_NINT) | K210_IOFLAG_GPIOHS); k210_fpioa_config(BSP_ENET_NINT, HS_GPIO(FPIOA_ENET_NINT) | K210_IOFLAG_GPIOHS);
k210_gpiohs_set_direction(FPIOA_W5500_MISO, GPIO_DM_INPUT); k210_gpiohs_set_direction(FPIOA_ENET_MISO, GPIO_DM_INPUT);
k210_gpiohs_set_direction(FPIOA_W5500_NRST, GPIO_DM_OUTPUT); k210_gpiohs_set_direction(FPIOA_ENET_NRST, GPIO_DM_OUTPUT);
k210_gpiohs_set_direction(FPIOA_W5500_SCLK, GPIO_DM_OUTPUT); k210_gpiohs_set_direction(FPIOA_ENET_SCLK, GPIO_DM_OUTPUT);
k210_gpiohs_set_direction(FPIOA_W5500_MOSI, GPIO_DM_OUTPUT); k210_gpiohs_set_direction(FPIOA_ENET_MOSI, GPIO_DM_OUTPUT);
k210_gpiohs_set_direction(FPIOA_W5500_NCS, GPIO_DM_OUTPUT); k210_gpiohs_set_direction(FPIOA_ENET_NCS, GPIO_DM_OUTPUT);
k210_gpiohs_set_direction(FPIOA_W5500_NINT, GPIO_DM_INPUT); k210_gpiohs_set_direction(FPIOA_ENET_NINT, GPIO_DM_INPUT);
k210_gpiohs_set_value(FPIOA_W5500_SCLK, GPIO_PV_HIGH); k210_gpiohs_set_value(FPIOA_ENET_SCLK, GPIO_PV_HIGH);
k210_gpiohs_set_value(FPIOA_W5500_MOSI, GPIO_PV_HIGH); k210_gpiohs_set_value(FPIOA_ENET_MOSI, GPIO_PV_HIGH);
k210_gpiohs_set_value(FPIOA_W5500_NCS, GPIO_PV_LOW); k210_gpiohs_set_value(FPIOA_ENET_NCS, GPIO_PV_LOW);
k210_gpiohs_set_value(FPIOA_W5500_NRST, GPIO_PV_HIGH); k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_HIGH);
w5500_register(w5500_dev_name); enet_register(enet_dev_name);
w5500info("dev %s ok!\n", w5500_dev_name); enetinfo("dev %s ok!\n", enet_dev_name);
} }

View File

@ -0,0 +1,122 @@
/*
* Copyright (c) 2022 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 k210_enet.h
* @brief define aiit-riscv64-board enet function and struct
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-09-14
*/
#ifndef __K210_ENET_H_
#define __K210_ENET_H_
#include <nuttx/kmalloc.h>
#include <nuttx/wqueue.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <debug.h>
#include <assert.h>
#include <fcntl.h>
#include <arch/board/board.h>
#include "riscv_internal.h"
#include "k210_config.h"
#include "k210_fpioa.h"
#include "k210_gpiohs.h"
#include "xidatong-riscv64.h"
#include "nuttx/serial/serial.h"
/* Define ENET PIN NUM */
#define BSP_ENET_SCLK 9
#define BSP_ENET_MISO 10
#define BSP_ENET_MOSI 11
#define BSP_ENET_NCS 12
#define BSP_ENET_NRST 13
#define BSP_ENET_NINT 14
/* Define enet FPIOA NUMBER */
#define FPIOA_ENET_NRST 0
#define FPIOA_ENET_NINT 9
#define FPIOA_ENET_SCLK 28
#define FPIOA_ENET_MISO 29
#define FPIOA_ENET_MOSI 23
#define FPIOA_ENET_NCS 31
#define ENET_FUNC_GPIO(n) ((K210_IO_FUNC_GPIOHS0 + n) | K210_IOFLAG_GPIOHS)
#define ENETIOC_SETFREQUENCY _WLIOC(0x0001) /* arg: Pointer to uint32_t frequency value */
#define ENETIOC_GETFREQUENCY _WLIOC(0x0002) /* arg: Pointer to uint32_t frequency value */
/* enet debug */
#ifdef CONFIG_DEBUG_ENET_ERROR
# define eneterr _err
#else
# define eneterr _none
#endif
#ifdef CONFIG_DEBUG_ENET_WARN
# define enetwarn _warn
#else
# define enetwarn _none
#endif
#ifdef CONFIG_DEBUG_ENET_INFO
# define enetinfo _info
#else
# define enetinfo _none
#endif
#define ENET_RECV_BUF_SIZE 256
#define ENET_INCREMENT MSEC2TICK(33)
struct enet_config_s
{
int (*attach)(FAR const struct enet_config_s *config, xcpt_t isr,
FAR void *arg);
void (*enable)(FAR const struct enet_config_s *config, bool enable);
void (*clear)(FAR const struct enet_config_s *config);
void (*wakeup)(FAR const struct enet_config_s *config);
void (*nreset)(FAR const struct enet_config_s *config, bool state);
};
struct enet_dev_s
{
uint8_t crefs; /* Number of times the device
* has been opened */
uint8_t nwaiters; /* Number of threads waiting for
* data */
sem_t devsem; /* Manages exclusive access to
* this structure */
sem_t waitsem; /* Used to wait for the
* availability of data */
FAR const struct enet_config_s *config; /* Board configuration data */
struct work_s irqwork; /* Supports the interrupt
* handling "bottom half" */
char *dev_name;
int uart_fd;
uart_dev_t *uart_dev;
int recv_size;
uint8_t recv_buf[ENET_RECV_BUF_SIZE];
};
void board_enet_initialize(void);
#endif

View File

@ -11,8 +11,8 @@
*/ */
/** /**
* @file k210_ec200.c * @file k210_lte.c
* @brief support to register ch436 pointer and function * @brief support to register lte pointer and function
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022-07-20 * @date 2022-07-20
@ -22,18 +22,18 @@
#include <nuttx/wqueue.h> #include <nuttx/wqueue.h>
#include <sys/poll.h> #include <sys/poll.h>
#include "ctype.h" #include "ctype.h"
#include "k210_ec200.h" #include "k210_lte.h"
#define ec_print printf #define ec_print printf
/******************************************************************************/ /******************************************************************************/
struct ec200_dev_s g_ec200dev; struct lte_dev_s g_ltedev;
static char *ec200_dev_name = "/dev/ec200"; static char *lte_dev_name = "/dev/lte";
/******************************************************************************/ /******************************************************************************/
void ec200_print_buf(int size, uint8_t *buf) void lte_print_buf(int size, uint8_t *buf)
{ {
char ch[10] = {0}; char ch[10] = {0};
char temp[256] = {0}; char temp[256] = {0};
@ -63,65 +63,63 @@ void ec200_print_buf(int size, uint8_t *buf)
} }
} }
if(size) if(size)
ec_print("ec200 read %d data: %s\n", size, temp); ec_print("lte read %d data: %s\n", size, temp);
} }
int ec200_read_buf(void *dev, int *size, uint8_t *buf) int lte_read_buf(void *dev, int *size, uint8_t *buf)
{ {
uart_dev_t *uart_dev = (uart_dev_t *)dev; uart_dev_t *uart_dev = (uart_dev_t *)dev;
int cur_size = uart_dev->recv.head - uart_dev->recv.tail; int cur_size = uart_dev->recv.head - uart_dev->recv.tail;
*size = *size > cur_size ? cur_size : *size; *size = *size > cur_size ? cur_size : *size;
memcpy(buf, uart_dev->recv.buffer, *size); memcpy(buf, uart_dev->recv.buffer, *size);
uart_dev->recv.head = uart_dev->recv.tail; uart_dev->recv.head = uart_dev->recv.tail;
ec200_print_buf(*size, buf); lte_print_buf(*size, buf);
return *size; return *size;
} }
/**************************************************************************** /****************************************************************************
* Name: ec200_data_work * Name: lte_data_work
* *
* Description: * Description:
* thread task ec200_data_work * thread task lte_data_work
* *
****************************************************************************/ ****************************************************************************/
static FAR void ec200_data_work(FAR void *arg) static FAR void lte_data_work(FAR void *arg)
{ {
struct ec200_dev_s *ec200_dev = (struct ec200_dev_s *)arg; struct lte_dev_s *lte_dev = (struct lte_dev_s *)arg;
uart_dev_t *uart_dev = ec200_dev->uart_dev; uart_dev_t *uart_dev = lte_dev->uart_dev;
nxsem_wait(&ec200_dev->waitsem); nxsem_wait(&lte_dev->waitsem);
ec200_dev->recv_size = EC200_RECV_BUF_SIZE; lte_dev->recv_size = LTE_RECV_BUF_SIZE;
ec200_read_buf(uart_dev, &ec200_dev->recv_size, ec200_dev->recv_buf); lte_read_buf(uart_dev, &lte_dev->recv_size, lte_dev->recv_buf);
work_queue(HPWORK, &ec200_dev->irqwork, ec200_data_work, ec200_dev, EC200_INCREMENT); work_queue(HPWORK, &lte_dev->irqwork, lte_data_work, lte_dev, LTE_INCREMENT);
// ec200info("uart size %d ok!\n", ec200_dev->recv_size); lteinfo("uart size %d ok!\n", lte_dev->recv_size);
} }
static int ec200_bringup(struct ec200_dev_s *dev) static int lte_bringup(struct lte_dev_s *dev)
{ {
// struct ec200_dev_s *ec200_dev = &g_ec200dev;
dev->uart_fd = open(dev->dev_name, O_RDWR); dev->uart_fd = open(dev->dev_name, O_RDWR);
ec200info("open %s fd = %d\n", dev->dev_name, dev->uart_fd); lteinfo("open %s fd = %d\n", dev->dev_name, dev->uart_fd);
work_queue(HPWORK, &dev->irqwork, ec200_data_work, dev, EC200_INCREMENT); work_queue(HPWORK, &dev->irqwork, lte_data_work, dev, LTE_INCREMENT);
return OK; return OK;
} }
static int ec200_write_config(struct ec200_dev_s *dev) static int lte_write_config(struct lte_dev_s *dev)
{ {
return OK; return OK;
} }
static int ec200_shutdown(struct ec200_dev_s *dev) static int lte_shutdown(struct lte_dev_s *dev)
{ {
close(dev->uart_fd); close(dev->uart_fd);
return OK; return OK;
} }
static int ec200_open(FAR struct file *filep) static int lte_open(FAR struct file *filep)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct ec200_dev_s *priv; FAR struct lte_dev_s *priv;
uint8_t ref_cnt; uint8_t ref_cnt;
@ -131,14 +129,14 @@ static int ec200_open(FAR struct file *filep)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct ec200_dev_s *)inode->i_private; priv = (FAR struct lte_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: nxsem_wait failed: %d\n", ret); lteerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -158,20 +156,20 @@ static int ec200_open(FAR struct file *filep)
if(ref_cnt == 1) if(ref_cnt == 1)
{ {
ret = ec200_bringup(priv); ret = lte_bringup(priv);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: ec200_bringup failed: %d\n", ret); lteerr("ERROR: lte_bringup failed: %d\n", ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
ret = ec200_write_config(priv); ret = lte_write_config(priv);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: ec200_write_config failed: %d\n", ret); lteerr("ERROR: lte_write_config failed: %d\n", ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
@ -185,13 +183,13 @@ static int ec200_open(FAR struct file *filep)
} }
/**************************************************************************** /****************************************************************************
* Name: ec200_close * Name: lte_close
****************************************************************************/ ****************************************************************************/
static int ec200_close(FAR struct file *filep) static int lte_close(FAR struct file *filep)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct ec200_dev_s *priv; FAR struct lte_dev_s *priv;
int ret; int ret;
@ -199,14 +197,14 @@ static int ec200_close(FAR struct file *filep)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct ec200_dev_s *)inode->i_private; priv = (FAR struct lte_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: nxsem_wait failed: %d\n", ret); lteerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -225,7 +223,7 @@ static int ec200_close(FAR struct file *filep)
if(priv->crefs == 0) if(priv->crefs == 0)
{ {
ec200_shutdown(priv); lte_shutdown(priv);
} }
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
@ -233,26 +231,26 @@ static int ec200_close(FAR struct file *filep)
} }
/**************************************************************************** /****************************************************************************
* Name: ec200_read * Name: lte_read
****************************************************************************/ ****************************************************************************/
static ssize_t ec200_read(FAR struct file *filep, FAR char *buffer, size_t len) static ssize_t lte_read(FAR struct file *filep, FAR char *buffer, size_t len)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct ec200_dev_s *priv; FAR struct lte_dev_s *priv;
int ret, buf_size = len; int ret, buf_size = len;
DEBUGASSERT(filep); DEBUGASSERT(filep);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct ec200_dev_s *)inode->i_private; priv = (FAR struct lte_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: nxsem_wait failed: %d\n", ret); lteerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -264,42 +262,42 @@ static ssize_t ec200_read(FAR struct file *filep, FAR char *buffer, size_t len)
/**************************************************************************** /****************************************************************************
* Name: ec200_write * Name: lte_write
****************************************************************************/ ****************************************************************************/
static ssize_t ec200_write(FAR struct file *filep, FAR const char *buffer, size_t len) static ssize_t lte_write(FAR struct file *filep, FAR const char *buffer, size_t len)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct ec200_dev_s *priv; FAR struct lte_dev_s *priv;
int ret; int ret;
DEBUGASSERT(filep); DEBUGASSERT(filep);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct ec200_dev_s *)inode->i_private; priv = (FAR struct lte_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: nxsem_wait failed: %d\n", ret); lteerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
ret = write(priv->uart_fd, buffer, len); ret = write(priv->uart_fd, buffer, len);
ec200info("write fd %d len %ld ret = %d\n", priv->uart_fd, len, ret); lteinfo("write fd %d len %ld ret = %d\n", priv->uart_fd, len, ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
/**************************************************************************** /****************************************************************************
* Name: ec200_ioctl * Name: lte_ioctl
****************************************************************************/ ****************************************************************************/
static int ec200_ioctl(FAR struct file *filep, int cmd, unsigned long arg) static int lte_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct ec200_dev_s *priv; FAR struct lte_dev_s *priv;
int ret; int ret;
@ -307,14 +305,14 @@ static int ec200_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct ec200_dev_s *)inode->i_private; priv = (FAR struct lte_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: nxsem_wait failed: %d\n", ret); lteerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -322,11 +320,6 @@ static int ec200_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
switch(cmd) switch(cmd)
{ {
// case TSIOC_SETFREQUENCY: /* arg: Pointer to uint32_t frequency value */
// FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg);
// DEBUGASSERT(priv->config != NULL && ptr != NULL);
// break;
default: default:
ret = -ENOTTY; ret = -ENOTTY;
break; break;
@ -337,30 +330,30 @@ static int ec200_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
/**************************************************************************** /****************************************************************************
* Name: ec200_poll * Name: lte_poll
****************************************************************************/ ****************************************************************************/
static int ec200_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) static int lte_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct ec200_dev_s *priv; FAR struct lte_dev_s *priv;
int ret; int ret;
ec200info("setup: %d\n", (int)setup); lteinfo("setup: %d\n", (int)setup);
DEBUGASSERT(filep && fds); DEBUGASSERT(filep && fds);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct ec200_dev_s *)inode->i_private; priv = (FAR struct lte_dev_s *)inode->i_private;
/* Are we setting up the poll? Or tearing it down? */ /* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
ec200err("ERROR: nxsem_wait failed: %d\n", ret); lteerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -369,11 +362,11 @@ static int ec200_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup
/* Ignore waits that do not include POLLIN */ /* Ignore waits that do not include POLLIN */
if((fds->events & POLLIN) == 0) if((fds->events & POLLIN) == 0)
{ {
ec200err("ERROR: Missing POLLIN: revents: %08x\n", fds->revents); lteerr("ERROR: Missing POLLIN: revents: %08x\n", fds->revents);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return -EDEADLK; return -EDEADLK;
} }
ec200_notify(priv->uart_dev); lte_notify(priv->uart_dev);
} }
else if(fds->priv) else if(fds->priv)
{ {
@ -390,28 +383,28 @@ static int ec200_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup
} }
static const struct file_operations ec200_fops = static const struct file_operations lte_fops =
{ {
ec200_open, /* open */ lte_open, /* open */
ec200_close, /* close */ lte_close, /* close */
ec200_read, /* read */ lte_read, /* read */
ec200_write, /* write */ lte_write, /* write */
NULL, /* seek */ NULL, /* seek */
ec200_ioctl, /* ioctl */ lte_ioctl, /* ioctl */
ec200_poll /* poll */ lte_poll /* poll */
}; };
/**************************************************************************** /****************************************************************************
* Name: ec200_register * Name: lte_register
* *
* Description: * Description:
* Register /dev/ext_uartN * Register /dev/lte
* *
****************************************************************************/ ****************************************************************************/
static int ec200_register(FAR const char *devpath) static int lte_register(FAR const char *devpath)
{ {
FAR struct ec200_dev_s *priv = &g_ec200dev; FAR struct lte_dev_s *priv = &g_ltedev;
int ret = 0; int ret = 0;
nxsem_init(&priv->devsem, 0, 1); nxsem_init(&priv->devsem, 0, 1);
@ -419,7 +412,7 @@ static int ec200_register(FAR const char *devpath)
nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE); nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE);
/* Register the driver */ /* Register the driver */
ret = register_driver(devpath, &ec200_fops, 0666, priv); ret = register_driver(devpath, &lte_fops, 0666, priv);
if(ret < 0) if(ret < 0)
{ {
kmm_free(priv); kmm_free(priv);
@ -428,31 +421,31 @@ static int ec200_register(FAR const char *devpath)
return ret; return ret;
} }
void ec200_notify(uart_dev_t *dev) void lte_notify(uart_dev_t *dev)
{ {
if(dev == g_ec200dev.uart_dev) if(dev == g_ltedev.uart_dev)
nxsem_post(&g_ec200dev.waitsem); nxsem_post(&g_ltedev.waitsem);
} }
/**************************************************************************** /****************************************************************************
* Name: ec200_init * Name: lte_init
* *
* Description: * Description:
* Ch376 default initialization function * Ch376 default initialization function
* *
****************************************************************************/ ****************************************************************************/
void board_ec200_initialize(void) void board_lte_initialize(void)
{ {
#if defined(CONFIG_U16550_UART2) #if defined(CONFIG_U16550_UART2)
fpioa_set_function(EC200_RX_PIN, FPIOA_EC200_RX); fpioa_set_function(LTE_RX_PIN, FPIOA_LTE_RX);
fpioa_set_function(EC200_TX_PIN, FPIOA_EC200_TX); fpioa_set_function(LTE_TX_PIN, FPIOA_LTE_TX);
g_ec200dev.dev_name = "/dev/uart2"; g_ltedev.dev_name = "/dev/uart2";
u16550_register(&g_ec200dev.uart_dev, 2); u16550_register(&g_ltedev.uart_dev, 2);
ec200_register(ec200_dev_name); lte_register(lte_dev_name);
ec200info("dev %p ok!\n", g_ec200dev.uart_dev); lteinfo("dev %p ok!\n", g_ltedev.uart_dev);
#endif #endif
} }

View File

@ -11,15 +11,15 @@
*/ */
/** /**
* @file k210_ec200.h * @file k210_lte.h
* @brief define aiit-riscv64-board ec200 function and struct * @brief define aiit-riscv64-board lte function and struct
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022-09-7 * @date 2022-09-7
*/ */
#ifndef __K210_EC200_H_ #ifndef __K210_LTE_H_
#define __K210_EC200_H_ #define __K210_LTE_H_
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
@ -61,50 +61,49 @@
#include "nuttx/serial/uart_16550.h" #include "nuttx/serial/uart_16550.h"
/* Define CH438 PIN NUM */ /* Define LTE PIN NUM */
#define EC200_RX_PIN 21 #define LTE_RX_PIN 21
#define EC200_TX_PIN 20 #define LTE_TX_PIN 20
/* Define ch438 FPIOA NUMBER */ /* Define FPIOA NUMBER */
#define FPIOA_EC200_RX 66 #define FPIOA_LTE_RX 66
#define FPIOA_EC200_TX 67 #define FPIOA_LTE_TX 67
/* lte debug */
/* ec200 debug */ #ifdef CONFIG_DEBUG_LTE_ERROR
#ifdef CONFIG_DEBUG_EC200_ERROR # define lteerr _err
# define ec200err _err
#else #else
# define ec200err _none # define lteerr _none
#endif #endif
#ifdef CONFIG_DEBUG_EC200_WARN #ifdef CONFIG_DEBUG_LTE_WARN
# define ec200warn _warn # define ltewarn _warn
#else #else
# define ec200warn _none # define ltewarn _none
#endif #endif
#ifdef CONFIG_DEBUG_EC200_INFO #ifdef CONFIG_DEBUG_LTE_INFO
# define ec200info _info # define lteinfo _info
#else #else
# define ec200info _none # define lteinfo _none
#endif #endif
#define EC200_RECV_BUF_SIZE 256 #define LTE_RECV_BUF_SIZE 256
#define EC200_INCREMENT MSEC2TICK(33) #define LTE_INCREMENT MSEC2TICK(33)
struct ec200_config_s struct lte_config_s
{ {
int (*attach)(FAR const struct ec200_config_s *config, xcpt_t isr, int (*attach)(FAR const struct lte_config_s *config, xcpt_t isr,
FAR void *arg); FAR void *arg);
void (*enable)(FAR const struct ec200_config_s *config, bool enable); void (*enable)(FAR const struct lte_config_s *config, bool enable);
void (*clear)(FAR const struct ec200_config_s *config); void (*clear)(FAR const struct lte_config_s *config);
void (*wakeup)(FAR const struct ec200_config_s *config); void (*wakeup)(FAR const struct lte_config_s *config);
void (*nreset)(FAR const struct ec200_config_s *config, bool state); void (*nreset)(FAR const struct lte_config_s *config, bool state);
}; };
struct ec200_dev_s struct lte_dev_s
{ {
uint8_t crefs; /* Number of times the device uint8_t crefs; /* Number of times the device
* has been opened */ * has been opened */
@ -115,18 +114,18 @@ struct ec200_dev_s
sem_t waitsem; /* Used to wait for the sem_t waitsem; /* Used to wait for the
* availability of data */ * availability of data */
FAR const struct ec200_config_s *config;/* Board configuration data */ FAR const struct lte_config_s *config;/* Board configuration data */
struct work_s irqwork; /* Supports the interrupt struct work_s irqwork; /* Supports the interrupt
* handling "bottom half" */ * handling "bottom half" */
char *dev_name; char *dev_name;
int uart_fd; int uart_fd;
uart_dev_t *uart_dev; uart_dev_t *uart_dev;
int recv_size; int recv_size;
uint8_t recv_buf[EC200_RECV_BUF_SIZE]; uint8_t recv_buf[LTE_RECV_BUF_SIZE];
}; };
void ec200_notify(uart_dev_t *dev); void lte_notify(uart_dev_t *dev);
void board_ec200_initialize(void); void board_lte_initialize(void);
#endif #endif

View File

@ -1,137 +0,0 @@
/*
* Copyright (c) 2022 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 k210_w5500.h
* @brief define aiit-riscv64-board w5500 function and struct
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-09-14
*/
#ifndef __K210_W5500_H_
#define __K210_W5500_H_
#include <nuttx/kmalloc.h>
#include <nuttx/wqueue.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <debug.h>
#include <assert.h>
#include <fcntl.h>
#include <arch/board/board.h>
#include "riscv_internal.h"
#include "k210_config.h"
#include "k210_fpioa.h"
#include "k210_gpiohs.h"
#include "xidatong-riscv64.h"
#include "nuttx/serial/serial.h"
/* Define W5500 PIN NUM */
#define BSP_W5500_SCLK 9
#define BSP_W5500_MISO 10
#define BSP_W5500_MOSI 11
#define BSP_W5500_NCS 12
#define BSP_W5500_NRST 13
#define BSP_W5500_NINT 14
/* Define w5500 FPIOA NUMBER */
//#define FPIOA_W5500_SCLK 83
//#define FPIOA_W5500_MISO 70
//#define FPIOA_W5500_MOSI 71
//#define FPIOA_W5500_NCS 78
//
//#define FPIOA_W5500_NRST 4
//#define FPIOA_W5500_INT 5
//#define FPIOA_W5500_NRST 0
//#define FPIOA_W5500_NINT 9
//#define FPIOA_W5500_SCLK 28
//#define FPIOA_W5500_MOSI 29
//#define FPIOA_W5500_MISO 23
//#define FPIOA_W5500_NCS 31
#define FPIOA_W5500_NRST 0
#define FPIOA_W5500_NINT 9
#define FPIOA_W5500_SCLK 28
#define FPIOA_W5500_MISO 29
#define FPIOA_W5500_MOSI 23
#define FPIOA_W5500_NCS 31
#define W5500_FUNC_GPIO(n) ((K210_IO_FUNC_GPIOHS0 + n) | K210_IOFLAG_GPIOHS)
#define W5500IOC_SETFREQUENCY _WLIOC(0x0001) /* arg: Pointer to uint32_t frequency value */
#define W5500IOC_GETFREQUENCY _WLIOC(0x0002) /* arg: Pointer to uint32_t frequency value */
/* w5500 debug */
#ifdef CONFIG_DEBUG_W5500_ERROR
# define w5500err _err
#else
# define w5500err _none
#endif
#ifdef CONFIG_DEBUG_W5500_WARN
# define w5500warn _warn
#else
# define w5500warn _none
#endif
#ifdef CONFIG_DEBUG_W5500_INFO
# define w5500info _info
#else
# define w5500info _none
#endif
#define W5500_RECV_BUF_SIZE 256
#define W5500_INCREMENT MSEC2TICK(33)
struct w5500_config_s
{
int (*attach)(FAR const struct w5500_config_s *config, xcpt_t isr,
FAR void *arg);
void (*enable)(FAR const struct w5500_config_s *config, bool enable);
void (*clear)(FAR const struct w5500_config_s *config);
void (*wakeup)(FAR const struct w5500_config_s *config);
void (*nreset)(FAR const struct w5500_config_s *config, bool state);
};
struct w5500_dev_s
{
uint8_t crefs; /* Number of times the device
* has been opened */
uint8_t nwaiters; /* Number of threads waiting for
* data */
sem_t devsem; /* Manages exclusive access to
* this structure */
sem_t waitsem; /* Used to wait for the
* availability of data */
FAR const struct w5500_config_s *config; /* Board configuration data */
struct work_s irqwork; /* Supports the interrupt
* handling "bottom half" */
char *dev_name;
int uart_fd;
uart_dev_t *uart_dev;
int recv_size;
uint8_t recv_buf[W5500_RECV_BUF_SIZE];
};
void board_w5500_initialize(void);
#endif

View File

@ -11,8 +11,8 @@
*/ */
/** /**
* @file k210_esp8266.c * @file k210_wifi.c
* @brief support to register esp8266 pointer and function * @brief support to register wifi pointer and function
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022-07-20 * @date 2022-07-20
@ -22,18 +22,18 @@
#include <nuttx/wqueue.h> #include <nuttx/wqueue.h>
#include <sys/poll.h> #include <sys/poll.h>
#include "ctype.h" #include "ctype.h"
#include "k210_esp8266.h" #include "k210_wifi.h"
#define ec_print printf #define ec_print printf
/******************************************************************************/ /******************************************************************************/
struct esp8266_dev_s g_esp8266dev; struct wifi_dev_s g_wifidev;
static char *esp8266_dev_name = "/dev/esp8266"; static char *wifi_dev_name = "/dev/wifi";
/******************************************************************************/ /******************************************************************************/
void esp8266_print_buf(int size, uint8_t *buf) void wifi_print_buf(int size, uint8_t *buf)
{ {
char ch[10] = {0}; char ch[10] = {0};
char temp[256] = {0}; char temp[256] = {0};
@ -63,65 +63,61 @@ void esp8266_print_buf(int size, uint8_t *buf)
} }
} }
if(size) if(size)
ec_print("esp8266 read %d data: %s\n", size, temp); ec_print("wifi read %d data: %s\n", size, temp);
} }
int esp8266_read_buf(void *dev, int *size, uint8_t *buf) int wifi_read_buf(void *dev, int *size, uint8_t *buf)
{ {
uart_dev_t *uart_dev = (uart_dev_t *)dev; uart_dev_t *uart_dev = (uart_dev_t *)dev;
int cur_size = uart_dev->recv.head - uart_dev->recv.tail; int cur_size = uart_dev->recv.head - uart_dev->recv.tail;
*size = *size > cur_size ? cur_size : *size; *size = *size > cur_size ? cur_size : *size;
memcpy(buf, uart_dev->recv.buffer, *size); memcpy(buf, uart_dev->recv.buffer, *size);
uart_dev->recv.head = uart_dev->recv.tail; uart_dev->recv.head = uart_dev->recv.tail;
esp8266_print_buf(*size, buf); wifi_print_buf(*size, buf);
return *size; return *size;
} }
/**************************************************************************** /****************************************************************************
* Name: esp8266_data_work * Name: wifi_data_work
* *
* Description: * Description:
* thread task esp8266_data_work * thread task wifi_data_work
* *
****************************************************************************/ ****************************************************************************/
static FAR void esp8266_data_work(FAR void *arg) static FAR void wifi_data_work(FAR void *arg)
{ {
struct esp8266_dev_s *esp8266_dev = (struct esp8266_dev_s *)arg; struct wifi_dev_s *wifi_dev = (struct wifi_dev_s *)arg;
uart_dev_t *uart_dev = esp8266_dev->uart_dev; uart_dev_t *uart_dev = wifi_dev->uart_dev;
nxsem_wait(&esp8266_dev->waitsem); nxsem_wait(&wifi_dev->waitsem);
esp8266_dev->recv_size = ESP8266_RECV_BUF_SIZE; wifi_dev->recv_size = WIFI_RECV_BUF_SIZE;
esp8266_read_buf(uart_dev, &esp8266_dev->recv_size, esp8266_dev->recv_buf); wifi_read_buf(uart_dev, &wifi_dev->recv_size, wifi_dev->recv_buf);
work_queue(HPWORK, &esp8266_dev->irqwork, esp8266_data_work, esp8266_dev, ESP8266_INCREMENT); work_queue(HPWORK, &wifi_dev->irqwork, wifi_data_work, wifi_dev, WIFI_INCREMENT);
// esp8266info("uart size %d ok!\n", esp8266_dev->recv_size); wifiinfo("uart size %d ok!\n", wifi_dev->recv_size);
} }
static int esp8266_bringup(struct esp8266_dev_s *dev) static int wifi_bringup(struct wifi_dev_s *dev)
{ {
// struct esp8266_dev_s *esp8266_dev = &g_esp8266dev;
dev->uart_fd = open(dev->dev_name, O_RDWR); dev->uart_fd = open(dev->dev_name, O_RDWR);
wifiinfo("open %s fd = %d\n", dev->dev_name, dev->uart_fd);
esp8266info("open %s fd = %d\n", dev->dev_name, dev->uart_fd); work_queue(HPWORK, &dev->irqwork, wifi_data_work, dev, WIFI_INCREMENT);
work_queue(HPWORK, &dev->irqwork, esp8266_data_work, dev, ESP8266_INCREMENT);
return OK; return OK;
} }
static int esp8266_write_config(struct esp8266_dev_s *dev) static int wifi_write_config(struct wifi_dev_s *dev)
{ {
return OK; return OK;
} }
static int esp8266_shutdown(struct esp8266_dev_s *dev) static int wifi_shutdown(struct wifi_dev_s *dev)
{ {
close(dev->uart_fd); close(dev->uart_fd);
return OK; return OK;
} }
static int esp8266_open(FAR struct file *filep) static int wifi_open(FAR struct file *filep)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct esp8266_dev_s *priv; FAR struct wifi_dev_s *priv;
uint8_t ref_cnt; uint8_t ref_cnt;
@ -131,14 +127,14 @@ static int esp8266_open(FAR struct file *filep)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct esp8266_dev_s *)inode->i_private; priv = (FAR struct wifi_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: nxsem_wait failed: %d\n", ret); wifierr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -158,20 +154,20 @@ static int esp8266_open(FAR struct file *filep)
if(ref_cnt == 1) if(ref_cnt == 1)
{ {
ret = esp8266_bringup(priv); ret = wifi_bringup(priv);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: esp8266_bringup failed: %d\n", ret); wifierr("ERROR: wifi_bringup failed: %d\n", ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
ret = esp8266_write_config(priv); ret = wifi_write_config(priv);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: esp8266_write_config failed: %d\n", ret); wifierr("ERROR: wifi_write_config failed: %d\n", ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
@ -185,13 +181,13 @@ static int esp8266_open(FAR struct file *filep)
} }
/**************************************************************************** /****************************************************************************
* Name: esp8266_close * Name: wifi_close
****************************************************************************/ ****************************************************************************/
static int esp8266_close(FAR struct file *filep) static int wifi_close(FAR struct file *filep)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct esp8266_dev_s *priv; FAR struct wifi_dev_s *priv;
int ret; int ret;
@ -199,14 +195,14 @@ static int esp8266_close(FAR struct file *filep)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct esp8266_dev_s *)inode->i_private; priv = (FAR struct wifi_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: nxsem_wait failed: %d\n", ret); wifierr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -220,12 +216,12 @@ static int esp8266_close(FAR struct file *filep)
} }
/* When the count decrements to zero, there are no further open references /* When the count decrements to zero, there are no further open references
* to the driver and it esp8266 be uninitialized. * to the driver and it wifi be uninitialized.
*/ */
if(priv->crefs == 0) if(priv->crefs == 0)
{ {
esp8266_shutdown(priv); wifi_shutdown(priv);
} }
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
@ -233,26 +229,26 @@ static int esp8266_close(FAR struct file *filep)
} }
/**************************************************************************** /****************************************************************************
* Name: esp8266_read * Name: wifi_read
****************************************************************************/ ****************************************************************************/
static ssize_t esp8266_read(FAR struct file *filep, FAR char *buffer, size_t len) static ssize_t wifi_read(FAR struct file *filep, FAR char *buffer, size_t len)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct esp8266_dev_s *priv; FAR struct wifi_dev_s *priv;
int ret, buf_size = len; int ret, buf_size = len;
DEBUGASSERT(filep); DEBUGASSERT(filep);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct esp8266_dev_s *)inode->i_private; priv = (FAR struct wifi_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: nxsem_wait failed: %d\n", ret); wifierr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -264,42 +260,42 @@ static ssize_t esp8266_read(FAR struct file *filep, FAR char *buffer, size_t len
/**************************************************************************** /****************************************************************************
* Name: esp8266_write * Name: wifi_write
****************************************************************************/ ****************************************************************************/
static ssize_t esp8266_write(FAR struct file *filep, FAR const char *buffer, size_t len) static ssize_t wifi_write(FAR struct file *filep, FAR const char *buffer, size_t len)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct esp8266_dev_s *priv; FAR struct wifi_dev_s *priv;
int ret; int ret;
DEBUGASSERT(filep); DEBUGASSERT(filep);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct esp8266_dev_s *)inode->i_private; priv = (FAR struct wifi_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: nxsem_wait failed: %d\n", ret); wifierr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
ret = write(priv->uart_fd, buffer, len); ret = write(priv->uart_fd, buffer, len);
esp8266info("write fd %d len %ld ret = %d\n", priv->uart_fd, len, ret); wifiinfo("write fd %d len %ld ret = %d\n", priv->uart_fd, len, ret);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return ret; return ret;
} }
/**************************************************************************** /****************************************************************************
* Name: esp8266_ioctl * Name: wifi_ioctl
****************************************************************************/ ****************************************************************************/
static int esp8266_ioctl(FAR struct file *filep, int cmd, unsigned long arg) static int wifi_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct esp8266_dev_s *priv; FAR struct wifi_dev_s *priv;
FAR uint32_t *ptr; FAR uint32_t *ptr;
int ret; int ret;
@ -308,14 +304,14 @@ static int esp8266_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct esp8266_dev_s *)inode->i_private; priv = (FAR struct wifi_dev_s *)inode->i_private;
/* Get exclusive access to the driver data structure */ /* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: nxsem_wait failed: %d\n", ret); wifierr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -323,7 +319,7 @@ static int esp8266_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
switch(cmd) switch(cmd)
{ {
case ESP8266IOC_SETFREQUENCY: /* arg: Pointer to uint32_t frequency value */ case WIFIIOC_SETFREQUENCY: /* arg: Pointer to uint32_t frequency value */
ptr = (FAR uint32_t *)((uintptr_t)arg); ptr = (FAR uint32_t *)((uintptr_t)arg);
DEBUGASSERT(priv->config != NULL && ptr != NULL); DEBUGASSERT(priv->config != NULL && ptr != NULL);
break; break;
@ -338,30 +334,30 @@ static int esp8266_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
/**************************************************************************** /****************************************************************************
* Name: esp8266_poll * Name: wifi_poll
****************************************************************************/ ****************************************************************************/
static int esp8266_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) static int wifi_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct esp8266_dev_s *priv; FAR struct wifi_dev_s *priv;
int ret; int ret;
esp8266info("setup: %d\n", (int)setup); wifiinfo("setup: %d\n", (int)setup);
DEBUGASSERT(filep && fds); DEBUGASSERT(filep && fds);
inode = filep->f_inode; inode = filep->f_inode;
DEBUGASSERT(inode && inode->i_private); DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct esp8266_dev_s *)inode->i_private; priv = (FAR struct wifi_dev_s *)inode->i_private;
/* Are we setting up the poll? Or tearing it down? */ /* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
if(ret < 0) if(ret < 0)
{ {
esp8266err("ERROR: nxsem_wait failed: %d\n", ret); wifierr("ERROR: nxsem_wait failed: %d\n", ret);
return ret; return ret;
} }
@ -370,11 +366,11 @@ static int esp8266_poll(FAR struct file *filep, FAR struct pollfd *fds, bool set
/* Ignore waits that do not include POLLIN */ /* Ignore waits that do not include POLLIN */
if((fds->events & POLLIN) == 0) if((fds->events & POLLIN) == 0)
{ {
esp8266err("ERROR: Missing POLLIN: revents: %08x\n", fds->revents); wifierr("ERROR: Missing POLLIN: revents: %08x\n", fds->revents);
nxsem_post(&priv->devsem); nxsem_post(&priv->devsem);
return -EDEADLK; return -EDEADLK;
} }
esp8266_notify(priv->uart_dev); wifi_notify(priv->uart_dev);
} }
else if(fds->priv) else if(fds->priv)
{ {
@ -391,28 +387,28 @@ static int esp8266_poll(FAR struct file *filep, FAR struct pollfd *fds, bool set
} }
static const struct file_operations esp8266_fops = static const struct file_operations wifi_fops =
{ {
esp8266_open, /* open */ wifi_open, /* open */
esp8266_close, /* close */ wifi_close, /* close */
esp8266_read, /* read */ wifi_read, /* read */
esp8266_write, /* write */ wifi_write, /* write */
NULL, /* seek */ NULL, /* seek */
esp8266_ioctl, /* ioctl */ wifi_ioctl, /* ioctl */
esp8266_poll /* poll */ wifi_poll /* poll */
}; };
/**************************************************************************** /****************************************************************************
* Name: esp8266_register * Name: wifi_register
* *
* Description: * Description:
* Register /dev/ext_uartN * Register /dev/ext_uartN
* *
****************************************************************************/ ****************************************************************************/
static int esp8266_register(FAR const char *devpath) static int wifi_register(FAR const char *devpath)
{ {
FAR struct esp8266_dev_s *priv = &g_esp8266dev; FAR struct wifi_dev_s *priv = &g_wifidev;
int ret = 0; int ret = 0;
nxsem_init(&priv->devsem, 0, 1); nxsem_init(&priv->devsem, 0, 1);
@ -420,7 +416,7 @@ static int esp8266_register(FAR const char *devpath)
nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE); nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE);
/* Register the driver */ /* Register the driver */
ret = register_driver(devpath, &esp8266_fops, 0666, priv); ret = register_driver(devpath, &wifi_fops, 0666, priv);
if(ret < 0) if(ret < 0)
{ {
kmm_free(priv); kmm_free(priv);
@ -429,34 +425,34 @@ static int esp8266_register(FAR const char *devpath)
return ret; return ret;
} }
void esp8266_notify(uart_dev_t *dev) void wifi_notify(uart_dev_t *dev)
{ {
if(dev == g_esp8266dev.uart_dev) if(dev == g_wifidev.uart_dev)
nxsem_post(&g_esp8266dev.waitsem); nxsem_post(&g_wifidev.waitsem);
} }
/**************************************************************************** /****************************************************************************
* Name: esp8266_init * Name: wifi_init
* *
* Description: * Description:
* Ch376 default initialization function * Ch376 default initialization function
* *
****************************************************************************/ ****************************************************************************/
void board_esp8266_initialize(void) void board_wifi_initialize(void)
{ {
k210_fpioa_config(ESP8266_EN_PIN, ESP8266_FUNC_GPIO(FPIOA_ESP8266_EN)); k210_fpioa_config(WIFI_EN_PIN, WIFI_FUNC_GPIO(FPIOA_WIFI_EN));
k210_gpiohs_set_direction(FPIOA_ESP8266_EN, GPIO_DM_OUTPUT); k210_gpiohs_set_direction(FPIOA_WIFI_EN, GPIO_DM_OUTPUT);
k210_gpiohs_set_value(FPIOA_ESP8266_EN, GPIO_PV_HIGH); k210_gpiohs_set_value(FPIOA_WIFI_EN, GPIO_PV_HIGH);
fpioa_set_function(ESP8266_RX_PIN, FPIOA_ESP8266_RX); fpioa_set_function(WIFI_RX_PIN, FPIOA_WIFI_RX);
fpioa_set_function(ESP8266_TX_PIN, FPIOA_ESP8266_TX); fpioa_set_function(WIFI_TX_PIN, FPIOA_WIFI_TX);
#if defined(CONFIG_U16550_UART2) #if defined(CONFIG_U16550_UART2)
g_esp8266dev.dev_name = "/dev/uart2"; g_wifidev.dev_name = "/dev/uart2";
u16550_register(&g_esp8266dev.uart_dev, 2); u16550_register(&g_wifidev.uart_dev, 2);
esp8266_register(esp8266_dev_name); wifi_register(wifi_dev_name);
esp8266info("dev %p ok!\n", g_esp8266dev.uart_dev); wifiinfo("dev %p ok!\n", g_wifidev.uart_dev);
#endif #endif
} }

View File

@ -11,15 +11,15 @@
*/ */
/** /**
* @file k210_esp8266.h * @file k210_wifi.h
* @brief define aiit-riscv64-board esp8266 function and struct * @brief define aiit-riscv64-board wifi function and struct
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022-09-7 * @date 2022-09-7
*/ */
#ifndef __K210_ESP8266_H_ #ifndef __K210_WIFI_H_
#define __K210_ESP8266_H_ #define __K210_WIFI_H_
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
@ -61,56 +61,56 @@
#include "nuttx/serial/uart_16550.h" #include "nuttx/serial/uart_16550.h"
/* Define CH438 PIN NUM */ /* Define WIFI PIN NUM */
#define ESP8266_RX_PIN 6 #define WIFI_RX_PIN 6
#define ESP8266_TX_PIN 7 #define WIFI_TX_PIN 7
#define ESP8266_EN_PIN 8 #define WIFI_EN_PIN 8
/* Define ch438 FPIOA NUMBER */ /* Define WIFI FPIOA NUMBER */
#define FPIOA_ESP8266_RX 66 #define FPIOA_WIFI_RX 66
#define FPIOA_ESP8266_TX 67 #define FPIOA_WIFI_TX 67
#define FPIOA_ESP8266_EN 4 #define FPIOA_WIFI_EN 4
#define ESP8266_FUNC_GPIO(n) ((K210_IO_FUNC_GPIOHS0 + n) | K210_IOFLAG_GPIOHS) #define WIFI_FUNC_GPIO(n) ((K210_IO_FUNC_GPIOHS0 + n) | K210_IOFLAG_GPIOHS)
#define ESP8266IOC_SETFREQUENCY _WLIOC(0x0001) /* arg: Pointer to uint32_t frequency value */ #define WIFIIOC_SETFREQUENCY _WLIOC(0x0001) /* arg: Pointer to uint32_t frequency value */
#define ESP8266IOC_GETFREQUENCY _WLIOC(0x0002) /* arg: Pointer to uint32_t frequency value */ #define WIFIIOC_GETFREQUENCY _WLIOC(0x0002) /* arg: Pointer to uint32_t frequency value */
/* esp8266 debug */ /* wifi debug */
#ifdef CONFIG_DEBUG_ESP8266_ERROR #ifdef CONFIG_DEBUG_WIFI_ERROR
# define esp8266err _err # define wifierr _err
#else #else
# define esp8266err _none # define wifierr _none
#endif #endif
#ifdef CONFIG_DEBUG_ESP8266_WARN #ifdef CONFIG_DEBUG_WIFI_WARN
# define esp8266warn _warn # define wifiwarn _warn
#else #else
# define esp8266warn _none # define wifiwarn _none
#endif #endif
#ifdef CONFIG_DEBUG_ESP8266_INFO #ifdef CONFIG_DEBUG_WIFI_INFO
# define esp8266info _info # define wifiinfo _info
#else #else
# define esp8266info _none # define wifiinfo _none
#endif #endif
#define ESP8266_RECV_BUF_SIZE 256 #define WIFI_RECV_BUF_SIZE 256
#define ESP8266_INCREMENT MSEC2TICK(33) #define WIFI_INCREMENT MSEC2TICK(33)
struct esp8266_config_s struct wifi_config_s
{ {
int (*attach)(FAR const struct esp8266_config_s *config, xcpt_t isr, int (*attach)(FAR const struct wifi_config_s *config, xcpt_t isr,
FAR void *arg); FAR void *arg);
void (*enable)(FAR const struct esp8266_config_s *config, bool enable); void (*enable)(FAR const struct wifi_config_s *config, bool enable);
void (*clear)(FAR const struct esp8266_config_s *config); void (*clear)(FAR const struct wifi_config_s *config);
void (*wakeup)(FAR const struct esp8266_config_s *config); void (*wakeup)(FAR const struct wifi_config_s *config);
void (*nreset)(FAR const struct esp8266_config_s *config, bool state); void (*nreset)(FAR const struct wifi_config_s *config, bool state);
}; };
struct esp8266_dev_s struct wifi_dev_s
{ {
uint8_t crefs; /* Number of times the device uint8_t crefs; /* Number of times the device
* has been opened */ * has been opened */
@ -120,18 +120,18 @@ struct esp8266_dev_s
* this structure */ * this structure */
sem_t waitsem; /* Used to wait for the sem_t waitsem; /* Used to wait for the
* availability of data */ * availability of data */
FAR const struct esp8266_config_s *config; /* Board configuration data */ FAR const struct wifi_config_s *config; /* Board configuration data */
struct work_s irqwork; /* Supports the interrupt struct work_s irqwork; /* Supports the interrupt
* handling "bottom half" */ * handling "bottom half" */
char *dev_name; char *dev_name;
int uart_fd; int uart_fd;
uart_dev_t *uart_dev; uart_dev_t *uart_dev;
int recv_size; int recv_size;
uint8_t recv_buf[ESP8266_RECV_BUF_SIZE]; uint8_t recv_buf[WIFI_RECV_BUF_SIZE];
}; };
void esp8266_notify(uart_dev_t *dev); void wifi_notify(uart_dev_t *dev);
void board_esp8266_initialize(void); void board_wifi_initialize(void);
#endif #endif

View File

@ -11,8 +11,8 @@
*/ */
/** /**
* @file ec200_demo.c * @file lte_demo.c
* @brief xidatong-riscv64 ec200_demo.c * @brief xidatong-riscv64 lte_demo.c
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022.08.22 * @date 2022.08.22
@ -21,19 +21,19 @@
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include "k210_ec200.h" #include "k210_lte.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "time.h" #include "time.h"
#define ec_print printf #define lte_print printf
#define EC200_DEMO_TIMEOUT 10 #define LTE_DEMO_TIMEOUT 10
// first: receive \n\rRDY\n\r // first: receive \n\rRDY\n\r
// second: AT -> OK // second: AT -> OK
// APN configuration "CTNET"(中国电信) // APN configuration "CTNET"(中国电信)
char *ec200_ctnet_cmd[] = char *lte_ctnet_cmd[] =
{ {
"AT\r\n", "AT\r\n",
@ -43,7 +43,7 @@ char *ec200_ctnet_cmd[] =
}; };
// APN configuration "CMNET"(中国移动) // APN configuration "CMNET"(中国移动)
char *ec200_cmnet_cmd[] = char *lte_cmnet_cmd[] =
{ {
"AT\r\n", "AT\r\n",
"AT+QICSGP=1,1,\"CMNET\",\"\",\"\",1\r\n", "AT+QICSGP=1,1,\"CMNET\",\"\",\"\",1\r\n",
@ -51,7 +51,7 @@ char *ec200_cmnet_cmd[] =
"AT+QIOPEN=1,0,\"TCP\",\"121.41.20.48\",8840,0,2\r\n" "AT+QIOPEN=1,0,\"TCP\",\"121.41.20.48\",8840,0,2\r\n"
}; };
static int ec200_read_with_time(int fd, char *buffer, int seconds) static int lte_read_with_time(int fd, char *buffer, int seconds)
{ {
int read_size = 0; int read_size = 0;
time_t cur_time = time(NULL); time_t cur_time = time(NULL);
@ -63,12 +63,12 @@ static int ec200_read_with_time(int fd, char *buffer, int seconds)
if(read_size < 0) if(read_size < 0)
{ {
ec_print("ec200 read failed %d\n", read_size); lte_print("lte read failed %d\n", read_size);
return -ETIME; return -ETIME;
} }
else if(read_size) else if(read_size)
{ {
ec_print("ec200 read size %d ok!\n", read_size); lte_print("lte read size %d ok!\n", read_size);
break; break;
} }
cur_time = time(NULL); cur_time = time(NULL);
@ -76,10 +76,10 @@ static int ec200_read_with_time(int fd, char *buffer, int seconds)
return read_size; return read_size;
} }
int ec200_check_demo(int fd, char *send_str, char *recv_str) int lte_check_demo(int fd, char *send_str, char *recv_str)
{ {
int ret; int ret;
char buf[EC200_RECV_BUF_SIZE] = {0}; char buf[LTE_RECV_BUF_SIZE] = {0};
if(send_str) if(send_str)
{ {
@ -87,52 +87,52 @@ int ec200_check_demo(int fd, char *send_str, char *recv_str)
if(ret < 0) if(ret < 0)
{ {
ec_print("ec200 write failed %d\n", ret); lte_print("lte write failed %d\n", ret);
return ret; return ret;
} }
ec_print("write %s ret = %d\n", send_str, ret); lte_print("write %s ret = %d\n", send_str, ret);
} }
ret = ec200_read_with_time(fd, buf, EC200_DEMO_TIMEOUT); ret = lte_read_with_time(fd, buf, LTE_DEMO_TIMEOUT);
if(ret < 0) if(ret < 0)
{ {
ec_print("ec200 read failed %d\n", ret); lte_print("lte read failed %d\n", ret);
return ret; return ret;
} }
ec_print("ec200 read: %s!\n", buf); lte_print("lte read: %s!\n", buf);
if(strstr(buf, recv_str)) if(strstr(buf, recv_str))
{ {
ec_print("ec200 %s found!\n", recv_str); lte_print("lte %s found!\n", recv_str);
} }
return ret; return ret;
} }
void EC200Demo(void) void LteDemo(void)
{ {
int fd; int fd;
ec_print("start %s\n", __func__); lte_print("start %s\n", __func__);
fd = open("/dev/ec200", O_RDWR); fd = open("/dev/lte", O_RDWR);
if(fd < 0) if(fd < 0)
{ {
ec_print("ec200 open failed %d\n", fd); lte_print("lte open failed %d\n", fd);
return; return;
} }
ec200_check_demo(fd, NULL, "RDY"); lte_check_demo(fd, NULL, "RDY");
ec200_check_demo(fd, "AT\r\n", "OK"); lte_check_demo(fd, "AT\r\n", "OK");
ec200_check_demo(fd, "AT+QICSGP=1,1,\"CTNET\",\"\",\"\",1\r\n", "OK"); lte_check_demo(fd, "AT+QICSGP=1,1,\"CTNET\",\"\",\"\",1\r\n", "OK");
ec200_check_demo(fd, "AT+QIACT=1\r\n", "OK"); lte_check_demo(fd, "AT+QIACT=1\r\n", "OK");
ec200_check_demo(fd, "AT+QIOPEN=1,0,\"TCP\",\"121.41.20.48\",8840,0,2\r\n", "OK"); lte_check_demo(fd, "AT+QIOPEN=1,0,\"TCP\",\"121.41.20.48\",8840,0,2\r\n", "OK");
up_mdelay(2000); up_mdelay(2000);
close(fd); close(fd);
ec_print("end %s\n", __func__); lte_print("end %s\n", __func__);
} }

View File

@ -20,7 +20,7 @@
#include "nuttx/arch.h" #include "nuttx/arch.h"
#include "w5500.h" #include "w5500.h"
#include "k210_w5500.h" #include "k210_enet.h"
#include "k210_gpio_common.h" #include "k210_gpio_common.h"
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -28,15 +28,15 @@
#define w_print printf #define w_print printf
#define w_delay() up_udelay(1) #define w_delay() up_udelay(1)
#define NCS_L() k210_gpiohs_set_value(FPIOA_W5500_NCS, GPIO_PV_LOW); w_delay(); #define NCS_L() k210_gpiohs_set_value(FPIOA_ENET_NCS, GPIO_PV_LOW); w_delay();
#define NCS_H() k210_gpiohs_set_value(FPIOA_W5500_NCS, GPIO_PV_HIGH); w_delay(); #define NCS_H() k210_gpiohs_set_value(FPIOA_ENET_NCS, GPIO_PV_HIGH); w_delay();
#define SCLK_L() k210_gpiohs_set_value(FPIOA_W5500_SCLK, GPIO_PV_LOW); w_delay(); #define SCLK_L() k210_gpiohs_set_value(FPIOA_ENET_SCLK, GPIO_PV_LOW); w_delay();
#define SCLK_H() k210_gpiohs_set_value(FPIOA_W5500_SCLK, GPIO_PV_HIGH); w_delay(); #define SCLK_H() k210_gpiohs_set_value(FPIOA_ENET_SCLK, GPIO_PV_HIGH); w_delay();
#define MOSI_L() k210_gpiohs_set_value(FPIOA_W5500_MOSI, GPIO_PV_LOW); w_delay(); #define MOSI_L() k210_gpiohs_set_value(FPIOA_ENET_MOSI, GPIO_PV_LOW); w_delay();
#define MOSI_H() k210_gpiohs_set_value(FPIOA_W5500_MOSI, GPIO_PV_HIGH); w_delay(); #define MOSI_H() k210_gpiohs_set_value(FPIOA_ENET_MOSI, GPIO_PV_HIGH); w_delay();
#define RST_L() k210_gpiohs_set_value(FPIOA_W5500_NRST, GPIO_PV_LOW); up_mdelay(200); #define RST_L() k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_LOW); up_mdelay(200);
#define RST_H() k210_gpiohs_set_value(FPIOA_W5500_NRST, GPIO_PV_HIGH); up_mdelay(200); #define RST_H() k210_gpiohs_set_value(FPIOA_ENET_NRST, GPIO_PV_HIGH); up_mdelay(200);
#define SOCK_WR_REG(_sock) (VDM | RWB_WRITE | (_sock * 0x20 + 0x10)) #define SOCK_WR_REG(_sock) (VDM | RWB_WRITE | (_sock * 0x20 + 0x10))
@ -61,7 +61,7 @@ static uint8_t spi_read_byte(void)
{ {
SCLK_H(); SCLK_H();
dat <<= 1; dat <<= 1;
dat |= k210_gpiohs_get_value(FPIOA_W5500_MISO); dat |= k210_gpiohs_get_value(FPIOA_ENET_MISO);
w_delay(); w_delay();
SCLK_L(); SCLK_L();
} }

View File

@ -11,8 +11,8 @@
*/ */
/** /**
* @file esp8266_demo.c * @file wifi_demo.c
* @brief xidatong-riscv64 esp8266_demo.c * @brief xidatong-riscv64 wifi_demo.c
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2022.08.22 * @date 2022.08.22
@ -21,18 +21,18 @@
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include "k210_esp8266.h" #include "k210_wifi.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "time.h" #include "time.h"
#define ec_print printf #define ec_print printf
#define ESP8266_DEMO_TIMEOUT 10 #define WIFI_DEMO_TIMEOUT 10
// first: receive \n\rRDY\n\r // first: receive \n\rRDY\n\r
// second: AT -> OK // second: AT -> OK
static int esp8266_read_with_time(int fd, char *buffer, int seconds) static int wifi_read_with_time(int fd, char *buffer, int seconds)
{ {
int read_size = 0; int read_size = 0;
time_t cur_time = time(NULL); time_t cur_time = time(NULL);
@ -44,12 +44,12 @@ static int esp8266_read_with_time(int fd, char *buffer, int seconds)
if(read_size < 0) if(read_size < 0)
{ {
ec_print("esp8266 read failed %d\n", read_size); ec_print("wifi read failed %d\n", read_size);
return -ETIME; return -ETIME;
} }
else if(read_size) else if(read_size)
{ {
ec_print("esp8266 read size %d ok!\n", read_size); ec_print("wifi read size %d ok!\n", read_size);
break; break;
} }
cur_time = time(NULL); cur_time = time(NULL);
@ -57,10 +57,10 @@ static int esp8266_read_with_time(int fd, char *buffer, int seconds)
return read_size; return read_size;
} }
int esp8266_check_demo(int fd, char *send_str, char *recv_str) int wifi_check_demo(int fd, char *send_str, char *recv_str)
{ {
int ret; int ret;
char buf[ESP8266_RECV_BUF_SIZE] = {0}; char buf[WIFI_RECV_BUF_SIZE] = {0};
if(send_str) if(send_str)
{ {
@ -68,49 +68,49 @@ int esp8266_check_demo(int fd, char *send_str, char *recv_str)
if(ret < 0) if(ret < 0)
{ {
ec_print("esp8266 write failed %d\n", ret); ec_print("wifi write failed %d\n", ret);
return ret; return ret;
} }
ec_print("write %s ret = %d\n", send_str, ret); ec_print("write %s ret = %d\n", send_str, ret);
} }
ret = esp8266_read_with_time(fd, buf, ESP8266_DEMO_TIMEOUT); ret = wifi_read_with_time(fd, buf, WIFI_DEMO_TIMEOUT);
if(ret < 0) if(ret < 0)
{ {
ec_print("esp8266 read failed %d\n", ret); ec_print("wifi read failed %d\n", ret);
return ret; return ret;
} }
ec_print("esp8266 read: %s!\n", buf); ec_print("wifi read: %s!\n", buf);
if(strstr(buf, recv_str)) if(strstr(buf, recv_str))
{ {
ec_print("esp8266 %s found!\n", recv_str); ec_print("wifi %s found!\n", recv_str);
} }
return ret; return ret;
} }
void Esp8266Demo(void) void WifiDemo(void)
{ {
int fd; int fd;
k210_gpiohs_set_value(FPIOA_ESP8266_EN, GPIO_PV_HIGH); k210_gpiohs_set_value(FPIOA_WIFI_EN, GPIO_PV_HIGH);
up_mdelay(100); up_mdelay(100);
ec_print("start %s\n", __func__); ec_print("start %s\n", __func__);
fd = open("/dev/esp8266", O_RDWR); fd = open("/dev/wifi", O_RDWR);
if(fd < 0) if(fd < 0)
{ {
ec_print("esp8266 open failed %d\n", fd); ec_print("wifi open failed %d\n", fd);
return; return;
} }
up_mdelay(2000); up_mdelay(2000);
esp8266_check_demo(fd, "AT\r\n", "OK"); wifi_check_demo(fd, "AT\r\n", "OK");
close(fd); close(fd);

View File

@ -1458,20 +1458,20 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb,
int cmd_Ch376(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_Ch376(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif #endif
#if defined(CONFIG_BSP_USING_EC200) && !defined(CONFIG_NSH_DISABLE_EC200) #if defined(CONFIG_BSP_USING_LTE) && !defined(CONFIG_NSH_DISABLE_LTE)
int cmd_EC200(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_Lte(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif #endif
#if defined(CONFIG_BSP_USING_CAN) && !defined(CONFIG_NSH_DISABLE_CAN) #if defined(CONFIG_BSP_USING_CAN) && !defined(CONFIG_NSH_DISABLE_CAN)
int cmd_CAN(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_CAN(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif #endif
#if defined(CONFIG_BSP_USING_ESP8266) && !defined(CONFIG_NSH_DISABLE_ESP8266) #if defined(CONFIG_BSP_USING_WIFI) && !defined(CONFIG_NSH_DISABLE_WIFI)
int cmd_Esp8266(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_Wifi(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif #endif
#if defined(CONFIG_BSP_USING_W5500) && !defined(CONFIG_NSH_DISABLE_W5500) #if defined(CONFIG_BSP_USING_ENET) && !defined(CONFIG_NSH_DISABLE_ENET)
int cmd_W5500(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_Enet(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif #endif
#if defined(CONFIG_K210_LCD) && !defined(CONFIG_NSH_DISABLE_LCD) #if defined(CONFIG_K210_LCD) && !defined(CONFIG_NSH_DISABLE_LCD)

View File

@ -67,12 +67,12 @@ int cmd_Ch376(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
/**************************************************************************** /****************************************************************************
* Name: cmd_Ch376 * Name: cmd_Ch376
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_BSP_USING_EC200) && !defined(CONFIG_NSH_DISABLE_EC200) #if defined(CONFIG_BSP_USING_LTE) && !defined(CONFIG_NSH_DISABLE_LTE)
extern void EC200Demo(void); extern void LteDemo(void);
int cmd_EC200(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) int cmd_Lte(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{ {
nsh_output(vtbl, "Hello, EC200!\n"); nsh_output(vtbl, "Hello, Lte!\n");
EC200Demo(); LteDemo();
return OK; return OK;
} }
#endif #endif
@ -91,14 +91,14 @@ int cmd_CAN(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: cmd_Esp8266 * Name: cmd_Wifi
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_BSP_USING_ESP8266) && !defined(CONFIG_NSH_DISABLE_ESP8266) #if defined(CONFIG_BSP_USING_WIFI) && !defined(CONFIG_NSH_DISABLE_WIFI)
extern void Esp8266Demo(void); extern void WifiDemo(void);
int cmd_Esp8266(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) int cmd_Wifi(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{ {
nsh_output(vtbl, "Hello, Esp8266!\n"); nsh_output(vtbl, "Hello, Wifi!\n");
Esp8266Demo(); WifiDemo();
return OK; return OK;
} }
#endif #endif
@ -106,12 +106,12 @@ int cmd_Esp8266(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
/**************************************************************************** /****************************************************************************
* Name: cmd_W5500 * Name: cmd_W5500
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_BSP_USING_W5500) && !defined(CONFIG_NSH_DISABLE_W5500) #if defined(CONFIG_BSP_USING_ENET) && !defined(CONFIG_NSH_DISABLE_ENET)
extern void W5500Demo(void); extern void EnetDemo(void);
int cmd_W5500(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) int cmd_Enet(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{ {
nsh_output(vtbl, "Hello, W5500!\n"); nsh_output(vtbl, "Hello, Enet!\n");
W5500Demo(); EnetDemo();
return OK; return OK;
} }
#endif #endif

View File

@ -604,20 +604,20 @@ static const struct cmdmap_s g_cmdmap[] =
{ "ch376", cmd_Ch376, 1, 1, "[ch376 demo cmd.]" }, { "ch376", cmd_Ch376, 1, 1, "[ch376 demo cmd.]" },
#endif #endif
#if defined(CONFIG_BSP_USING_EC200) && !defined(CONFIG_NSH_DISABLE_EC200) #if defined(CONFIG_BSP_USING_LTE) && !defined(CONFIG_NSH_DISABLE_LTE)
{ "ec200", cmd_EC200, 1, 1, "[ec200 demo cmd.]" }, { "lte", cmd_Lte, 1, 1, "[Lte demo cmd.]" },
#endif #endif
#if defined(CONFIG_BSP_USING_CAN) && !defined(CONFIG_NSH_DISABLE_CAN) #if defined(CONFIG_BSP_USING_CAN) && !defined(CONFIG_NSH_DISABLE_CAN)
{ "can", cmd_CAN, 1, 1, "[can demo cmd.]" }, { "can", cmd_CAN, 1, 1, "[CAN demo cmd.]" },
#endif #endif
#if defined(CONFIG_BSP_USING_ESP8266) && !defined(CONFIG_NSH_DISABLE_ESP8266) #if defined(CONFIG_BSP_USING_WIFI) && !defined(CONFIG_NSH_DISABLE_WIFI)
{ "esp8266", cmd_Esp8266, 1, 1, "[can demo cmd.]" }, { "wifi", cmd_Wifi, 1, 1, "[Wifi demo cmd.]" },
#endif #endif
#if defined(CONFIG_BSP_USING_W5500) && !defined(CONFIG_NSH_DISABLE_W5500) #if defined(CONFIG_BSP_USING_ENET) && !defined(CONFIG_NSH_DISABLE_ENET)
{ "w5500", cmd_W5500, 1, 1, "[can demo cmd.]" }, { "enet", cmd_Enet, 1, 1, "[Ethernet demo cmd.]" },
#endif #endif
#if defined(CONFIG_K210_LCD) && !defined(CONFIG_NSH_DISABLE_LCD) #if defined(CONFIG_K210_LCD) && !defined(CONFIG_NSH_DISABLE_LCD)

View File

@ -1890,6 +1890,132 @@ config DEBUG_CH438_INFO
endif # DEBUG_CH438 endif # DEBUG_CH438
config DEBUG_CH376
bool "CH376 Debug Features"
default n
---help---
Enable CH376 debug features.
if DEBUG_CH376
config DEBUG_CH376_ERROR
bool "CH376 Error Output"
default n
depends on DEBUG_ERROR
---help---
Enable CH376 error output to SYSLOG.
config DEBUG_CH376_WARN
bool "CH376 Warnings Output"
default n
depends on DEBUG_WARN
---help---
Enable CH376 warning output to SYSLOG.
config DEBUG_CH376_INFO
bool "CH376 Informational Output"
default n
depends on DEBUG_INFO
---help---
Enable CH376 informational output to SYSLOG.
endif # DEBUG_CH376
config DEBUG_WIFI
bool "WIFI Debug Features"
default n
---help---
Enable WIFI debug features.
if DEBUG_WIFI
config DEBUG_WIFI_ERROR
bool "WIFI Error Output"
default n
depends on DEBUG_ERROR
---help---
Enable WIFI error output to SYSLOG.
config DEBUG_WIFI_WARN
bool "WIFI Warnings Output"
default n
depends on DEBUG_WARN
---help---
Enable WIFI warning output to SYSLOG.
config DEBUG_WIFI_INFO
bool "WIFI Informational Output"
default n
depends on DEBUG_INFO
---help---
Enable WIFI informational output to SYSLOG.
endif # DEBUG_WIFI
config DEBUG_LTE
bool "LTE Debug Features"
default n
---help---
Enable LTE debug features.
if DEBUG_LTE
config DEBUG_LTE_ERROR
bool "LTE Error Output"
default n
depends on DEBUG_ERROR
---help---
Enable LTE error output to SYSLOG.
config DEBUG_LTE_WARN
bool "LTE Warnings Output"
default n
depends on DEBUG_WARN
---help---
Enable LTE warning output to SYSLOG.
config DEBUG_LTE_INFO
bool "LTE Informational Output"
default n
depends on DEBUG_INFO
---help---
Enable LTE informational output to SYSLOG.
endif # DEBUG_LTE
config DEBUG_ENET
bool "ENET Debug Features"
default n
---help---
Enable ENET debug features.
if DEBUG_ENET
config DEBUG_ENET_ERROR
bool "ENET Error Output"
default n
depends on DEBUG_ERROR
---help---
Enable ENET error output to SYSLOG.
config DEBUG_ENET_WARN
bool "ENET Warnings Output"
default n
depends on DEBUG_WARN
---help---
Enable ENET warning output to SYSLOG.
config DEBUG_ENET_INFO
bool "ENET Informational Output"
default n
depends on DEBUG_INFO
---help---
Enable ENET informational output to SYSLOG.
endif # DEBUG_ENET
endif # DEBUG_FEATURES endif # DEBUG_FEATURES
config DEBUG_TCBINFO config DEBUG_TCBINFO