From e007b5567da1758e9cc1b7ab738fd462749497dc Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Thu, 5 May 2022 18:22:42 +0800 Subject: [PATCH] Register ch438 to character driver --- .../aiit_board/xidatong/Kconfig | 40 +++++++++++++- .../aiit_board/xidatong/src/Makefile | 6 ++- .../aiit_board/xidatong/src/ch438_demo.c | 16 +++--- .../aiit_board/xidatong/src/imxrt_bringup.c | 8 +++ .../aiit_board/xidatong/src/imxrt_ch438.c | 54 +++++++++++++++++-- .../aiit_board/xidatong/src/imxrt_ch438.h | 19 +++++++ .../app_match_nuttx/apps/nshlib/Kconfig | 5 ++ .../app_match_nuttx/apps/nshlib/nsh.h | 4 +- .../apps/nshlib/nsh_Applicationscmd.c | 9 ++-- .../app_match_nuttx/apps/nshlib/nsh_command.c | 4 +- .../app_match_nuttx/nuttx/Kconfig | 32 +++++++++++ 11 files changed, 177 insertions(+), 20 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/Kconfig index e9b8024af..44d81f49f 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/Kconfig @@ -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 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/Makefile b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/Makefile index 7f4a76155..45b928370 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/Makefile +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/Makefile @@ -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 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/ch438_demo.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/ch438_demo.c index f73be6e83..88861f5d5 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/ch438_demo.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/ch438_demo.c @@ -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 #endif +#ifdef CONFIG_BSP_USING_CH438 +# include "imxrt_ch438.h" +#endif + #include "xidatong.h" #include /* 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; } diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.c b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.c index 695485f40..e9c169b3f 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.c @@ -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 } \ No newline at end of file diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.h b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.h index c2cbc4eec..834668a26 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong/src/imxrt_ch438.h @@ -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 diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig index 25a54fb13..96c5fb6c5 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig @@ -587,6 +587,11 @@ config NSH_DISABLE_XD bool "Disable xd" default y if DEFAULT_SMALL default n if !DEFAULT_SMALL + +config NSH_DISABLE_CH438 + bool "Disable the ch438 demo." + default n + config NSH_DISABLE_HCHO_TB600B_WQ_HCHO1OS bool "Disable the sensor tb600b_wq_hcho1os." default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index f46851a37..912397b01 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1417,7 +1417,9 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, FAR void *arg); #endif -int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) + int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif #if defined(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS) && !defined(CONFIG_NSH_DISABLE_HCHO_TB600B_WQ_HCHO1OS) int cmd_Hcho1os(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 47693892d..465f21be4 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -36,8 +36,10 @@ #include "nsh.h" #include "nsh_console.h" -extern int FrameworkInit(void); - +/**************************************************************************** + * Name: cmd_Ch438 + ****************************************************************************/ +#if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) extern void CH438Demo(void); int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { @@ -45,8 +47,7 @@ int cmd_Ch438(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) CH438Demo(); return OK; } - - +#endif /**************************************************************************** * Name: cmd_Hcho1os diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index ceecb0f79..efe59c107 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -590,7 +590,9 @@ static const struct cmdmap_s g_cmdmap[] = { "xd", cmd_xd, 3, 3, " " }, #endif - { "ch438", cmd_Ch438, 1, 1, "[ch438 demo cmd.]" }, +#if defined(CONFIG_BSP_USING_CH438) && !defined(CONFIG_NSH_DISABLE_CH438) + { "ch438", cmd_Ch438, 1, 1, "[ch438 demo cmd.]" }, +#endif #if defined(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS) && !defined(CONFIG_NSH_DISABLE_HCHO_TB600B_WQ_HCHO1OS) { "hcho1os", cmd_Hcho1os, 1, 1, "[get the concentration of formaldehyde with sensor tb600b_wq_hcho1os.]" }, diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/Kconfig index d12f9651c..e7243e890 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/nuttx/Kconfig @@ -1812,6 +1812,38 @@ config DEBUG_VIDEO_INFO Enable video informational output to SYSLOG. endif # DEBUG_VIDEO + +config DEBUG_CH438 + bool "CH438 Debug Features" + default n + ---help--- + Enable CH438 debug features. + +if DEBUG_CH438 + +config DEBUG_CH438_ERROR + bool "CH438 Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable CH438 error output to SYSLOG. + +config DEBUG_CH438_WARN + bool "CH438 Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable CH438 warning output to SYSLOG. + +config DEBUG_CH438_INFO + bool "CH438 Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable CH438 informational output to SYSLOG. + +endif # DEBUG_CH438 + endif # DEBUG_FEATURES config ARCH_HAVE_STACKCHECK