forked from xuos/xiuos
example for edu-riscv64:watchdog,lcd and timer
This commit is contained in:
@@ -102,6 +102,43 @@ menu "test app"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_HWTIMER
|
||||
select BSP_USING_HWTIMER
|
||||
select BSP_USING_GPIO
|
||||
bool "Config test hwtimer"
|
||||
default n
|
||||
if USER_TEST_HWTIMER
|
||||
if ADD_XIZI_FETURES
|
||||
config HWTIMER_PIN_DEV_DRIVER
|
||||
string "Set pin dev path"
|
||||
default "/dev/pin_dev"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_WDT
|
||||
select BSP_USING_WDT0
|
||||
bool "Config test watchdog"
|
||||
default n
|
||||
if USER_TEST_WDT
|
||||
if ADD_XIZI_FETURES
|
||||
config WDT0_DEV_DRIVER
|
||||
string "Set wdt dev path"
|
||||
default "/dev/wdt0_dev0"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_LCD_EDU
|
||||
select BSP_USING_LCD
|
||||
bool "Config test lcd in PrivOpen"
|
||||
default n
|
||||
if USER_TEST_LCD_EDU
|
||||
if ADD_XIZI_FETURES
|
||||
config EDU_LCD_DEV_DRIVER
|
||||
string "Set lcd dev path"
|
||||
default "/dev/lcd_dev"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_I2C
|
||||
select BSP_USING_I2C
|
||||
bool "Config test i2c"
|
||||
@@ -110,7 +147,7 @@ menu "test app"
|
||||
if ADD_XIZI_FETURES
|
||||
config I2C_DEV_DRIVER
|
||||
string "Set i2c dev path"
|
||||
default "/dev/i2c_dev"
|
||||
default "/dev/i2c1_dev0"
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@@ -57,5 +57,17 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES += test_rs485.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_HWTIMER),y)
|
||||
SRC_FILES += test_hwtimer.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_LCD_EDU),y)
|
||||
SRC_FILES += test_lcd_edu.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_WDT),y)
|
||||
SRC_FILES += test_wdt.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
#define BSP_LED_PIN 29
|
||||
#define NULL_PARAMETER 0
|
||||
|
||||
static uint16_t pinval=0;
|
||||
|
||||
void ledflip(void *parameter)
|
||||
{
|
||||
int tmp_fd = *(int*)parameter;
|
||||
struct PinStat pin_led;
|
||||
pin_led.pin = BSP_LED_PIN;
|
||||
pin_led.val = !pinval;
|
||||
pinval = !pinval;
|
||||
PrivWrite(tmp_fd,&pin_led,NULL_PARAMETER);
|
||||
printf("Timer has callback once\n");
|
||||
}
|
||||
|
||||
void TestHwTimer(int argc, char *argv[])
|
||||
{
|
||||
x_ticks_t period = 100;//uint:10ms
|
||||
|
||||
if(argc>1){
|
||||
period = (x_ticks_t)atoi(argv[1]);
|
||||
}
|
||||
|
||||
|
||||
int pin_fd = PrivOpen(HWTIMER_PIN_DEV_DRIVER, O_RDWR);
|
||||
if(pin_fd<0){
|
||||
printf("open pin fd error:%d\n",pin_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
//config led pin in board
|
||||
struct PinParam parameter;
|
||||
parameter.cmd = GPIO_CONFIG_MODE;
|
||||
parameter.pin = BSP_LED_PIN;
|
||||
parameter.mode = GPIO_CFG_OUTPUT;
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||
ioctl_cfg.args = (void *)¶meter;
|
||||
|
||||
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
printf("ioctl pin fd error %d\n", pin_fd);
|
||||
PrivClose(pin_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
int32 timer_handle = KCreateTimer("LED on and off by 1s",&ledflip,&pin_fd,period,TIMER_TRIGGER_PERIODIC);
|
||||
|
||||
KTimerStartRun(timer_handle);
|
||||
PrivTaskDelay(10000);
|
||||
KTimerQuitRun(timer_handle);
|
||||
|
||||
KDeleteTimer(timer_handle);
|
||||
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestHwTimer, a timer test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
@@ -2,10 +2,49 @@
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
#define I2C_SLAVE_ADDRESS 0x0012U
|
||||
|
||||
void TestI2C(void)
|
||||
void TestI2C(void)
|
||||
{
|
||||
|
||||
// config IIC pin(SCL:34.SDA:35) in menuconfig
|
||||
int iic_fd = PrivOpen(I2C_DEV_DRIVER, O_RDWR);
|
||||
if (iic_fd < 0)
|
||||
{
|
||||
printf("open iic_fd fd error:%d\n", iic_fd);
|
||||
return;
|
||||
}
|
||||
printf("IIC open successful!\n");
|
||||
|
||||
// init iic
|
||||
uint16 iic_address = I2C_SLAVE_ADDRESS;
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = I2C_TYPE;
|
||||
ioctl_cfg.args = (void *)&iic_address;
|
||||
|
||||
if (0 != PrivIoctl(iic_fd, OPE_INT, &ioctl_cfg))
|
||||
{
|
||||
printf("ioctl iic fd error %d\n", iic_fd);
|
||||
PrivClose(iic_fd);
|
||||
return;
|
||||
}
|
||||
printf("IIC configure successful!\n");
|
||||
|
||||
// I2C read and write
|
||||
char tmp_buff[100];
|
||||
while (1)
|
||||
{
|
||||
PrivTaskDelay(1000);
|
||||
PrivWrite(iic_fd, "Hello World!\n", sizeof("Hello World!\n"));
|
||||
printf("msg send:%s\n", "Hello World!\n");
|
||||
PrivTaskDelay(1000);
|
||||
memset(tmp_buff, 0, sizeof(tmp_buff));
|
||||
PrivRead(iic_fd, tmp_buff, sizeof(tmp_buff));
|
||||
printf("msg recv:%s\n", tmp_buff);
|
||||
}
|
||||
|
||||
PrivClose(iic_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestI2C, a iic test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
#define GRAPHIC_CTRL_RECT_UPDATE 0x00
|
||||
#define LCD_STRING_TYPE 0
|
||||
#define LCD_DOT_TYPE 1
|
||||
#define LCD_FONT_RECT_WIDTH 150
|
||||
#define LCD_FONT_RECT_HEIGHT 50
|
||||
#define NULL_PARAMETER 0
|
||||
|
||||
void TestLcd(void)
|
||||
{
|
||||
int lcd_fd = PrivOpen(EDU_LCD_DEV_DRIVER, O_RDWR);
|
||||
if (lcd_fd < 0)
|
||||
{
|
||||
printf("open lcd fd error:%d\n", lcd_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
// draw text
|
||||
LcdWriteParam graph_param;
|
||||
graph_param.type = LCD_STRING_TYPE;
|
||||
graph_param.string_info.x_pos = 0;
|
||||
graph_param.string_info.y_pos = 0;
|
||||
graph_param.string_info.width = 250;
|
||||
graph_param.string_info.height = 24;
|
||||
graph_param.string_info.font_size = 24;
|
||||
graph_param.string_info.back_color = 0xFFFF;
|
||||
graph_param.string_info.font_color = 0x0000;
|
||||
graph_param.string_info.addr = "hello_world!";
|
||||
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
|
||||
uint16 color_select = 0xF800;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
graph_param.type = LCD_DOT_TYPE;
|
||||
graph_param.pixel_info.x_startpos = 0;
|
||||
graph_param.pixel_info.y_startpos = 50 * i;
|
||||
graph_param.pixel_info.x_endpos = 320;
|
||||
graph_param.pixel_info.y_endpos = 50 * i;
|
||||
graph_param.pixel_info.pixel_color = &color_select;
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
}
|
||||
|
||||
PrivClose(lcd_fd);
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestLcd, a lcd test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
@@ -81,7 +81,6 @@ void Test485(void)
|
||||
PrivClose(pin_fd);
|
||||
PrivClose(uart_fd);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(Test485, a RS485 test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
@@ -0,0 +1,45 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
void TestWDT(int argc, char *agrv[])
|
||||
{
|
||||
int wdt_fd = PrivOpen(WDT0_DEV_DRIVER, O_RDWR);
|
||||
if (wdt_fd < 0)
|
||||
{
|
||||
printf("open wdt_fd fd error:%d\n", wdt_fd);
|
||||
return;
|
||||
}
|
||||
printf("hw watchdog open!\n");
|
||||
|
||||
// init watchdog
|
||||
int wdt_time = 1000;
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = WDT_TYPE;
|
||||
ioctl_cfg.args = (void *)&wdt_time;
|
||||
|
||||
if (0 != PrivIoctl(wdt_fd, OPER_WDT_SET_TIMEOUT, &ioctl_cfg))
|
||||
{
|
||||
printf("ioctl wdt fd error %d\n", wdt_fd);
|
||||
PrivClose(wdt_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
int test_counter = 100;
|
||||
|
||||
// wdt feed or not according to argc,if argc!=1 then dog won't be feed
|
||||
while (test_counter--)
|
||||
{
|
||||
if (1 == argc)
|
||||
{
|
||||
printf("dog is feed\n");
|
||||
PrivIoctl(wdt_fd, OPER_WDT_KEEPALIVE, &ioctl_cfg); // feed dog
|
||||
}
|
||||
PrivTaskDelay(100);
|
||||
}
|
||||
PrivClose(wdt_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestWDT, a wdt test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
Reference in New Issue
Block a user