forked from xuos/xiuos
rs485 test example
This commit is contained in:
parent
e7175c2745
commit
8c929ba701
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
#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);
|
|
@ -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<times;i++){
|
||||
PrivIoctl(rtc_fd,0,&ioctl_cfg);
|
||||
printf("The time now is %x,%d\n",*(rtc_para.time),*(rtc_para.time));
|
||||
printf("The time now is %d\n",*(rtc_para.time));
|
||||
PrivTaskDelay(5000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PrivClose(rtc_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,10 @@ static struct io_config
|
|||
IOCONFIG(BSP_E220_M1_PIN, HS_GPIO(FUNC_GPIOHS11)),
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_RS485
|
||||
IOCONFIG(BSP_485_DIR_PIN,HS_GPIO(FUNC_GPIOHS12));
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_LED
|
||||
IOCONFIG(BSP_LED_PIN,FUNC_GPIO5);
|
||||
#endif
|
||||
|
|
|
@ -103,6 +103,11 @@ enum HS_GPIO_CONFIG
|
|||
#define BSP_E220_M0_PIN 32
|
||||
#define BSP_E220_M1_PIN 33
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_RS485
|
||||
#define BSP_485_DIR_PIN 24
|
||||
#endif
|
||||
|
||||
extern int IoConfigInit(void);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue