diff --git a/APP_Framework/Applications/app_test/Kconfig b/APP_Framework/Applications/app_test/Kconfig index 3302d3596..c3fde9f87 100644 --- a/APP_Framework/Applications/app_test/Kconfig +++ b/APP_Framework/Applications/app_test/Kconfig @@ -59,7 +59,7 @@ menu "test app" select RESOURCES_PIN select BSP_USING_UART2 select BSP_USING_LORA - bool "Config test uart" + bool "Config test uart(loraE220)" default n if USER_TEST_LORA if ADD_XIZI_FETURES @@ -72,6 +72,24 @@ menu "test app" endif endif + menuconfig USER_TEST_RS485 + select BSP_USING_UART + select BSP_USING_GPIO + select RESOURCES_PIN + select BSP_USING_UART1 + bool "Config test uart(RS485)" + default n + if USER_TEST_RS485 + if ADD_XIZI_FETURES + config RS485_UART_DEV_DRIVER + string "Set uart dev path" + default "/dev/uart1_dev1" + config RS485_PIN_DEV_DRIVER + string "Set pin dev path" + default "/dev/pin_dev" + endif + endif + menuconfig USER_TEST_RTC select BSP_USING_RTC bool "Config test rtc" diff --git a/APP_Framework/Applications/app_test/Makefile b/APP_Framework/Applications/app_test/Makefile index ad0368c10..b511ec9e6 100644 --- a/APP_Framework/Applications/app_test/Makefile +++ b/APP_Framework/Applications/app_test/Makefile @@ -53,5 +53,9 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y) SRC_FILES += test_rtc.c endif + ifeq ($(CONFIG_USER_TEST_RS485),y) + SRC_FILES += test_rs485.c + endif + include $(KERNEL_ROOT)/compiler.mk endif diff --git a/APP_Framework/Applications/app_test/test_loraE220.c b/APP_Framework/Applications/app_test/test_loraE220.c index 4ea400669..c4409dd21 100644 --- a/APP_Framework/Applications/app_test/test_loraE220.c +++ b/APP_Framework/Applications/app_test/test_loraE220.c @@ -17,7 +17,7 @@ #define BSP_E220_M0_PIN 32 #define BSP_E220_M1_PIN 33 -void TestLora(int argc, char *agrv[]) +void TestLora(int argc, char *argv[]) { char uart_recvbuff[100]; memset(uart_recvbuff, 0, sizeof(uart_recvbuff)); @@ -39,7 +39,6 @@ void TestLora(int argc, char *agrv[]) struct PinStat pin_m0; struct PinStat pin_m1; - struct PinStat pin_key; pin_m0.pin = BSP_E220_M0_PIN; pin_m1.pin = BSP_E220_M1_PIN; @@ -47,19 +46,10 @@ void TestLora(int argc, char *agrv[]) struct PrivIoctlCfg ioctl_cfg; struct PinParam pin_param; pin_param.cmd = GPIO_CONFIG_MODE; - pin_param.mode = GPIO_CFG_INPUT; - - ioctl_cfg.ioctl_driver_type = PIN_TYPE; - ioctl_cfg.args = (void *)&pin_param; - if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) - { - printf("ioctl pin fd error %d\n", pin_fd); - PrivClose(pin_fd); - return; - } - pin_param.mode = GPIO_CFG_OUTPUT; pin_param.pin = BSP_E220_M0_PIN; + ioctl_cfg.ioctl_driver_type = PIN_TYPE; + ioctl_cfg.args = &pin_param; if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) { printf("ioctl pin fd error %d\n", pin_fd); @@ -106,7 +96,7 @@ void TestLora(int argc, char *agrv[]) printf("lora configure into sleep(configure) mode\n"); // send configure data, and receive the same length of data - char sendbuff[] = {0xC0, 0x00, 0x05, 0x19, 0x49, 0xE6, 0x00, 0x17}; // config as address 1949 CH17 2.4kps + char sendbuff[] = {0xC0, 0x00, 0x05, 0x19, 0x49, 0xE6, 0x00, 0x17}; // config as address 1949 CH17 36.8kps PrivTaskDelay(2000); @@ -150,6 +140,8 @@ void TestLora(int argc, char *agrv[]) PrivRead(uart_fd, uart_recvbuff, sizeof(uart_recvbuff)); printf("Receive Data is :\n%s\n", uart_recvbuff); } + PrivClose(pin_fd); + PrivClose(uart_fd); } PRIV_SHELL_CMD_FUNCTION(TestLora, a lora test sample, PRIV_SHELL_CMD_MAIN_ATTR); diff --git a/APP_Framework/Applications/app_test/test_rs485.c b/APP_Framework/Applications/app_test/test_rs485.c index e69de29bb..8b9fd5e1e 100644 --- a/APP_Framework/Applications/app_test/test_rs485.c +++ b/APP_Framework/Applications/app_test/test_rs485.c @@ -0,0 +1,87 @@ +#include +#include +#include + +#define BSP_485_DIR_PIN 24 + +void Test485(void) +{ + int pin_fd = PrivOpen(RS485_PIN_DEV_DRIVER, O_RDWR); + if (pin_fd < 0) + { + printf("open pin fd error:%d\n", pin_fd); + return; + } + + int uart_fd = PrivOpen(RS485_UART_DEV_DRIVER, O_RDWR); + if (uart_fd < 0) + { + printf("open pin fd error:%d\n", uart_fd); + return; + } + printf("uart and pin fopen success\n"); + + //config led pin in board + struct PinParam pin_parameter; + memset(&pin_parameter, 0, sizeof(struct PinParam)); + pin_parameter.cmd = GPIO_CONFIG_MODE; + pin_parameter.pin = BSP_485_DIR_PIN; + pin_parameter.mode = GPIO_CFG_OUTPUT; + + struct PrivIoctlCfg ioctl_cfg; + ioctl_cfg.ioctl_driver_type = PIN_TYPE; + ioctl_cfg.args = (void *)&pin_parameter; + + if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) { + printf("ioctl pin fd error %d\n", pin_fd); + PrivClose(pin_fd); + return; + } + + struct SerialDataCfg uart_cfg; + memset(&uart_cfg, 0, sizeof(struct SerialDataCfg)); + + uart_cfg.serial_baud_rate = BAUD_RATE_115200; + uart_cfg.serial_data_bits = DATA_BITS_8; + uart_cfg.serial_stop_bits = STOP_BITS_1; + uart_cfg.serial_parity_mode = PARITY_NONE; + uart_cfg.serial_bit_order = BIT_ORDER_LSB; + uart_cfg.serial_invert_mode = NRZ_NORMAL; + uart_cfg.serial_buffer_size = SERIAL_RB_BUFSZ; + uart_cfg.serial_timeout = 1000; + uart_cfg.is_ext_uart = 0; + + ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; + ioctl_cfg.args = (void *)&uart_cfg; + + if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) + { + printf("ioctl uart fd error %d\n", uart_fd); + PrivClose(uart_fd); + return; + } + + struct PinStat pin_dir; + pin_dir.pin = BSP_485_DIR_PIN; + while (1) + { + pin_dir.val = GPIO_HIGH; + PrivWrite(pin_fd,&pin_dir,0); + PrivWrite(uart_fd,"Hello world!\n",sizeof("Hello world!\n")); + PrivTaskDelay(100); + + pin_dir.val = GPIO_LOW; + PrivWrite(pin_fd,&pin_dir,0); + char recv_buff[100]; + memset(recv_buff,0,sizeof(recv_buff)); + PrivRead(uart_fd,recv_buff,20); + printf("%s",recv_buff); + PrivTaskDelay(100); + } + PrivClose(pin_fd); + PrivClose(uart_fd); + return; + +} + +PRIV_SHELL_CMD_FUNCTION(Test485, a RS485 test sample, PRIV_SHELL_CMD_MAIN_ATTR); \ No newline at end of file diff --git a/APP_Framework/Applications/app_test/test_rtc.c b/APP_Framework/Applications/app_test/test_rtc.c index 683478dd1..3a95c6cea 100644 --- a/APP_Framework/Applications/app_test/test_rtc.c +++ b/APP_Framework/Applications/app_test/test_rtc.c @@ -13,7 +13,7 @@ void TestRTC(int argc,char *argv[]) if(argc>1){ int times = atoi(argv[1]); - printf("Time will be printf times %d\n",times); + printf("Time will be printf %d times\n",times); struct RtcDrvConfigureParam rtc_para; rtc_para.rtc_operation_cmd = OPER_RTC_SET_TIME; *(rtc_para.time) = 0; @@ -26,12 +26,12 @@ void TestRTC(int argc,char *argv[]) rtc_para.rtc_operation_cmd = OPER_RTC_GET_TIME; for(size_t i=0;i