forked from xuos/xiuos
add can and flash driver for hc32f4a0 in XiZi_IIoT
This commit is contained in:
@@ -171,6 +171,18 @@ menu "test app"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_CAN
|
||||
select BSP_USING_CAN
|
||||
bool "Config test can"
|
||||
default n
|
||||
if USER_TEST_CAN
|
||||
if ADD_XIZI_FETURES
|
||||
config CAN_DEV_DRIVER
|
||||
string "Set can dev path"
|
||||
default "/dev/can2_dev1"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_CAMERA
|
||||
select BSP_USING_CAMERA
|
||||
select BSP_USING_LCD
|
||||
|
||||
@@ -91,6 +91,10 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_FLASH),y)
|
||||
SRC_FILES += test_flash.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_CAN),y)
|
||||
SRC_FILES += test_can.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
66
APP_Framework/Applications/app_test/test_can.c
Normal file
66
APP_Framework/Applications/app_test/test_can.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
|
||||
void TestCAN(void)
|
||||
{
|
||||
// config CAN pin(SCL:34.SDA:35) in menuconfig
|
||||
int can_fd = PrivOpen(CAN_DEV_DRIVER, O_RDWR);
|
||||
if (can_fd < 0)
|
||||
{
|
||||
printf("open can_fd fd error:%d\n", can_fd);
|
||||
return;
|
||||
}
|
||||
printf("CAN open successful!\n");
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = CAN_TYPE;
|
||||
|
||||
struct CanDriverConfigure can_config;
|
||||
can_config.brp = 8U;
|
||||
can_config.tbs1 = 1U + 8U;
|
||||
can_config.tbs2 = 4U;
|
||||
can_config.tsjw = 4U;
|
||||
can_config.mode = 0U;
|
||||
|
||||
ioctl_cfg.args = (void *)&can_config;
|
||||
|
||||
if (0 != PrivIoctl(can_fd, OPE_INT, &ioctl_cfg))
|
||||
{
|
||||
printf("init can fd error %d\n", can_fd);
|
||||
PrivClose(can_fd);
|
||||
return;
|
||||
}
|
||||
printf("CAN configure successful!\n");
|
||||
|
||||
uint8_t data_buff[64u] = {1,2,3,4,4,3,2,1};
|
||||
struct CanSendConfigure frame_send;
|
||||
frame_send.ide=0;
|
||||
frame_send.stdid = 0x55;
|
||||
frame_send.rtr=0;
|
||||
frame_send.data_lenth=8;
|
||||
frame_send.data = data_buff;
|
||||
|
||||
struct CanSendConfigure frame_recv;
|
||||
uint8_t recv_buff[65U] = {0};
|
||||
frame_recv.data = recv_buff;
|
||||
|
||||
// CAN write
|
||||
while (1)
|
||||
{
|
||||
PrivTaskDelay(500);
|
||||
PrivWrite(can_fd, &frame_send, NONE);
|
||||
PrivTaskDelay(500);
|
||||
PrivRead(can_fd, &frame_recv, NONE);
|
||||
// if any data has received,Then printf message
|
||||
if(frame_recv.data_lenth > 0){
|
||||
printf("ID %08x:%s\n",frame_recv.exdid,frame_recv.data);
|
||||
}
|
||||
}
|
||||
|
||||
PrivClose(can_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestCAN, a can test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
@@ -105,6 +105,7 @@ void TestTouch(void)
|
||||
graph_param.pixel_info.y_endpos = touch_pixel.y+10;
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
}
|
||||
PrivClose(lcd_fd);
|
||||
PrivClose(touch_fd);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,3 +26,5 @@ void mnist_app(void);
|
||||
int tfmnist(void) {
|
||||
mnist_app();
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(tfmnist, a mnist test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
Reference in New Issue
Block a user