forked from xuos/xiuos
Register ch438 to character driver
This commit is contained in:
@@ -83,5 +83,43 @@ config XIDATONG_USB_AUTOMOUNT_UDELAY
|
||||
|
||||
endif # XIDATONG_USB_AUTOMOUNT
|
||||
|
||||
menuconfig BSP_USING_CH438
|
||||
bool "Using CH438 device"
|
||||
default n
|
||||
|
||||
endif
|
||||
if BSP_USING_CH438
|
||||
config CH438_EXTUART0
|
||||
bool "using ch438 port 0"
|
||||
default n
|
||||
|
||||
config CH438_EXTUART1
|
||||
bool "using ch438 port 1"
|
||||
default n
|
||||
|
||||
config CH438_EXTUART2
|
||||
bool "using ch438 port 2"
|
||||
default n
|
||||
|
||||
config CH438_EXTUART3
|
||||
bool "using ch438 port 3"
|
||||
default n
|
||||
|
||||
config CH438_EXTUART4
|
||||
bool "using ch438 port 4"
|
||||
default n
|
||||
|
||||
config CH438_EXTUART5
|
||||
bool "using ch438 port 5"
|
||||
default n
|
||||
|
||||
config CH438_EXTUART6
|
||||
bool "using ch438 port 6"
|
||||
default n
|
||||
|
||||
config CH438_EXTUART7
|
||||
bool "using ch438 port 7"
|
||||
default n
|
||||
|
||||
endif # BSP_USING_CH438
|
||||
|
||||
endif # ARCH_BOARD_XIDATONG
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
include $(TOPDIR)/Make.defs
|
||||
|
||||
CSRCS = imxrt_boot.c imxrt_flexspi_nor_boot.c imxrt_flexspi_nor_flash.c imxrt_ch438.c ch438_demo.c
|
||||
CSRCS = imxrt_boot.c imxrt_flexspi_nor_boot.c imxrt_flexspi_nor_flash.c
|
||||
|
||||
ifeq ($(CONFIG_IMXRT_SDRAMC),y)
|
||||
CSRCS += imxrt_sdram.c
|
||||
@@ -82,4 +82,8 @@ ifeq ($(CONFIG_XIDATONG_SDIO_AUTOMOUNT),y)
|
||||
CSRCS += imxrt_mmcsd_automount.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BSP_USING_CH438),y)
|
||||
CSRCS += imxrt_ch438.c ch438_demo.c
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/boards/Board.mk
|
||||
|
||||
@@ -53,26 +53,26 @@ void CH438Demo(void)
|
||||
int i;
|
||||
char buffer[256];
|
||||
int readlen;
|
||||
_info("ch438_main\n");
|
||||
Ch438InitDefault();
|
||||
ch438_register("/dev/ext_uart3",2);
|
||||
ch438_register("/dev/ext_uart2",1);
|
||||
|
||||
fd1 = open("/dev/ext_uart3", O_RDWR);
|
||||
fd1 = open("/dev/extuart_dev2", O_RDWR);
|
||||
write(fd1, "AT+BAUD=?",9);
|
||||
readlen = read(fd1, buffer, 256);
|
||||
|
||||
for(i=0;i<readlen;++i)
|
||||
{
|
||||
_info("%c(0x%x)\n", buffer[i], buffer[i]);
|
||||
printf("%c(0x%x)\n", buffer[i], buffer[i]);
|
||||
}
|
||||
close(fd1);
|
||||
|
||||
up_mdelay(1000);
|
||||
|
||||
fd2 = open("/dev/ext_uart2", O_RDWR);
|
||||
fd2 = open("/dev/extuart_dev1", O_RDWR);
|
||||
write(fd2, "AT+BAUD=?",9);
|
||||
readlen = read(fd2, buffer, 256);
|
||||
for(i=0;i<readlen;++i)
|
||||
{
|
||||
_info("%c(0x%x)\n", buffer[i], buffer[i]);
|
||||
printf("%c(0x%x)\n", buffer[i], buffer[i]);
|
||||
}
|
||||
|
||||
close(fd2);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
# include <nuttx/usb/usbmonitor.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BSP_USING_CH438
|
||||
# include "imxrt_ch438.h"
|
||||
#endif
|
||||
|
||||
#include "xidatong.h"
|
||||
|
||||
#include <arch/board/board.h> /* Must always be included last */
|
||||
@@ -181,6 +185,10 @@ int imxrt_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BSP_USING_CH438
|
||||
board_ch438_initialize();
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ static size_t ImxrtCh438ReadData(uint8_t ext_uart_no)
|
||||
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
|
||||
REG_MSR_ADDR = offsetadd[ext_uart_no] | REG_MSR0_ADDR;
|
||||
InterruptStatus = ReadCH438Data(REG_IIR_ADDR) & 0x0f; /* 读串口的中断状态 */
|
||||
_info("InterruptStatus is %d\n", InterruptStatus);
|
||||
ch438info("InterruptStatus is %d\n", InterruptStatus);
|
||||
|
||||
switch(InterruptStatus)
|
||||
{
|
||||
@@ -498,7 +498,7 @@ void Ch438InitDefault(void)
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
_info("pthread_mutex_init failed, status=%d\n", ret);
|
||||
ch438err("pthread_mutex_init failed, status=%d\n", ret);
|
||||
}
|
||||
|
||||
/* Initialize the condition variable */
|
||||
@@ -506,13 +506,13 @@ void Ch438InitDefault(void)
|
||||
ret = pthread_cond_init(&cond, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
_info("pthread_cond_init failed, status=%d\n", ret);
|
||||
ch438err("pthread_cond_init failed, status=%d\n", ret);
|
||||
}
|
||||
|
||||
ret = task_create("ch438_task", 60, 8192, getInterruptStatus, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
_info("task create failed, status=%d\n", ret);
|
||||
ch438err("task create failed, status=%d\n", ret);
|
||||
}
|
||||
|
||||
ImxrtCH438Init();
|
||||
@@ -615,6 +615,7 @@ int ch438_register(FAR const char *devpath, uint8_t port)
|
||||
priv = (FAR struct ch438_dev_s *)kmm_malloc(sizeof(struct ch438_dev_s));
|
||||
if (priv == NULL)
|
||||
{
|
||||
ch438err("ERROR: Failed to allocate instance\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@@ -624,8 +625,53 @@ int ch438_register(FAR const char *devpath, uint8_t port)
|
||||
ret = register_driver(devpath, &g_ch438fops, 0666, priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
ch438err("ERROR: Failed to register driver: %d\n", ret);
|
||||
kmm_free(priv);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_ch438_initialize
|
||||
*
|
||||
* Description:
|
||||
* ch438 initialize
|
||||
*
|
||||
****************************************************************************/
|
||||
void board_ch438_initialize(void)
|
||||
{
|
||||
Ch438InitDefault();
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART0
|
||||
ch438_register("/dev/extuart_dev0", 0);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART1
|
||||
ch438_register("/dev/extuart_dev1", 1);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART2
|
||||
ch438_register("/dev/extuart_dev2", 2);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART3
|
||||
ch438_register("/dev/extuart_dev3", 3);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART4
|
||||
ch438_register("/dev/extuart_dev4", 4);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART5
|
||||
ch438_register("/dev/extuart_dev5", 5);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART6
|
||||
ch438_register("/dev/extuart_dev6", 6);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CH438_EXTUART7
|
||||
ch438_register("/dev/extuart_dev7", 7);
|
||||
#endif
|
||||
}
|
||||
@@ -299,10 +299,29 @@
|
||||
GPIO_PORT1 | GPIO_PIN29)
|
||||
|
||||
|
||||
#ifdef CONFIG_DEBUG_CH438_ERROR
|
||||
# define ch438err _err
|
||||
#else
|
||||
# define ch438err _none
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CH438_WARN
|
||||
# define ch438warn _warn
|
||||
#else
|
||||
# define ch438warn _none
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_CH438_INFO
|
||||
# define ch438info _info
|
||||
#else
|
||||
# define ch438info _none
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
int getInterruptStatus(int argc, char **argv);
|
||||
void Ch438InitDefault(void);
|
||||
int ch438_register(FAR const char *devpath,uint8_t port);
|
||||
void board_ch438_initialize(void);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user