forked from xuos/xiuos
First commit XiUOS
This commit is contained in:
62
kernel/kernel_test/Kconfig
Normal file
62
kernel/kernel_test/Kconfig
Normal file
@@ -0,0 +1,62 @@
|
||||
menuconfig KERNEL_TEST
|
||||
bool "Enable kernel test function "
|
||||
default n
|
||||
|
||||
if KERNEL_TEST
|
||||
config KERNEL_TEST_AVLTREE
|
||||
bool "Config test avl tree"
|
||||
default n
|
||||
select KERNEL_AVL_TREE
|
||||
config KERNEL_TEST_CRICULAR_AREA
|
||||
bool "Config test Circular area"
|
||||
default n
|
||||
select KERNEL_CIRCULAR_AREA
|
||||
config KERNEL_TEST_MEM
|
||||
bool "Config test mem"
|
||||
default n
|
||||
select KERNEL_MEMBLOCK
|
||||
config KERNEL_TEST_TIMER
|
||||
bool "Config test timer"
|
||||
default n
|
||||
config KERNEL_TEST_IWG
|
||||
bool "Config test iwg"
|
||||
default n
|
||||
select BSP_USING_WDT
|
||||
config KERNEL_TEST_REALTIME
|
||||
bool "Config test realtime"
|
||||
default n
|
||||
config KERNEL_TEST_DBG
|
||||
bool "Config test dbg"
|
||||
default n
|
||||
select KERNEL_DEBUG
|
||||
config KERNEL_TEST_SCHED
|
||||
bool "Config test sched"
|
||||
default n
|
||||
config KERNEL_TEST_RTC
|
||||
bool "Config test rtc"
|
||||
default n
|
||||
config KERNEL_TEST_SERIAL
|
||||
bool "Config test serial"
|
||||
default n
|
||||
config KERNEL_TEST_HWTIMER
|
||||
bool "Config test hwtimer"
|
||||
default n
|
||||
config KERNEL_TEST_CAN
|
||||
bool "Config test can"
|
||||
default n
|
||||
config KERNEL_TEST_TOUCH
|
||||
bool "Config test touch"
|
||||
default n
|
||||
config KERNEL_TEST_LCD
|
||||
bool "Config test lcd"
|
||||
default n
|
||||
config KERNEL_TEST_CH438
|
||||
bool "Config test ch438"
|
||||
default n
|
||||
config KERNEL_TEST_I2C
|
||||
bool "Config test i2c"
|
||||
default n
|
||||
config KERNEL_TEST_RISC_CAN
|
||||
bool "Config test riscv can "
|
||||
default n
|
||||
endif
|
||||
88
kernel/kernel_test/Makefile
Normal file
88
kernel/kernel_test/Makefile
Normal file
@@ -0,0 +1,88 @@
|
||||
SRC_FILES := test_main.c
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_SEM),y)
|
||||
SRC_FILES += test_sem.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_MUTEX),y)
|
||||
SRC_FILES += test_mutex.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_EVENT),y)
|
||||
SRC_FILES += test_event.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_MSG),y)
|
||||
SRC_FILES += test_mq.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_AVLTREE),y)
|
||||
SRC_FILES += test_avltree.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_CRICULAR_AREA),y)
|
||||
SRC_FILES += test_circulararea.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_TOUCH),y)
|
||||
SRC_FILES += test_touch.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_MEM),y)
|
||||
SRC_FILES += test_mem.c
|
||||
SRC_FILES += test_gatherblock.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_TIMER),y)
|
||||
SRC_FILES += test_timer.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_IWG),y)
|
||||
SRC_FILES += test_iwg.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_CAN),y)
|
||||
SRC_FILES += test_can.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_REALTIME),y)
|
||||
SRC_FILES += test_realtime.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_DBG),y)
|
||||
SRC_FILES += test_dbg.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_SCHED),y)
|
||||
SRC_FILES += test_threadsched.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_RTC),y)
|
||||
SRC_FILES += test_rtc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_SERIAL),y)
|
||||
SRC_FILES += test_serial.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_HWTIMER),y)
|
||||
SRC_FILES += test_hwtimer.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_LCD),y)
|
||||
SRC_FILES += test_lcd.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_CH438),y)
|
||||
SRC_FILES += test_ch438.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_I2C),y)
|
||||
SRC_FILES += test_i2c.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_TEST_RISC_CAN),y)
|
||||
SRC_FILES += riscv_test_can.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
127
kernel/kernel_test/riscv_test_can.c
Normal file
127
kernel/kernel_test/riscv_test_can.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file riscv_test_can.c
|
||||
* @brief support to test can function on aiit-riscv64-board
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
|
||||
#ifdef BOARD_AIIT_RISCV_EVB
|
||||
|
||||
#include <device.h>
|
||||
#include <gpiohs.h>
|
||||
#include "board.h"
|
||||
#include "connect_ch438.h"
|
||||
|
||||
static struct Bus *bus;
|
||||
static struct HardwareDev *dev;
|
||||
static struct Driver *drv;
|
||||
|
||||
static int32 Timer = NONE;
|
||||
|
||||
static uint8 idx = 0;
|
||||
|
||||
static void Ch438Read(void *parameter)
|
||||
{
|
||||
uint8 rev_len;
|
||||
uint8 ext_uart_no = 3;
|
||||
static uint8 dat,i,count;
|
||||
|
||||
struct BusBlockReadParam read_param;
|
||||
static uint8 Ch438Buff[8][BUFFSIZE];
|
||||
|
||||
while (1)
|
||||
{
|
||||
read_param.buffer = Ch438Buff[3];
|
||||
rev_len = BusDevReadData(dev, &read_param);
|
||||
|
||||
for(count = 0 ;count < rev_len ;count++)
|
||||
{
|
||||
KPrintf("%#2x ",Ch438Buff[3][count]);
|
||||
KPrintf("\n");
|
||||
}
|
||||
|
||||
for(i=0;i<BUFFSIZE;i++)
|
||||
{
|
||||
Ch438Buff[3][i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestCh438Init(void)
|
||||
{
|
||||
x_err_t flag;
|
||||
|
||||
struct BusConfigureInfo configure_info;
|
||||
|
||||
int32 task_CH438 = KTaskCreate("task_CH438", Ch438Read, NONE, 2048, 10);
|
||||
flag = StartupKTask(task_CH438);
|
||||
if (flag != EOK) {
|
||||
KPrintf("StartupKTask failed .\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
bus = BusFind(CH438_BUS_NAME);
|
||||
drv = BusFindDriver(bus, CH438_DRIVER_NAME);
|
||||
dev = BusFindDevice(bus, CH438_DEVICE_NAME_3);
|
||||
|
||||
struct SerialCfgParam serial_cfg;
|
||||
memset(&serial_cfg, 0, sizeof(struct SerialCfgParam));
|
||||
configure_info.configure_cmd = OPE_INT;
|
||||
configure_info.private_data = (void *)&serial_cfg;
|
||||
|
||||
serial_cfg.data_cfg.port_configure = PORT_CFG_INIT;
|
||||
|
||||
serial_cfg.data_cfg.ext_uart_no = 3;
|
||||
serial_cfg.data_cfg.serial_baud_rate = 115200;
|
||||
BusDrvConfigure(drv, &configure_info);
|
||||
}
|
||||
|
||||
void CanTestSend(void)
|
||||
{
|
||||
uint8 MeterInstruction[8]={0x01, 0x04, 0x77, 0x66, 0x20, 0x03, 0xB0, 0x0B};
|
||||
|
||||
struct BusBlockWriteParam write_param;
|
||||
|
||||
write_param.buffer = MeterInstruction;
|
||||
write_param.size = 8;
|
||||
|
||||
TestCh438Init();
|
||||
MdelayKTask(500);
|
||||
while(1)
|
||||
{
|
||||
BusDevWriteData(dev, &write_param);
|
||||
KPrintf("test_can_send!\n");
|
||||
MdelayKTask(500);
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
CanTestSend, CanTestSend, CanTestSend );
|
||||
|
||||
void CanTestRecv(void)
|
||||
{
|
||||
TestCh438Init();
|
||||
MdelayKTask(500);
|
||||
while(1)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
CanTestRecv, CanTestRecv, CanTestRecv );
|
||||
#endif
|
||||
200
kernel/kernel_test/test_avltree.c
Normal file
200
kernel/kernel_test/test_avltree.c
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestAvltree.c
|
||||
* @brief support to test avltree function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <xs_avltree.h>
|
||||
|
||||
static char string[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
static AvlNodeType g_avlnode;
|
||||
|
||||
static AvlNodeType create_tree(AvlNodeType avl_node)
|
||||
{
|
||||
uint32 i = 0;
|
||||
uint32 string_len = strlen(string);
|
||||
|
||||
for(i = 0; i < string_len; i ++)
|
||||
{
|
||||
KPrintf("avl_node %8p data %d\n", avl_node, string[i]);
|
||||
avl_node = AvlTreeInsertNode(avl_node, string[i]);
|
||||
}
|
||||
|
||||
return avl_node;
|
||||
}
|
||||
|
||||
static AvlNodeType DeleteNode(AvlNodeType avl_node, int32 data)
|
||||
{
|
||||
avl_node = AvlTreeDeleteNode(avl_node, data);
|
||||
|
||||
return avl_node;
|
||||
}
|
||||
|
||||
static AvlNodeType DeleteTree(AvlNodeType avl_node)
|
||||
{
|
||||
uint32 i = 0;
|
||||
uint32 string_len = strlen(string);
|
||||
|
||||
for(i = 0; i < string_len; i ++)
|
||||
{
|
||||
avl_node = AvlTreeDeleteNode(avl_node, string[i]);
|
||||
}
|
||||
|
||||
return avl_node;
|
||||
}
|
||||
|
||||
static AvlNodeType InsertNode(AvlNodeType avl_node, int32 data)
|
||||
{
|
||||
avl_node = AvlTreeInsertNode(avl_node, data);
|
||||
|
||||
return avl_node;
|
||||
}
|
||||
|
||||
static AvlNodeType SearchNode(AvlNodeType avl_node, int32 data)
|
||||
{
|
||||
AvlNodeType dst_node;
|
||||
dst_node = AvlNodeSearchNode(avl_node, data);
|
||||
|
||||
return dst_node;
|
||||
}
|
||||
|
||||
static AvlNodeType ModyfiNode(AvlNodeType avl_node, int32 src_data, int32 dst_data)
|
||||
{
|
||||
AvlNodeType dst_node;
|
||||
dst_node = AvlNodeModifyNode(avl_node, src_data, dst_data);
|
||||
|
||||
return dst_node;
|
||||
}
|
||||
|
||||
static void PrintfRootnode(void)
|
||||
{
|
||||
KPrintf("g_avlnode %8p data %d left %8p data %d right %8p data %d\n",
|
||||
g_avlnode, g_avlnode->data, g_avlnode->left, g_avlnode->left->data, g_avlnode->right, g_avlnode->right->data);
|
||||
|
||||
KPrintf("g_avlnode left %8p data %d left %8p data %d right %8p data %d\n",
|
||||
g_avlnode->left, g_avlnode->left->data, g_avlnode->left->left, g_avlnode->left->left->data, g_avlnode->left->right, g_avlnode->left->right->data);
|
||||
|
||||
KPrintf("g_avlnode right %8p data %d left %8p data %d right %8p data %d\n",
|
||||
g_avlnode->right, g_avlnode->right->data, g_avlnode->right->left, g_avlnode->right->left->data, g_avlnode->right->right, g_avlnode->right->right->data);
|
||||
}
|
||||
|
||||
static void InorderPrintftree(AvlNodeType avl_node)
|
||||
{
|
||||
if(avl_node)
|
||||
{
|
||||
if(avl_node->left)
|
||||
{
|
||||
InorderPrintftree(avl_node->left);
|
||||
}
|
||||
|
||||
KPrintf("%d ", avl_node->data);
|
||||
|
||||
if(avl_node->right)
|
||||
{
|
||||
InorderPrintftree(avl_node->right);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("nil \n");
|
||||
}
|
||||
}
|
||||
|
||||
static uint32 TestAvltree(int argc, char *argv[])
|
||||
{
|
||||
if(0 == argc)
|
||||
{
|
||||
KPrintf("TestAvltree needs parameters. Just return\n");
|
||||
return EOK;
|
||||
}
|
||||
|
||||
if(0 == strcmp("-c", argv[1]))
|
||||
{
|
||||
g_avlnode = create_tree(g_avlnode);
|
||||
if(NONE == g_avlnode)
|
||||
{
|
||||
KPrintf("TestAvltree g_avlnode create failed!\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
PrintfRootnode();
|
||||
InorderPrintftree(g_avlnode);
|
||||
}
|
||||
else if(0 == strcmp("-d", argv[1]))
|
||||
{
|
||||
if(3 == argc)
|
||||
{
|
||||
int32 data = atoi(argv[2]);
|
||||
|
||||
g_avlnode = DeleteNode(g_avlnode, data);
|
||||
|
||||
PrintfRootnode();
|
||||
InorderPrintftree(g_avlnode);
|
||||
}
|
||||
else if(2 == argc)
|
||||
{
|
||||
g_avlnode = DeleteTree(g_avlnode);
|
||||
|
||||
PrintfRootnode();
|
||||
InorderPrintftree(g_avlnode);
|
||||
}
|
||||
}
|
||||
else if(0 == strcmp("-i", argv[1]))
|
||||
{
|
||||
if(3 == argc)
|
||||
{
|
||||
int32 data = atoi(argv[2]);
|
||||
|
||||
g_avlnode = InsertNode(g_avlnode, data);
|
||||
|
||||
PrintfRootnode();
|
||||
InorderPrintftree(g_avlnode);
|
||||
}
|
||||
}
|
||||
else if(0 == strcmp("-s", argv[1]))
|
||||
{
|
||||
if(3 == argc)
|
||||
{
|
||||
int32 data = atoi(argv[2]);
|
||||
|
||||
AvlNodeType dst_node = SearchNode(g_avlnode, data);
|
||||
|
||||
KPrintf("find data %dx%d node %8p\n", dst_node->data, data, dst_node);
|
||||
PrintfRootnode();
|
||||
}
|
||||
}
|
||||
else if(0 == strcmp("-m", argv[1]))
|
||||
{
|
||||
if(4 == argc)
|
||||
{
|
||||
int32 src_data = atoi(argv[2]);
|
||||
int32 dst_data = atoi(argv[3]);
|
||||
|
||||
g_avlnode = ModyfiNode(g_avlnode, src_data, dst_data);
|
||||
|
||||
PrintfRootnode();
|
||||
InorderPrintftree(g_avlnode);
|
||||
}
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4),
|
||||
TestAvltree, TestAvltree, Test the AVL tree Function);
|
||||
169
kernel/kernel_test/test_can.c
Normal file
169
kernel/kernel_test/test_can.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_can.c
|
||||
* @brief support to test can function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include "bus_can.h"
|
||||
#include "dev_can.h"
|
||||
|
||||
|
||||
uint8 buf[8] = {0x33,0x55,0x77,0x99,0x66,0x44,0x88,0x11};
|
||||
uint8 rx_buf[8];
|
||||
struct BusBlockWriteParam cfx = {
|
||||
.pos = 0,
|
||||
.buffer = buf,
|
||||
.size = 8
|
||||
};
|
||||
|
||||
|
||||
uint8 rx_buf[8] = {0};
|
||||
struct BusBlockReadParam read_param = {
|
||||
.pos = 0,
|
||||
.buffer =rx_buf ,
|
||||
.read_length =0
|
||||
};
|
||||
|
||||
|
||||
static struct CanDriverConfigure can_defconfig = {
|
||||
.tsjw = 0,
|
||||
.tbs2 = 5 ,
|
||||
.tbs1 = 6,
|
||||
.brp = 6,
|
||||
.mode = 0
|
||||
};
|
||||
|
||||
struct BusConfigureInfo configure_info ={
|
||||
.configure_cmd = 0,
|
||||
.private_data = &can_defconfig
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int _CanTestSend(const char *bus_name, const char *driver_name, const char *device_name0)
|
||||
{
|
||||
int i;
|
||||
struct Bus *bus;
|
||||
struct Driver *driver, *bus_driver;
|
||||
struct HardwareDev *device0, *device1;
|
||||
struct HardwareDev *bus_device0;
|
||||
|
||||
if(bus_name)
|
||||
{
|
||||
bus = BusFind(bus_name);
|
||||
KPrintf("##test bus %p##\n", bus);
|
||||
}
|
||||
|
||||
if(driver_name)
|
||||
{
|
||||
driver = CanDriverFind(driver_name, TYPE_CAN_DRV);
|
||||
bus_driver = BusFindDriver(bus, driver_name);
|
||||
KPrintf("##test driver %p bus_driver %p##\n", driver, bus_driver);
|
||||
}
|
||||
|
||||
if(device_name0)
|
||||
{
|
||||
device0 = CanDeviceFind(device_name0, TYPE_CAN_DEV);
|
||||
bus_device0 = BusFindDevice(bus, device_name0);
|
||||
KPrintf("####test device0 %p bus_device0 %p####\n", device0, bus_device0);
|
||||
KPrintf("####test device0 private %p\n", device0->private_data);
|
||||
}
|
||||
|
||||
BusDrvConfigure(bus_driver, &configure_info);
|
||||
|
||||
while(1)
|
||||
{
|
||||
BusDevWriteData(device0, &cfx);
|
||||
uint8 * buf =(uint8 *) cfx.buffer;
|
||||
KPrintf("send:");
|
||||
for(i = 0;i<cfx.size;i++)
|
||||
KPrintf("0x%2x ", buf[i]);
|
||||
KPrintf("\n");
|
||||
MdelayKTask(2000);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void CanTestSend(void)
|
||||
{
|
||||
_CanTestSend(CAN_BUS_NAME_1,CAN_DRIVER_NAME,CAN_1_DEVICE_NAME_1);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),CanTestSend, CanTestSend, Close AC task );
|
||||
|
||||
|
||||
|
||||
|
||||
static int _CanTestRecv(const char *bus_name, const char *driver_name, const char *device_name0)
|
||||
{
|
||||
int len ,i;
|
||||
struct Bus *bus;
|
||||
struct Driver *driver, *bus_driver;
|
||||
struct HardwareDev *device0, *device1;
|
||||
struct HardwareDev *bus_device0;
|
||||
|
||||
if(bus_name)
|
||||
{
|
||||
KPrintf("####test find bus %s\n", bus_name);
|
||||
bus = BusFind(bus_name);
|
||||
KPrintf("####test bus %p####\n", bus);
|
||||
}
|
||||
|
||||
if(driver_name)
|
||||
{
|
||||
KPrintf("####test find driver %s\n", driver_name);
|
||||
driver = CanDriverFind(driver_name, TYPE_CAN_DRV);
|
||||
bus_driver = BusFindDriver(bus, driver_name);
|
||||
KPrintf("####test driver %p bus_driver %p####\n", driver, bus_driver);
|
||||
}
|
||||
|
||||
if(device_name0)
|
||||
{
|
||||
KPrintf("####test find device0 %s\n", device_name0);
|
||||
device0 = CanDeviceFind(device_name0, TYPE_CAN_DEV);
|
||||
bus_device0 = BusFindDevice(bus, device_name0);
|
||||
KPrintf("####test device0 %p bus_device0 %p####\n", device0, bus_device0);
|
||||
KPrintf("####test device0 private %p\n", device0->private_data);
|
||||
}
|
||||
|
||||
BusDrvConfigure(bus_driver, &configure_info);
|
||||
|
||||
while(1)
|
||||
{
|
||||
len = BusDevReadData(bus_device0,&read_param);
|
||||
if(0 != len)
|
||||
{
|
||||
for(i = 0; i<len;i++)
|
||||
KPrintf("0x%02x ", rx_buf[i]);
|
||||
KPrintf("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
MdelayKTask(100);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void CanTestRecv(void)
|
||||
{
|
||||
_CanTestRecv(CAN_BUS_NAME_1,CAN_DRIVER_NAME,CAN_1_DEVICE_NAME_1);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),CanTestRecv, CanTestRecv, Close AC task );
|
||||
|
||||
131
kernel/kernel_test/test_ch438.c
Normal file
131
kernel/kernel_test/test_ch438.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestCh438.c
|
||||
* @brief support to test ch438 function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <device.h>
|
||||
#include "board.h"
|
||||
#include "connect_ch438.h"
|
||||
|
||||
#if defined BOARD_AIIT_RISCV_EVB
|
||||
#define EXT_UART_NO 2
|
||||
#elif defined BOARD_STM32F407_EVB
|
||||
#define EXT_UART_NO 4
|
||||
#endif
|
||||
|
||||
#define DATA_BUFF_SIZE 255
|
||||
|
||||
static struct Bus *bus;
|
||||
static struct HardwareDev *dev;
|
||||
static struct Driver *drv;
|
||||
|
||||
|
||||
static void Ch438Read(void *parameter)
|
||||
{
|
||||
uint8 RevLen;
|
||||
uint8 ext_uart_no = EXT_UART_NO;
|
||||
uint8 i;
|
||||
uint16 vol, cur, pwr;
|
||||
|
||||
struct BusBlockReadParam read_param;
|
||||
static uint8 Ch438Buff[8][DATA_BUFF_SIZE];
|
||||
|
||||
while (1)
|
||||
{
|
||||
MdelayKTask(100);
|
||||
|
||||
read_param.buffer = Ch438Buff[ext_uart_no];
|
||||
RevLen = BusDevReadData(dev, &read_param);
|
||||
|
||||
vol = ((uint16)Ch438Buff[ext_uart_no][3] << 8) | Ch438Buff[ext_uart_no][4];
|
||||
cur = ((uint16)Ch438Buff[ext_uart_no][5] << 8) | Ch438Buff[ext_uart_no][6];
|
||||
pwr = ((uint16)Ch438Buff[ext_uart_no][7] << 8) | Ch438Buff[ext_uart_no][8];
|
||||
KPrintf("Board voltage : %d.%d V current : %d mA power : %d.%03d W\n", vol/10, vol%10, cur, pwr/1000, pwr%1000);
|
||||
|
||||
for(i = 0 ; i < DATA_BUFF_SIZE; i ++) {
|
||||
Ch438Buff[ext_uart_no][i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Ch438Write(void *parameter)
|
||||
{
|
||||
x_err_t result;
|
||||
uint8 MeterInstruction[8] = {0x01, 0x04, 0x00, 0x00, 0x00, 0x03, 0xB0, 0x0B};
|
||||
struct BusBlockWriteParam write_param;
|
||||
|
||||
write_param.buffer = MeterInstruction;
|
||||
write_param.size = 8;
|
||||
|
||||
while (1)
|
||||
{
|
||||
MdelayKTask(1000);
|
||||
KPrintf("\n");
|
||||
BusDevWriteData(dev, &write_param);
|
||||
}
|
||||
}
|
||||
|
||||
static void TestCh438Init(void)
|
||||
{
|
||||
x_err_t flag;
|
||||
|
||||
struct BusConfigureInfo configure_info;
|
||||
|
||||
bus = BusFind(CH438_BUS_NAME);
|
||||
drv = BusFindDriver(bus, CH438_DRIVER_NAME);
|
||||
|
||||
#if defined BOARD_AIIT_RISCV_EVB
|
||||
dev = BusFindDevice(bus, CH438_DEVICE_NAME_2);
|
||||
#elif defined BOARD_STM32F407_EVB
|
||||
dev = BusFindDevice(bus, CH438_DEVICE_NAME_4);
|
||||
#endif
|
||||
|
||||
struct SerialCfgParam serial_cfg;
|
||||
memset(&serial_cfg, 0, sizeof(struct SerialCfgParam));
|
||||
configure_info.configure_cmd = OPE_INT;
|
||||
configure_info.private_data = (void *)&serial_cfg;
|
||||
|
||||
serial_cfg.data_cfg.port_configure = PORT_CFG_INIT;
|
||||
|
||||
serial_cfg.data_cfg.ext_uart_no = EXT_UART_NO;
|
||||
serial_cfg.data_cfg.serial_baud_rate = 9600;
|
||||
BusDrvConfigure(drv, &configure_info);
|
||||
|
||||
int32 task_CH438_read = KTaskCreate("task_CH438_read", Ch438Read, NONE, 2048, 10);
|
||||
flag = StartupKTask(task_CH438_read);
|
||||
if (flag != EOK) {
|
||||
KPrintf("StartupKTask task_CH438_read failed .\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
int32 task_CH438_write = KTaskCreate("task_CH438_write", Ch438Write, NONE, 2048, 10);
|
||||
flag = StartupKTask(task_CH438_write);
|
||||
if (flag != EOK) {
|
||||
KPrintf("StartupKTask task_CH438_write failed .\n");
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
void TestCh438(void)
|
||||
{
|
||||
TestCh438Init();
|
||||
MdelayKTask(500);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
TestCh438, TestCh438, TestCh438 );
|
||||
160
kernel/kernel_test/test_circulararea.c
Normal file
160
kernel/kernel_test/test_circulararea.c
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestCirculararea.c
|
||||
* @brief support to test circular area function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#ifdef KERNEL_CIRCULAR_AREA
|
||||
|
||||
#define READ_LENGTH 2
|
||||
#define Write_LENGTH 3
|
||||
#define CIRCULARAREA_LENGTH 8
|
||||
|
||||
static struct CircularArea *g_circular_area;
|
||||
static int8 test_string[] = "Aiit-XiuOs";
|
||||
|
||||
static int32 task_caread;
|
||||
static int32 task_cawrite;
|
||||
|
||||
int data_lock = -1;
|
||||
|
||||
static void CircularArea_ReadTsk_Entry(void *parameter)
|
||||
{
|
||||
uint8 i;
|
||||
uint8 read_string[8] = {0};
|
||||
uint8 read_cnt = 0;
|
||||
|
||||
while(read_cnt < 30)
|
||||
{
|
||||
KMutexObtain(data_lock, WAITING_FOREVER);
|
||||
|
||||
if(EOK == g_circular_area->CircularAreaOperations->read(g_circular_area, read_string, READ_LENGTH)){
|
||||
for(i = 0; i < READ_LENGTH; i ++){
|
||||
KPrintf("Read data i %u ch %c rdidx %u wridx %u\n", i, read_string[i], g_circular_area->readidx, g_circular_area->writeidx);
|
||||
}
|
||||
|
||||
#ifdef Test_Dbg
|
||||
KPrintf("Read TSK writeidx %u readidx %u status %u len %u\n",
|
||||
g_circular_area->writeidx,
|
||||
g_circular_area->readidx,
|
||||
g_circular_area->b_status,
|
||||
CircularAreaGetDataLength(g_circular_area));
|
||||
#endif
|
||||
}
|
||||
|
||||
read_cnt++;
|
||||
MdelayKTask(500);
|
||||
|
||||
KMutexAbandon(data_lock);
|
||||
}
|
||||
|
||||
KMutexDelete(data_lock);
|
||||
KTaskDelete(task_caread);
|
||||
g_circular_area->CircularAreaOperations->release(g_circular_area);
|
||||
}
|
||||
|
||||
static void CircularAreaWriteTskEntry(void *parameter)
|
||||
{
|
||||
uint8 i;
|
||||
uint8 write_cnt = 0;
|
||||
uint8 string_length = strlen(test_string);
|
||||
static uint32 single_write_length = 0;
|
||||
|
||||
while(write_cnt < 30)
|
||||
{
|
||||
KMutexObtain(data_lock, WAITING_FOREVER);
|
||||
|
||||
uint8 write_string[CIRCULARAREA_LENGTH] = {0};
|
||||
if((write_cnt % string_length + Write_LENGTH) > string_length){
|
||||
memcpy(write_string, &test_string[write_cnt % string_length], string_length - write_cnt % string_length);
|
||||
memcpy(&write_string[string_length - write_cnt % string_length], test_string, Write_LENGTH - string_length + write_cnt % string_length);
|
||||
}
|
||||
else{
|
||||
memcpy(write_string, &test_string[write_cnt % string_length], Write_LENGTH);
|
||||
}
|
||||
|
||||
if(EOK == g_circular_area->CircularAreaOperations->write(g_circular_area, write_string, Write_LENGTH, 0))
|
||||
{
|
||||
for(i = 0; i < Write_LENGTH; i ++) {
|
||||
KPrintf("Write data i %d ch %c rdidx %u wridx %u\n", i, write_string[i], g_circular_area->readidx, g_circular_area->writeidx);
|
||||
}
|
||||
write_cnt += (g_circular_area->writeidx - single_write_length + CIRCULARAREA_LENGTH) % CIRCULARAREA_LENGTH;
|
||||
single_write_length = g_circular_area->writeidx;
|
||||
}
|
||||
|
||||
#ifdef Test_Dbg
|
||||
KPrintf("Write TSK writeidx %u readidx %u status %u len %u\n",
|
||||
g_circular_area->writeidx,
|
||||
g_circular_area->readidx,
|
||||
g_circular_area->b_status,
|
||||
CircularAreaGetDataLength(g_circular_area));
|
||||
#endif
|
||||
MdelayKTask(500);
|
||||
|
||||
KMutexAbandon(data_lock);
|
||||
}
|
||||
|
||||
KTaskDelete(task_cawrite);
|
||||
}
|
||||
|
||||
static uint32 TestCirculararea(void)
|
||||
{
|
||||
x_err_t flag;
|
||||
|
||||
g_circular_area = CircularAreaInit(CIRCULARAREA_LENGTH);
|
||||
if(g_circular_area){
|
||||
KPrintf("CircularAreaInit done buffer 0x%8p length %u phead 0x%8p ptail 0x%8p wridx %u rdidx %u\n",
|
||||
g_circular_area->data_buffer, g_circular_area->area_length,
|
||||
g_circular_area->p_head, g_circular_area->p_tail,
|
||||
g_circular_area->writeidx, g_circular_area->readidx);
|
||||
}
|
||||
else{
|
||||
KPrintf("CircularAreaInit failed!Just return\n");
|
||||
CircularAreaRelease(g_circular_area);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
data_lock = KMutexCreate();
|
||||
if (data_lock < 0){
|
||||
KPrintf("data_lock creat failed.\n");
|
||||
g_circular_area->CircularAreaOperations->release(g_circular_area);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
task_caread = KTaskCreate("task_caread", CircularArea_ReadTsk_Entry, NONE, 2048, 10);
|
||||
flag = StartupKTask(task_caread);
|
||||
if (EOK != flag){
|
||||
KPrintf("CircularArea_Test StartupKTask task_caread failed!\n");
|
||||
g_circular_area->CircularAreaOperations->release(g_circular_area);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
task_cawrite = KTaskCreate("task_cawrite", CircularAreaWriteTskEntry, NONE, 2048, 10);
|
||||
flag = StartupKTask(task_cawrite);
|
||||
if (EOK != flag){
|
||||
KPrintf("CircularArea_Test StartupKTask task_cawrite failed!\n");
|
||||
g_circular_area->CircularAreaOperations->release(g_circular_area);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
||||
TestCirculararea, TestCirculararea, Test the Circular Area Function);
|
||||
#endif
|
||||
40
kernel/kernel_test/test_dbg.c
Normal file
40
kernel/kernel_test/test_dbg.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestDbg.c
|
||||
* @brief support to test dbg function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
|
||||
#define KDBG_TEST1 1
|
||||
#define KDBG_TEST2 0
|
||||
|
||||
static uint32 TestDbg(void)
|
||||
{
|
||||
x_err_t flag;
|
||||
|
||||
SYS_WARN("TestDbg function 1!\n");
|
||||
SYS_ERR("TestDbg function 2!\n");
|
||||
DBG("TestDbg function 3!\n");
|
||||
|
||||
SYS_KDEBUG_LOG(KDBG_TEST1, ("TestDbg kernel function 1!\n"));
|
||||
SYS_KDEBUG_LOG(KDBG_TEST2, ("TestDbg kernel function 2!\n"));
|
||||
|
||||
return EOK;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
||||
TestDbg, TestDbg, Test the log debug Function);
|
||||
570
kernel/kernel_test/test_gatherblock.c
Normal file
570
kernel/kernel_test/test_gatherblock.c
Normal file
@@ -0,0 +1,570 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_gatherblock.c
|
||||
* @brief support to test gather block function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <string.h>
|
||||
|
||||
extern long ShowMemPool(void);
|
||||
extern void ShowMemory(void);
|
||||
extern void ListBuddy(void);
|
||||
/**************************single gatherblock test sample***********************************/
|
||||
static uint8 *ptr[30];
|
||||
static uint8 mempool[2048];
|
||||
static struct MemGather gm;
|
||||
static GatherMemType gm_d;
|
||||
|
||||
#define TASK_PRIORITY 25
|
||||
#define TASK_STACK_SIZE 2048
|
||||
#define TASK_TIMESLICE 5
|
||||
|
||||
/* thread control pointer */
|
||||
static int32 tid1;
|
||||
static int32 tid2;
|
||||
|
||||
/* task1 entry */
|
||||
static void Task1GmAlloc(void *parameter)
|
||||
{
|
||||
int i;
|
||||
for (i = 0 ; i < 30 ; i++){
|
||||
if (ptr[i] == NONE){
|
||||
/* alloc memory blocks for 50 times, if failed, suspend task1 and start task2 */
|
||||
if (0 == strncmp("static", parameter, strlen("static"))){
|
||||
ptr[i] = AllocBlockMemGather(&gm, WAITING_FOREVER);
|
||||
if (ptr[i] != NONE)
|
||||
KPrintf("task1: allocate No.%d from static gatherblock\n", i);
|
||||
}
|
||||
else{
|
||||
ptr[i] = AllocBlockMemGather(gm_d, WAITING_FOREVER);
|
||||
if (ptr[i] != NONE)
|
||||
KPrintf("task1: allocate No.%d from dynamic gatherblock\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* task2 entry, its priority is lower than task1 */
|
||||
static void Task2GmRelease(void *parameter)
|
||||
{
|
||||
int i;
|
||||
KPrintf("task2 try to release block\n");
|
||||
for (i = 0; i < 30 ; i++){
|
||||
DelayKTask(10);
|
||||
|
||||
/* release all memory blocks */
|
||||
if (ptr[i] != NONE){
|
||||
KPrintf("release block %d\n", i);
|
||||
FreeBlockMemGather(ptr[i]);
|
||||
ptr[i] = NONE;
|
||||
}
|
||||
}
|
||||
if (0 == strncmp("static", parameter, strlen("static"))) {
|
||||
KPrintf("**************** detach gatherblock test *****************\n");
|
||||
RemoveMemGather(&gm);
|
||||
} else {
|
||||
KPrintf("**************** delete gatherblock test *****************\n");
|
||||
DeleteMemGather(gm_d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int SingleGatherblockTest(char * parameter)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 30; i ++) ptr[i] = NONE;
|
||||
/* init memory blocks object */
|
||||
if(0 == strncmp("static", parameter, strlen("static"))){
|
||||
KPrintf("test static create gatherblock.\n");
|
||||
InitMemGather(&gm, "mp_s", &mempool[0], sizeof(mempool), 80);
|
||||
ShowMemPool();
|
||||
}
|
||||
|
||||
if(0 == strncmp("dynamic", parameter, strlen("dynamic"))){
|
||||
KPrintf("test dynamic create gatherblock.\n");
|
||||
//FreeBlockMemGather(&mp, "mp1", &mempool[0], sizeof(mempool), 80);
|
||||
gm_d = CreateMemGather("mp_d",20,80);
|
||||
if(gm_d == NONE){
|
||||
KPrintf("%s: allocate failure.\n",__func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ShowMemPool();
|
||||
}
|
||||
/* create task1, alloc memory blocks */
|
||||
tid1 = KTaskCreate("task1", Task1GmAlloc, parameter,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY);
|
||||
if (tid1 >= 0){
|
||||
KPrintf("single test: task1 startup.\n");
|
||||
StartupKTask(tid1);
|
||||
}
|
||||
|
||||
/* create task2, release memory blocks */
|
||||
tid2 = KTaskCreate("task2", Task2GmRelease, parameter,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY + 1);
|
||||
if (tid2 >= 0){
|
||||
StartupKTask(tid2);
|
||||
}
|
||||
else{
|
||||
KPrintf("create task2 for release failure.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/**************************************************************************************/
|
||||
|
||||
|
||||
/**********************mutiple gatherblock test sample**************************************/
|
||||
struct MemGather s_gm1;
|
||||
struct MemGather *d_gm1 = NONE;
|
||||
|
||||
static uint8 mempool_gm1[1024];
|
||||
|
||||
#define MAX_SIZE 11
|
||||
#define TASK_PRIORITY 25
|
||||
#define TASK_STACK_SIZE 2048
|
||||
#define TASK_TIMESLICE 5
|
||||
|
||||
/* thread control pointer */
|
||||
static int32 m_tid1 = NONE;
|
||||
static int32 m_tid2 = NONE;
|
||||
|
||||
static uint8 *multiple_s_ptr[20];
|
||||
static uint8 *multiple_d_ptr[20];
|
||||
|
||||
void Task1AllocEntry(void *parameter){
|
||||
int index = 0;
|
||||
for(int i=0;i<20;i++){
|
||||
|
||||
multiple_s_ptr[i] = AllocBlockMemGather(&s_gm1, WAITING_FOREVER);
|
||||
if(multiple_s_ptr[i] != NONE){
|
||||
KPrintf("task1: allocate No.%d from static\n", i);
|
||||
}
|
||||
multiple_d_ptr[i] = AllocBlockMemGather(d_gm1, WAITING_FOREVER);
|
||||
|
||||
if (ptr[i] != NONE)
|
||||
KPrintf("task1: allocate No.%d from dynamic\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
void Task2FreeEntry(void *parameter){
|
||||
DelayKTask(100);
|
||||
for(int i=0;i<20;i++){
|
||||
|
||||
DelayKTask(10);
|
||||
if(multiple_s_ptr[i]){
|
||||
FreeBlockMemGather(multiple_s_ptr[i]);
|
||||
KPrintf("task2: free No.%d of static\n", i);
|
||||
}
|
||||
DelayKTask(10);
|
||||
if(multiple_d_ptr[i]){
|
||||
FreeBlockMemGather(multiple_d_ptr[i]);
|
||||
|
||||
KPrintf("task2: free No.%d of dynamic\n", i);
|
||||
}
|
||||
}
|
||||
KPrintf("**************** detach gatherblock test *****************\n");
|
||||
RemoveMemGather(&s_gm1);
|
||||
KPrintf("**************** delete gatherblock test *****************\n");
|
||||
DeleteMemGather(d_gm1);
|
||||
}
|
||||
|
||||
int MultipleGatherblockTest(void)
|
||||
{
|
||||
|
||||
KPrintf("****************mutiple gatherblock test start*****************\n");
|
||||
|
||||
for(int i=0;i<20;i++){
|
||||
multiple_s_ptr[i] = NONE;
|
||||
multiple_d_ptr[i] = NONE;
|
||||
}
|
||||
|
||||
InitMemGather(&s_gm1, "m_gm_s1", &mempool_gm1[0], sizeof(mempool_gm1), 80);
|
||||
|
||||
d_gm1 = CreateMemGather("m_gm_d1", MAX_SIZE, 80);
|
||||
if (mempool_gm1 == NONE){
|
||||
KPrintf("create m_gm_d2 failed.");
|
||||
CHECK(0);
|
||||
}
|
||||
ShowMemPool();
|
||||
|
||||
/* create task1, alloc memory blocks */
|
||||
m_tid1 = KTaskCreate("task1_m", Task1AllocEntry, NONE,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY);
|
||||
if (m_tid1 >= 0){
|
||||
StartupKTask(m_tid1);
|
||||
}
|
||||
|
||||
/* create task2, release memory blocks */
|
||||
m_tid2 = KTaskCreate("task2_m", Task2FreeEntry, NONE,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY + 1);
|
||||
if (m_tid2 >= 0){
|
||||
StartupKTask(m_tid2);
|
||||
}
|
||||
else{
|
||||
KPrintf("create task2 for release failure.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/**************************************************************************************/
|
||||
|
||||
/* thread control pointer */
|
||||
static int32 l_tid1 = NONE;
|
||||
static int32 l_tid2 = NONE;
|
||||
struct MemGather *gm_l = NONE;
|
||||
void *l_ptr[50];
|
||||
|
||||
void LTask1AllocEntry(void *parameter){
|
||||
int index = 0;
|
||||
for(int i=0;i<50;i++){
|
||||
l_ptr[i] = AllocBlockMemGather(gm_l, WAITING_FOREVER);
|
||||
if(l_ptr[i] != NONE){
|
||||
KPrintf("l_task1: allocate No.%d\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LTask2FreeEntry(void *parameter){
|
||||
DelayKTask(100);
|
||||
for(int i=0;i<50;i++){
|
||||
DelayKTask(10);
|
||||
if(l_ptr[i]){
|
||||
FreeBlockMemGather(l_ptr[i]);
|
||||
KPrintf("l_task2: free No.%d\n", i);
|
||||
}
|
||||
}
|
||||
KPrintf("**************** delete gatherblock test *****************\n");
|
||||
DeleteMemGather(gm_l);
|
||||
}
|
||||
|
||||
|
||||
void GatherblockLimitTest(char *name, int count, int blocksize){
|
||||
gm_l = CreateMemGather(name, count, blocksize);
|
||||
if(gm_l == NONE){
|
||||
KPrintf("no memory.\n");
|
||||
return;
|
||||
}
|
||||
ListBuddy();
|
||||
/* create task1, alloc memory blocks */
|
||||
l_tid1 = KTaskCreate("task1_l", LTask1AllocEntry, NONE,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY);
|
||||
if (l_tid1 >= 0){
|
||||
StartupKTask(l_tid1);
|
||||
}
|
||||
|
||||
/* create task2, release memory blocks */
|
||||
l_tid2 = KTaskCreate("task2_l", LTask2FreeEntry, NONE,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY + 1);
|
||||
if (l_tid2 >= 0){
|
||||
StartupKTask(l_tid2);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ARCH_ARM
|
||||
#define CACHE_COUNT 1024
|
||||
#else
|
||||
#define CACHE_COUNT 8000
|
||||
#endif
|
||||
|
||||
struct MemGather *pools[CACHE_COUNT];
|
||||
void GatherblockLimitcountTest(char *name, int count, int blocksize, int poolcount){
|
||||
if(poolcount>CACHE_COUNT || poolcount<=0){
|
||||
KPrintf("type the poolcount between 0-%d\n",CACHE_COUNT);
|
||||
return;
|
||||
}
|
||||
int index;
|
||||
for(index=0;index < poolcount;index++){
|
||||
pools[index] = CreateMemGather(name, count, blocksize);
|
||||
if(pools[index] == NONE){
|
||||
KPrintf("gatherblock allocation failure,count[%d],size[%d]\n", count, blocksize);
|
||||
break;
|
||||
}
|
||||
KPrintf("gatherblock allocation,count[%d],size[%d]\n", count, blocksize);
|
||||
}
|
||||
ListBuddy();
|
||||
|
||||
index--;
|
||||
for(;index>=0;index--){
|
||||
DeleteMemGather(pools[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
static int32 traverse_tid = NONE;
|
||||
static struct MemGather *traverse_gm = NONE;
|
||||
|
||||
void TraverseGmEntry(void *parameter){
|
||||
int count,size;
|
||||
int limit_count, limit_size;
|
||||
|
||||
for(count =1; count <= 30; count++){
|
||||
for(size = 1; ;size++){
|
||||
traverse_gm = CreateMemGather("hello",count,size);
|
||||
if( traverse_gm == NONE ){
|
||||
KPrintf("gatherblock allocation failure,count[%d],size[%d]\n", count, size);
|
||||
|
||||
if(count == 1)
|
||||
limit_size = size;
|
||||
break;
|
||||
}else{
|
||||
DeleteMemGather(traverse_gm);
|
||||
}
|
||||
}
|
||||
if(size ==1){
|
||||
limit_count = count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
KPrintf("\n\n--------------------------- bound -----------------------------\n\n");
|
||||
KPrintf("\n\n--------------------------- over end -----------------------------\n\n");
|
||||
}
|
||||
|
||||
#define TRAVERSE_TASK_PRIORITY 5
|
||||
void TraverseGmTest(){
|
||||
|
||||
traverse_tid = KTaskCreate("traverse_task", TraverseGmEntry, NONE,
|
||||
TASK_STACK_SIZE ,
|
||||
TRAVERSE_TASK_PRIORITY);
|
||||
if(traverse_tid >= 0){
|
||||
StartupKTask(traverse_tid);
|
||||
}else{
|
||||
KPrintf("Fail.\n");
|
||||
}
|
||||
}
|
||||
/********************************************************************/
|
||||
/***************************test random read and write **************/
|
||||
static uint8 *random_ptr[50];
|
||||
static struct MemGather random_static_gm;
|
||||
static GatherMemType random_dynamic_gm;
|
||||
static uint8 dynamic_mempool[2048];
|
||||
|
||||
/* thread control pointer */
|
||||
static int32 random_tid1 = NONE;
|
||||
static int32 random_tid2 = NONE;
|
||||
/* task1 entry */
|
||||
int time_seed = 1;
|
||||
char temp_parameter[40];
|
||||
|
||||
static void RandomTask1GmAlloc(void *parameter)
|
||||
{
|
||||
int i;
|
||||
int total=0;
|
||||
time_seed++;
|
||||
srand(time_seed);
|
||||
char string[10];
|
||||
|
||||
while(total<40){
|
||||
i = rand()%40;
|
||||
if (random_ptr[i] == NONE){
|
||||
/* alloc memory blocks for 50 times, if failed, suspend task1 and start task2 */
|
||||
if (0 == strncmp("static", temp_parameter, strlen("static"))){
|
||||
random_ptr[i] = AllocBlockMemGather(&random_static_gm, WAITING_FOREVER);
|
||||
if (random_ptr[i] != NONE){
|
||||
itoa(i,string,10);
|
||||
memcpy(random_ptr[i],string,sizeof(string));
|
||||
KPrintf("%s No.%d: %s\n",temp_parameter, i, random_ptr[i]);
|
||||
}
|
||||
}else{
|
||||
random_ptr[i] = AllocBlockMemGather(random_dynamic_gm, WAITING_FOREVER);
|
||||
if (random_ptr[i] != NONE){
|
||||
itoa(i,string,10);
|
||||
memcpy(random_ptr[i],string,sizeof(string));
|
||||
KPrintf("%s No.%d: %s\n", temp_parameter, i, random_ptr[i]);
|
||||
}
|
||||
}
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* task2 entry, its priority is lower than task1 */
|
||||
static void RandomTask2GmRelease(void *parameter)
|
||||
{
|
||||
int i;
|
||||
time_seed++;
|
||||
srand(time_seed);
|
||||
|
||||
|
||||
int total = 0;
|
||||
|
||||
while(total<40){
|
||||
i = rand()%40;
|
||||
|
||||
/* release all memory blocks */
|
||||
if (random_ptr[i] != NONE){
|
||||
DelayKTask(10);
|
||||
KPrintf("release block %d: %s\n",i, random_ptr[i]);
|
||||
FreeBlockMemGather(random_ptr[i]);
|
||||
random_ptr[i] = NONE;
|
||||
total++;
|
||||
}
|
||||
}
|
||||
if (0 == strncmp("static", temp_parameter, strlen("static"))) {
|
||||
KPrintf("**************** detach gatherblock test *****************\n");
|
||||
RemoveMemGather(&random_static_gm);
|
||||
} else {
|
||||
KPrintf("**************** delete gatherblock test *****************\n");
|
||||
DeleteMemGather(random_dynamic_gm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int RandomAllocFreeTest(void *parameter)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 40; i ++) random_ptr[i] = NONE;
|
||||
memcpy(temp_parameter,parameter, 10);
|
||||
/* init memory block object */
|
||||
if(0 == strncmp("static", parameter, strlen("static"))){
|
||||
KPrintf("test static create gatherblock-%s.\n",parameter);
|
||||
InitMemGather(&random_static_gm, "ran_mp_s", &dynamic_mempool[0], sizeof(dynamic_mempool), 80);
|
||||
ShowMemPool();
|
||||
}else{
|
||||
KPrintf("test dynamic create gatherblock.\n");
|
||||
random_dynamic_gm = CreateMemGather("ran_mp_d",40,80);
|
||||
if(random_dynamic_gm == NONE){
|
||||
KPrintf("%s: allocate failure.\n",__func__);
|
||||
return -1;
|
||||
}
|
||||
ShowMemPool();
|
||||
}
|
||||
/* create task1, alloc memory blocks */
|
||||
random_tid1 = KTaskCreate("r_task1", RandomTask1GmAlloc, parameter,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY);
|
||||
if (random_tid1 >= 0){
|
||||
StartupKTask(random_tid1);
|
||||
}
|
||||
|
||||
/* create task2, release memory blocks */
|
||||
random_tid2 = KTaskCreate("r_task2", RandomTask2GmRelease, parameter,
|
||||
TASK_STACK_SIZE,
|
||||
TASK_PRIORITY + 1);
|
||||
if (random_tid2 >= 0){
|
||||
StartupKTask(random_tid2);
|
||||
}
|
||||
else{
|
||||
KPrintf("create task2 for release failure.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
void TestGatherblockUsage(void)
|
||||
{
|
||||
KPrintf("TestGatherblockUsage.\n");
|
||||
KPrintf("test_main gm -a --static, dynamic and multiple test.\n");
|
||||
KPrintf("test_main gm -s static/dynamic --test static create gatherblock to allocate and free.\n");
|
||||
KPrintf("test_main gm -m --test multiple gatherblock to allocate and free.\n");
|
||||
KPrintf("test_main gm count_size [count] [size] --create a gatherblock with typed count and size "
|
||||
"to allocate and free.\n");
|
||||
KPrintf("test_main gm multiple_gms [count] [size] [gm_ns] --create multiple gatherblocks with typed count and \n");
|
||||
KPrintf(" size to allocate and free.\n");
|
||||
KPrintf("test_main gm traverse --traverse.\n");
|
||||
KPrintf("test_main gm -r static/dynamic --random allocate and free.\n");
|
||||
|
||||
}
|
||||
|
||||
int TestGatherblock(char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (NONE == argv || 0 == strncmp("-h", argv[0], strlen("-h")) || 0 == strncmp("usage", argv[0], strlen("usage"))) {
|
||||
TestGatherblockUsage();
|
||||
return -EINVALED;
|
||||
}
|
||||
/**************** gatherblock auto test ******************/
|
||||
if (0 == strncmp("-a", argv[0], strlen("-a"))) {
|
||||
ret = SingleGatherblockTest("static"); ///< static creat single gatherblock test
|
||||
MdelayKTask(7000);
|
||||
ret |= SingleGatherblockTest("dynamic"); ///< dynamic creat single gatherblock test
|
||||
MdelayKTask(7000);
|
||||
ret |= MultipleGatherblockTest();
|
||||
MdelayKTask(7000);
|
||||
ret |= RandomAllocFreeTest("static");
|
||||
MdelayKTask(7000);
|
||||
ret |= RandomAllocFreeTest("dynamic");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/**************** single gatherblock test ****************/
|
||||
if (0 == strncmp("-s",argv[0],strlen("-s")) ) {
|
||||
if (0 == strncmp("static",argv[1],strlen("static"))) {
|
||||
ret = SingleGatherblockTest("static"); ///< static creat single gatherblock test
|
||||
} else {
|
||||
ret = SingleGatherblockTest("dynamic"); ///< dynamic creat single gatherblock test
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
/**************** mutiple gatherblock test ****************/
|
||||
if (0 == strncmp("-m",argv[0],strlen("-m")) ) {
|
||||
ret = MultipleGatherblockTest();
|
||||
goto out;
|
||||
}
|
||||
/******************** limitation test **********************/
|
||||
if (0 == strncmp("count_size",argv[0],strlen("count_size")) ) {
|
||||
int size = atoi(argv[2]);
|
||||
int count = atoi(argv[1]);
|
||||
GatherblockLimitTest("xsos",count,size);
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/******************** limitation test **********************/
|
||||
if (0 == strncmp("multiple_gms",argv[0],strlen("multiple_gms")) ) {
|
||||
int size = atoi(argv[2]);
|
||||
int count = atoi(argv[1]);
|
||||
int poolnumber = atoi(argv[3]);
|
||||
GatherblockLimitcountTest("xsos",count,size,poolnumber);
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/********************** traverse test **********************/
|
||||
if (0 == strncmp("traverse",argv[0],strlen("traverse")) ) {
|
||||
TraverseGmTest();
|
||||
goto out;
|
||||
}
|
||||
|
||||
/**************** random alloc and free test ****************/
|
||||
if (0 == strncmp("-r",argv[0],strlen("-r")) ) {
|
||||
ret = RandomAllocFreeTest(argv[1]);
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
if (ret < 0) {
|
||||
KPrintf("test gatherblock failed ret = %d.\n",ret);
|
||||
return -ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
74
kernel/kernel_test/test_hwtimer.c
Normal file
74
kernel/kernel_test/test_hwtimer.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_hwtimer.c
|
||||
* @brief support to test hwtimer function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <bus.h>
|
||||
#include <xsconfig.h>
|
||||
#include <dev_hwtimer.h>
|
||||
|
||||
#if defined (ARCH_ARM)
|
||||
#define HWTIMER_BUS_NAME HWTIMER_BUS_NAME_2
|
||||
#define HWTIMER_DEVICE_NAME HWTIMER_2_DEVICE_NAME_2
|
||||
#elif defined (ARCH_RISCV)
|
||||
#define HWTIMER_BUS_NAME HWTIMER_BUS_NAME_1
|
||||
#define HWTIMER_DEVICE_NAME HWTIMER_1_DEVICE_NAME_1
|
||||
#elif
|
||||
#define HWTIMER_BUS_NAME
|
||||
#define HWTIMER_DEVICE_NAME
|
||||
#endif
|
||||
|
||||
void TimeoutCb(void* param){
|
||||
KPrintf("resource_sample callback come ... \n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void HwtimerSample(void)//int argc, char *argv[]
|
||||
{
|
||||
struct Bus * hwtimer_bus = BusFind(HWTIMER_BUS_NAME);
|
||||
if (NULL == hwtimer_bus){
|
||||
KPrintf("hwtimer bus find failed !\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
struct HardwareDev* dev = BusFindDevice(hwtimer_bus, HWTIMER_DEVICE_NAME);
|
||||
struct HwtimerHardwareDevice* hwtimer_dev = (struct HwtimerHardwareDevice*)dev;
|
||||
if (NULL == hwtimer_dev){
|
||||
KPrintf("hwtimer hwtimer_dev find failed !\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
hwtimer_dev->hwtimer_param.repeat = 1;
|
||||
hwtimer_dev->hwtimer_param.period_millisecond = 3000;
|
||||
hwtimer_dev->hwtimer_param.cb_info.param = NULL;
|
||||
hwtimer_dev->hwtimer_param.cb_info.TimeoutCb = TimeoutCb;
|
||||
|
||||
BusDevOpen(dev);
|
||||
|
||||
MdelayKTask(20000);
|
||||
|
||||
KPrintf("close hwtimer...\n");
|
||||
BusDevClose(dev);
|
||||
|
||||
}
|
||||
/* export to shell cmd */
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_DISABLE_RETURN|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
HwtimerSample, HwtimerSample, HwtimerSample );
|
||||
178
kernel/kernel_test/test_i2c.c
Normal file
178
kernel/kernel_test/test_i2c.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_i2c.c
|
||||
* @brief support to test i2c function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <device.h>
|
||||
#include <bus.h>
|
||||
|
||||
/*********************************************************************************************************************************************************/
|
||||
/*
|
||||
* function:I2C device sample support reading temperature and humidity sensor data and printfing on the terminal
|
||||
* shell cmd:i2c_HS3000_sample i2c1
|
||||
* shell cmd param:i2c device name,if null means default i2c device name
|
||||
*/
|
||||
|
||||
#define HS_I2C_BUS_NAME I2C_BUS_NAME_1 /* I2C bus name */
|
||||
#define HS_I2C_DEV_NAME I2C_1_DEVICE_NAME_0/* I2C device name */
|
||||
#define HS_I2C_DRV_NAME I2C_DRV_NAME_1 /* I2C driver name */
|
||||
#define ADDR 0x44 /* slave address */
|
||||
|
||||
static struct Bus *i2c_bus = NONE; /* I2C bus handle */
|
||||
|
||||
typedef struct Hs300xData
|
||||
{
|
||||
int humi_high;
|
||||
int humi_low;
|
||||
int temp_high;
|
||||
int temp_low;
|
||||
}Hs300xDataType;
|
||||
|
||||
Hs300xDataType g_hs300x_data;
|
||||
|
||||
static x_err_t WriteReg(struct HardwareDev *dev)
|
||||
{
|
||||
struct BusBlockWriteParam write_param;
|
||||
|
||||
/* use I2C device API transfer data */
|
||||
if(1 == BusDevWriteData(dev, &write_param)) {
|
||||
return EOK;
|
||||
}
|
||||
else{
|
||||
return -ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* read sensor register data */
|
||||
static x_err_t ReadRegs(struct HardwareDev *dev, uint8 len, uint8 *buf)
|
||||
{
|
||||
struct BusBlockReadParam read_param;
|
||||
|
||||
read_param.buffer = (void *)buf;
|
||||
read_param.size = len;
|
||||
|
||||
/* use I2C device API transfer data */
|
||||
if(1 == BusDevReadData(dev, &read_param)){
|
||||
return EOK;
|
||||
}
|
||||
else{
|
||||
return -ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static void read_temp_humi(float *cur_temp, float *cur_humi)
|
||||
{
|
||||
uint8 temp[4],ret=0;
|
||||
MdelayKTask(15);
|
||||
ret = WriteReg(i2c_bus->owner_haldev); //reset
|
||||
if(EOK != ret){
|
||||
KPrintf("read_temp_humi WriteReg failed!\n");
|
||||
}
|
||||
MdelayKTask(50);
|
||||
ret = ReadRegs(i2c_bus->owner_haldev, 4, temp); /* get sensor data */
|
||||
if(EOK != ret){
|
||||
KPrintf("read_temp_humi ReadRegs failed\n");
|
||||
}
|
||||
|
||||
*cur_humi = ((temp[0] <<8 | temp[1] )& 0x3fff ) * 100.0 / ( (1 << 14) - 1); /* humidity data */
|
||||
|
||||
*cur_temp = ((temp[2] << 8 | temp[3]) >> 2) * 165.0 /( (1 << 14) - 1) - 40.0; /* temperature data */
|
||||
}
|
||||
|
||||
static void _HS3000Init(const char *bus_name, const char *dev_name, const char *drv_name)
|
||||
{
|
||||
/* find I2C device and get I2C handle */
|
||||
i2c_bus = BusFind(bus_name);
|
||||
if (NONE == i2c_bus){
|
||||
KPrintf("_HS3000Init can't find %s bus!\n", bus_name);
|
||||
}
|
||||
else{
|
||||
KPrintf("_HS3000Init find %s bus!\n", bus_name);
|
||||
}
|
||||
|
||||
i2c_bus->owner_haldev = BusFindDevice(i2c_bus, dev_name);
|
||||
i2c_bus->owner_driver = BusFindDriver(i2c_bus, drv_name);
|
||||
|
||||
if(i2c_bus->match(i2c_bus->owner_driver, i2c_bus->owner_haldev)){
|
||||
KPrintf("i2c match drv %s %p dev %s %p error\n", drv_name, i2c_bus->owner_driver, dev_name, i2c_bus->owner_haldev);
|
||||
}
|
||||
else{
|
||||
KPrintf("_HS3000Init successfully!write %p read %p\n",
|
||||
i2c_bus->owner_haldev->dev_done->write,
|
||||
i2c_bus->owner_haldev->dev_done->read);
|
||||
}
|
||||
}
|
||||
|
||||
void Hs300xInit(void)
|
||||
{
|
||||
_HS3000Init(HS_I2C_BUS_NAME, HS_I2C_DEV_NAME, HS_I2C_DRV_NAME); /* init sensor */
|
||||
}
|
||||
|
||||
void Hs300xRead(Hs300xDataType *Hs300xDataType)
|
||||
{
|
||||
float humidity = 0.0, temperature = 0.0;
|
||||
read_temp_humi(&temperature, &humidity); /* read temperature and humidity sensor data */
|
||||
Hs300xDataType->humi_high = (int)humidity;
|
||||
Hs300xDataType->humi_low = (int)(humidity*10)%10;
|
||||
if( temperature >= 0 ) {
|
||||
Hs300xDataType->temp_high = (int)temperature;
|
||||
Hs300xDataType->temp_low = (int)(temperature*10)%10;
|
||||
}
|
||||
else{
|
||||
Hs300xDataType->temp_high = (int)temperature;
|
||||
Hs300xDataType->temp_low = (int)(-temperature*10)%10;
|
||||
}
|
||||
}
|
||||
|
||||
void Tsk_hs300x_test()
|
||||
{
|
||||
memset(&g_hs300x_data, 0, sizeof(Hs300xDataType));
|
||||
KPrintf("Tsk create successfully!\n");
|
||||
|
||||
while(1)
|
||||
{
|
||||
Hs300xRead(&g_hs300x_data);
|
||||
|
||||
KPrintf("HS300X:I2C humidity:%d.%d temperature:%d.%d\n",
|
||||
g_hs300x_data.humi_high,
|
||||
g_hs300x_data.humi_low,
|
||||
g_hs300x_data.temp_high,
|
||||
g_hs300x_data.temp_low);
|
||||
|
||||
MdelayKTask(1000);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Hs300xI2cTest(void)
|
||||
{
|
||||
Hs300xInit();
|
||||
MdelayKTask(1000);
|
||||
|
||||
x_err_t flag;
|
||||
int32 Tsk_hs300x = KTaskCreate("Tsk_hs300x", Tsk_hs300x_test, NONE, 2048, 10);
|
||||
flag = StartupKTask(Tsk_hs300x);
|
||||
if (EOK != flag){
|
||||
KPrintf("Hs300xI2cTest StartupKTask failed!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
||||
Hs300xI2cTest, Hs300xI2cTest, Test the HS300X using I2C);
|
||||
67
kernel/kernel_test/test_iwg.c
Normal file
67
kernel/kernel_test/test_iwg.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestIwg.c
|
||||
* @brief support to test watchdog function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <device.h>
|
||||
|
||||
static BusType wdt;
|
||||
|
||||
/**
|
||||
* @description: Feed watchdog task function
|
||||
*/
|
||||
static void FeedWatchdog(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
/* keep watchdog alive in idle task */
|
||||
struct BusConfigureInfo cfg;
|
||||
cfg.configure_cmd = OPER_WDT_KEEPALIVE;
|
||||
cfg.private_data = NONE;
|
||||
BusDrvConfigure(wdt->owner_driver, &cfg);
|
||||
KPrintf("feed the dog!\n ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Watchdog test function
|
||||
* @return success: EOK, failure: other
|
||||
*/
|
||||
int TestIwg(void)
|
||||
{
|
||||
x_err_t res = EOK;
|
||||
uint32 timeout = 1000; /* timeout time */
|
||||
|
||||
wdt = BusFind(WDT_BUS_NAME_0);
|
||||
wdt->owner_driver = BusFindDriver(wdt, WDT_DRIVER_NAME_0);
|
||||
wdt->owner_haldev = BusFindDevice(wdt, WDT_0_DEVICE_NAME_0);
|
||||
|
||||
/* set watchdog timeout time */
|
||||
struct BusConfigureInfo cfg;
|
||||
cfg.configure_cmd = OPER_WDT_SET_TIMEOUT;
|
||||
cfg.private_data = &timeout;
|
||||
res = BusDrvConfigure(wdt->owner_driver, &cfg);
|
||||
KPrintf("feed the dog!\n");
|
||||
|
||||
int32 WdtTask = KTaskCreate("WdtTask", (void *)FeedWatchdog, NONE, 2048, 20);
|
||||
res = StartupKTask(WdtTask);
|
||||
|
||||
return res;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),TestIwg, TestIwg, TestIwg );
|
||||
99
kernel/kernel_test/test_lcd.c
Normal file
99
kernel/kernel_test/test_lcd.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file EnableLcd.c
|
||||
* @brief support to test lcd function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include "bus_lcd.h"
|
||||
#include "dev_lcd.h"
|
||||
|
||||
uint16 color = RED;
|
||||
|
||||
char *addr ="LCD Testing ";
|
||||
|
||||
/**
|
||||
* @description: Enable LCD function
|
||||
* @param bus_name - LCD bus name
|
||||
* @param driver_name - LCD driver name
|
||||
* @param device_name - LCD device name
|
||||
*/
|
||||
int EnableLcd(const char *bus_name, const char *driver_name, const char *device_name)
|
||||
{
|
||||
struct Bus *bus;
|
||||
struct Driver *driver, *bus_driver;
|
||||
struct HardwareDev *device;
|
||||
struct HardwareDev *bus_device;
|
||||
|
||||
|
||||
if (bus_name) {
|
||||
KPrintf("##test find bus %s\n", bus_name);
|
||||
bus = BusFind(bus_name);
|
||||
KPrintf("##test bus %p##\n", bus);
|
||||
}
|
||||
|
||||
if (driver_name) {
|
||||
KPrintf("##test find driver %s\n", driver_name);
|
||||
driver = LcdDriverFind(driver_name, TYPE_LCD_DRV);
|
||||
bus_driver = BusFindDriver(bus, driver_name);
|
||||
KPrintf("##test driver %p bus_driver %p####\n", driver, bus_driver);
|
||||
}
|
||||
|
||||
if (device_name) {
|
||||
KPrintf("##test find device %s\n", device_name);
|
||||
device = LcdDeviceFind(device_name, TYPE_LCD_DEV);
|
||||
bus_device = BusFindDevice(bus, device_name);
|
||||
KPrintf("##test device %p bus_device %p##\n", device, bus_device);
|
||||
}
|
||||
|
||||
LcdStringParam str;
|
||||
str.x_pos = 60 ;
|
||||
str.y_pos = 40;
|
||||
str.width = 250;
|
||||
str.height = 24;
|
||||
str.font_size = 24;
|
||||
str.addr = addr;
|
||||
str.font_color = WHITE;
|
||||
str.back_color = RED;
|
||||
|
||||
struct BusBlockWriteParam write_param;
|
||||
memset(&write_param,0,sizeof(struct BusBlockWriteParam ));
|
||||
|
||||
struct BusConfigureInfo pdata = {RED,NONE};
|
||||
|
||||
write_param.pos = 0;
|
||||
write_param.buffer = &str ;
|
||||
|
||||
while (1) {
|
||||
|
||||
BusDrvConfigure(bus_driver, &pdata );
|
||||
MdelayKTask(1000);
|
||||
|
||||
BusDevWriteData(device,&write_param);
|
||||
MdelayKTask(1000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: LCD test function
|
||||
*/
|
||||
void TestLcd(void)
|
||||
{
|
||||
EnableLcd(LCD_BUS_NAME_1,LCD_DRV_NAME_1,LCD_1_DEVICE_NAME_0);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),TestLcd, TestLcd, Test LCD );
|
||||
125
kernel/kernel_test/test_main.c
Normal file
125
kernel/kernel_test/test_main.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestMain.c
|
||||
* @brief support to test function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <stdio.h>
|
||||
#define MAX_ITEM_NAME_LENGTH 16
|
||||
extern int TestIwg(void);
|
||||
|
||||
int TestTmrD(void);
|
||||
int TestTmrM(void);
|
||||
|
||||
extern int TestTmr(int argc, char *argv[]);
|
||||
extern int TestMem(int argc, char *argv[]);
|
||||
extern int TestGatherblock(char *argv[]);
|
||||
extern int TestTaskReadyAndSched(int argc, char *argv[]);
|
||||
extern int TestRealtime(int argc, char * argv[]);
|
||||
|
||||
void KernelTestusage(void)
|
||||
{
|
||||
KPrintf("test usage.\n");
|
||||
KPrintf("e.g., TestMain -mem\n");
|
||||
}
|
||||
struct TestSubitem
|
||||
{
|
||||
char name[MAX_ITEM_NAME_LENGTH];
|
||||
int item;
|
||||
};
|
||||
|
||||
enum TestItem
|
||||
{
|
||||
USAGE = 0, /* usage idex */
|
||||
MEM, /* mem test item index */
|
||||
TIMER, /* timer test item index */
|
||||
GATHERBLOCK,
|
||||
SCHED, /* task sched test */
|
||||
IWG, /* iwg test item index */
|
||||
REALTIME,
|
||||
INVALID_ITEM, /* invalid index */
|
||||
};
|
||||
|
||||
static struct TestSubitem kernel_subitem[INVALID_ITEM] =
|
||||
{
|
||||
{ "-h", USAGE },
|
||||
{ "-mem", MEM },
|
||||
{ "-timer", TIMER},
|
||||
{ "-gm", GATHERBLOCK},
|
||||
{ "-sched", SCHED},
|
||||
{ "-iwg", IWG},
|
||||
{ "-realtime", REALTIME},
|
||||
|
||||
};
|
||||
|
||||
int TestMain(int argc, char*argv[])
|
||||
{
|
||||
char name[MAX_ITEM_NAME_LENGTH] = {0};
|
||||
int i = 0;
|
||||
int item = -1;
|
||||
|
||||
strncpy(name, argv[1], MAX_ITEM_NAME_LENGTH); ///< getting input name of test item
|
||||
for(i = 0; i < INVALID_ITEM; i++) {
|
||||
if(0 == strncmp(kernel_subitem[i].name, name, MAX_ITEM_NAME_LENGTH) ){
|
||||
item = kernel_subitem[i].item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(item)
|
||||
{
|
||||
case USAGE:
|
||||
KernelTestusage();
|
||||
break;
|
||||
case MEM:
|
||||
#ifdef KERNEL_TEST_MEM
|
||||
TestMem(argc-2,&argv[2]);
|
||||
#endif
|
||||
break;
|
||||
case TIMER:
|
||||
#ifdef KERNEL_TEST_TIMER
|
||||
TestTmr(argc-2,&argv[2]);
|
||||
#endif
|
||||
break;
|
||||
case GATHERBLOCK:
|
||||
#ifdef KERNEL_TEST_MEM
|
||||
TestGatherblock(&argv[2]);
|
||||
#endif
|
||||
break;
|
||||
case SCHED:
|
||||
#ifdef KERNEL_TEST_SCHED
|
||||
TestTaskReadyAndSched(argc-2, &argv[2]);
|
||||
#endif
|
||||
break;
|
||||
case IWG:
|
||||
#ifdef KERNEL_TEST_IWG
|
||||
TestIwg();
|
||||
#endif
|
||||
case REALTIME:
|
||||
#ifdef KERNEL_TEST_REALTIME
|
||||
TestRealtime(argc-2, &argv[2]);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_DISABLE_RETURN|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
TestMain, TestMain, test main sample );
|
||||
451
kernel/kernel_test/test_mem.c
Normal file
451
kernel/kernel_test/test_mem.c
Normal file
@@ -0,0 +1,451 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestMem.c
|
||||
* @brief support to test mem function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <string.h>
|
||||
|
||||
extern void ShowMemory(void);
|
||||
extern void ListBuddy(void);
|
||||
|
||||
/**************************test memory usage***********************************/
|
||||
|
||||
#include<time.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
#define TASK_PRIORITY 5
|
||||
#define TASK_STACK_SIZE 4096
|
||||
#define TASK_TIMESLICE 5
|
||||
#define MEM_TEST_NUMBER 23
|
||||
|
||||
int number_imm=0;
|
||||
static int arr[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22};
|
||||
|
||||
void Fimm(void *parameter)
|
||||
{
|
||||
KPrintf("%s: task starts.\n",__func__);
|
||||
int i=0;
|
||||
unsigned long size;
|
||||
char *ptr = NONE;
|
||||
|
||||
srand(number_imm);
|
||||
while (i<50) {
|
||||
size = 1 << arr[rand() % MEM_TEST_NUMBER];
|
||||
ptr = x_malloc(size);
|
||||
|
||||
if (ptr != NULL) {
|
||||
KPrintf("alloc-memory: %d btye\n",size);
|
||||
x_free(ptr);
|
||||
KPrintf("free--memory: %d byte\n",size);
|
||||
ptr=NONE;
|
||||
} else {
|
||||
KPrintf("try to get %d byte memory failed!\n",size);
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
number_imm++;
|
||||
}
|
||||
|
||||
int FreeImmediatelly(void){
|
||||
|
||||
KPrintf("\033[32;1m***********test limitations*************\033[0m\n");
|
||||
KPrintf("allocation and free pointer immdiatetely. \n");
|
||||
|
||||
int32 tid;
|
||||
tid = KTaskCreate("Fimm",Fimm,NONE,TASK_STACK_SIZE,TASK_PRIORITY);
|
||||
|
||||
if (tid >= 0)
|
||||
StartupKTask(tid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int num_FTillEnd=1;
|
||||
|
||||
void FTillEnd(void *parameter)
|
||||
{
|
||||
int i=0;
|
||||
unsigned long size;
|
||||
char *ptr[55];
|
||||
unsigned long arrsize[55];
|
||||
// srand((unsigned)time(NULL)*10);
|
||||
srand(num_FTillEnd);
|
||||
num_FTillEnd++;
|
||||
|
||||
while (i<50) {
|
||||
size = 1 << arr[rand() % MEM_TEST_NUMBER];
|
||||
ptr[i] = x_malloc(size);
|
||||
arrsize[i]=size;
|
||||
|
||||
if (ptr[i] != NULL) {
|
||||
KPrintf("get memory: %d btye\n",size);
|
||||
} else {
|
||||
KPrintf("try to get %d byte memory failed!\n",size);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
i -= 1;
|
||||
for( ; i>=0 ; i-- ) {
|
||||
x_free(ptr[i]);
|
||||
KPrintf("free memory: %d byte\n",arrsize[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int FreeEnd(void)
|
||||
{
|
||||
KPrintf("\033[32;1m***********test limitations*************\033[0m\n");
|
||||
KPrintf("-------allocation until no memory-------\n");
|
||||
|
||||
int32 tid;
|
||||
tid = KTaskCreate("fend",FTillEnd,NONE,TASK_STACK_SIZE,TASK_PRIORITY);
|
||||
|
||||
if (tid >= 0)
|
||||
StartupKTask(tid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef ARCH_ARM
|
||||
#define MEM_GRIN_COUNT 1024
|
||||
#else
|
||||
#define MEM_GRIN_COUNT 8000
|
||||
#endif
|
||||
|
||||
char *ptr[MEM_GRIN_COUNT];
|
||||
unsigned int arr_grin[MEM_GRIN_COUNT];
|
||||
|
||||
extern void ListBuddy();
|
||||
int FendGrin()
|
||||
{
|
||||
KPrintf("\033[32;1m***********test limitations*************\033[0m\n");
|
||||
KPrintf("-------allocation for 1 byte with step 1-------\n");
|
||||
int i=0;
|
||||
int tempvalue = 1;
|
||||
|
||||
while( i< MEM_GRIN_COUNT) {
|
||||
KPrintf("\033[32;1malloc memory [%d]\033[0m\n",tempvalue);
|
||||
ptr[i] = x_malloc(tempvalue);
|
||||
|
||||
if (ptr[i]) {
|
||||
arr_grin[i] = tempvalue;
|
||||
i++;
|
||||
tempvalue++;
|
||||
} else {
|
||||
if (tempvalue == 60)
|
||||
break;
|
||||
tempvalue=60;
|
||||
}
|
||||
}
|
||||
KPrintf("------------- limitation until [%d] -----------\n",i);
|
||||
ListBuddy();
|
||||
|
||||
DelayKTask(2000);
|
||||
|
||||
i -= 1;
|
||||
for ( ; i>=0 ; i-- ) {
|
||||
x_free(ptr[i]);
|
||||
KPrintf("free memory: %d byte\n",arr_grin[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef ARCH_ARM
|
||||
#define MEM_CACHE_COUNT 1024
|
||||
#else
|
||||
#define MEM_CACHE_COUNT 8000
|
||||
#endif
|
||||
|
||||
char *cache_ptr[MEM_CACHE_COUNT];
|
||||
|
||||
void TestCacheLimitation(int timers,int init)
|
||||
{
|
||||
KPrintf("\033[32;1m******test small memory limit****\033[0m\n");
|
||||
int temp = init;
|
||||
int index;
|
||||
void *temp_ptr;
|
||||
|
||||
timers = timers > MEM_CACHE_COUNT? MEM_CACHE_COUNT: timers;
|
||||
|
||||
for (index = 1; index <= timers;index++) {
|
||||
if (index&1) {
|
||||
KPrintf("%d: x_malloc size [%d]. \n", index, temp);
|
||||
cache_ptr[index] = x_malloc(temp);
|
||||
} else {
|
||||
KPrintf("%d: x_calloc size [%d]. \n", index, temp);
|
||||
cache_ptr[index] = x_calloc(1,temp);
|
||||
}
|
||||
|
||||
if (cache_ptr[index] == NONE) {
|
||||
KPrintf("%d: malloc or calloc failure. \n", index);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((index % 4) == 0) {
|
||||
KPrintf("%d: x_realloc size [%d]. \n", index, temp+index);
|
||||
temp_ptr = cache_ptr[index];
|
||||
cache_ptr[index] = x_realloc(cache_ptr[index], temp+index);
|
||||
if (cache_ptr[index] == NONE) {
|
||||
KPrintf("%d: x_realloc failure, roll back old pointer. \n", index);
|
||||
cache_ptr[index] = temp_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
temp++;
|
||||
temp %= 64;
|
||||
temp = ((temp==0) ? (temp + 1) : temp);
|
||||
}
|
||||
ListBuddy();
|
||||
|
||||
DelayKTask(1000);
|
||||
|
||||
index--;
|
||||
|
||||
for(; index > 0; index--){
|
||||
//KPrintf("free %d\n",index);
|
||||
x_free(cache_ptr[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void UsageMem()
|
||||
{
|
||||
KPrintf("%s: invalidate parameter\n",__func__);
|
||||
KPrintf("%s: usage for memory \n",__func__);
|
||||
KPrintf("%s: -s, test malloc allocation, e.g., test_main mem -s 64 \n",__func__);
|
||||
KPrintf("%s: -c, test calloc allocation, e.g., test_main mem -c 64 \n",__func__);
|
||||
KPrintf("%s: -r, test realloc allocation, e.g., test_main mem -r 64 80 \n",__func__);
|
||||
KPrintf("%s: -Fimm, test limit allocation, e.g., test_main mem -Fimm \n",__func__);
|
||||
KPrintf("%s: -fend, test limit allocation, e.g., test_main mem -fend \n",__func__);
|
||||
KPrintf("%s: -grin, test limit allocation, e.g., test_main mem -grin \n",__func__);
|
||||
KPrintf("%s: rw, test read and write opts, e.g., test_main mem rw 100 \"oldcontent\" \"newcontent\"\n",__func__);
|
||||
KPrintf("%s: cache, test limit allocation, e.g., test_main mem cache 100 1,\n",__func__);
|
||||
KPrintf("%s: allocate small mem for 100 timers started from 1. \n",__func__);
|
||||
KPrintf("%s: exception, make exception, e.g., test_main mem exception 100\n",__func__);
|
||||
}
|
||||
|
||||
void TestMalloc(x_size_t size)
|
||||
{
|
||||
KPrintf("\033[32;1m**********x_malloc & x_free***********\033[0m\n");
|
||||
KPrintf("the memory size is [%u] for allocation. \n", size);
|
||||
KPrintf("-------------before x_malloc-----------\n");
|
||||
|
||||
ShowMemory();
|
||||
|
||||
void *ptr = x_malloc(size);
|
||||
if (ptr) {
|
||||
KPrintf("----------x_malloc successfully--------\n");
|
||||
ShowMemory();
|
||||
x_free(ptr);
|
||||
KPrintf("-----------x_free successfully---------\n");
|
||||
ShowMemory();
|
||||
} else {
|
||||
KPrintf("------------x_malloc failure-----------\n");
|
||||
}
|
||||
KPrintf("****************** end *****************\n");
|
||||
}
|
||||
|
||||
void TestReAlloc(x_size_t size_prev, x_size_t size_next)
|
||||
{
|
||||
KPrintf("\033[32;1m**********x_realloc & x_free**********\033[0m\n");
|
||||
KPrintf("the memory size is [%u] for x_malloc. \n", size_prev);
|
||||
KPrintf("-------------before x_malloc-----------\n");
|
||||
ShowMemory();
|
||||
|
||||
void *ptr = x_malloc(size_prev);
|
||||
void *ptr2;
|
||||
if (ptr) {
|
||||
KPrintf("---------x_malloc successfully--------\n");
|
||||
ShowMemory();
|
||||
KPrintf("-----------before x_realloc-----------\n");
|
||||
KPrintf("the memory size is [%u] for x_malloc. \n", size_next);
|
||||
ptr2 = x_realloc(ptr, size_next);
|
||||
if (ptr2) {
|
||||
KPrintf("-----------realloc successfully---------\n");
|
||||
ShowMemory();
|
||||
x_free(ptr2);
|
||||
KPrintf("-----------x_free successfully---------\n");
|
||||
ShowMemory();
|
||||
} else {
|
||||
KPrintf("-----------x_realloc failure-----------\n");
|
||||
if(size_next !=0)
|
||||
x_free(ptr);
|
||||
KPrintf("-----------x_free successfully---------\n");
|
||||
ShowMemory();
|
||||
}
|
||||
} else {
|
||||
KPrintf("-----------x_malloc failure------------\n");
|
||||
}
|
||||
KPrintf("****************** end *****************\n");
|
||||
}
|
||||
|
||||
void TestCalloc(x_size_t size)
|
||||
{
|
||||
KPrintf("\033[32;1m**********x_calloc & x_free***********\033[0m\n");
|
||||
KPrintf("the memory size is [%u] for x_malloc. \n", size);
|
||||
KPrintf("------------before x_calloc------------\n");
|
||||
ShowMemory();
|
||||
|
||||
void*ptr = x_calloc(1, size);
|
||||
if (ptr) {
|
||||
KPrintf("---------x_calloc successfully---------\n");
|
||||
ShowMemory();
|
||||
x_free(ptr);
|
||||
KPrintf("----------x_free successfully----------\n");
|
||||
ShowMemory();
|
||||
} else {
|
||||
KPrintf("------------x_calloc failure-----------\n");
|
||||
}
|
||||
KPrintf("****************** end *****************\n");
|
||||
}
|
||||
|
||||
void TestReadWrite(x_size_t size, char *raw_content, char *new_content)
|
||||
{
|
||||
KPrintf("\033[32;1m**********read and write opts***********\033[0m\n");
|
||||
KPrintf("the memory size is [%u] for allocation. \n", size);
|
||||
KPrintf("-------------before x_malloc-----------\n");
|
||||
int endposition;
|
||||
|
||||
void *ptr = x_malloc(size);
|
||||
if (ptr) {
|
||||
KPrintf("----------x_malloc successfully--------\n");
|
||||
KPrintf("---------- show raw content --------\n");
|
||||
memcpy(ptr,raw_content, size > strlen(raw_content) ? strlen(raw_content): size);
|
||||
endposition = size > strlen(raw_content) ? strlen(raw_content): size;
|
||||
*((char*)ptr + endposition) = 0;
|
||||
|
||||
KPrintf("raw content is [\033[41;1m%s\033[0m]\n",ptr);
|
||||
KPrintf("----- write and show new content -----\n");
|
||||
memcpy(ptr,new_content, size > strlen(new_content)? strlen(new_content): size);
|
||||
endposition = size>strlen(new_content)? strlen(new_content): size;
|
||||
|
||||
*((char*)ptr + endposition) = 0;
|
||||
DelayKTask(100);
|
||||
|
||||
KPrintf("new content is [\033[41;1m%s\033[0m]\n",ptr);
|
||||
x_free(ptr);
|
||||
KPrintf("-----------x_free successfully---------\n");
|
||||
} else {
|
||||
KPrintf("------------x_malloc failure-----------\n");
|
||||
}
|
||||
KPrintf("\n------------------ end -----------------\n\n");
|
||||
|
||||
ptr = x_calloc(1,size);
|
||||
if (ptr) {
|
||||
KPrintf("----------x_calloc successfully--------\n");
|
||||
KPrintf("---------- show raw content --------\n");
|
||||
memcpy(ptr,raw_content,size > strlen(raw_content) ? strlen(raw_content): size);
|
||||
endposition = size > strlen(raw_content) ? strlen(raw_content): size;
|
||||
*((char*)ptr + endposition) = 0;
|
||||
|
||||
KPrintf("raw content is [\033[41;1m%s\033[0m]\n",ptr);
|
||||
KPrintf("----- write and show new content -----\n");
|
||||
memcpy(ptr,new_content,size > strlen(new_content) ? strlen(new_content): size);
|
||||
endposition = size > strlen(new_content) ? strlen(new_content): size;
|
||||
*((char*)ptr + endposition)=0;
|
||||
|
||||
DelayKTask(100);
|
||||
KPrintf("new content is [\033[41;1m%s\033[0m]\n",ptr);
|
||||
x_free(ptr);
|
||||
KPrintf("-----------x_free successfully---------\n");
|
||||
} else {
|
||||
KPrintf("------------x_calloc failure-----------\n");
|
||||
}
|
||||
KPrintf("****************** end *****************\n");
|
||||
}
|
||||
|
||||
void TestException(x_size_t size)
|
||||
{
|
||||
KPrintf("\033[32;1m**********test make exception***********\033[0m\n");
|
||||
KPrintf("the memory size is [%u] for allocation. \n", size);
|
||||
|
||||
void*ptr = x_malloc(size);
|
||||
if (ptr == NONE) {
|
||||
KPrintf("------------x_malloc failure-----------\n");
|
||||
} else {
|
||||
memset(ptr-8, 5, size+8);
|
||||
x_free(ptr);
|
||||
}
|
||||
KPrintf("****************** end *****************\n");
|
||||
}
|
||||
|
||||
int TestMem(int argc,char*argv[])
|
||||
{
|
||||
x_size_t size;
|
||||
x_size_t newsize;
|
||||
if (0 == strncmp("-h", argv[0], strlen("-h"))) {
|
||||
UsageMem();
|
||||
}
|
||||
|
||||
if (0 == strncmp("cache", argv[0], strlen("cache"))) {
|
||||
if (argc == 2) {
|
||||
size = atoi(argv[1]);
|
||||
newsize =1;
|
||||
}
|
||||
|
||||
if(argc == 3) {
|
||||
size = atoi(argv[1]);
|
||||
newsize = atoi(argv[2]);
|
||||
newsize = newsize==0 ? 1: newsize;
|
||||
}
|
||||
|
||||
TestCacheLimitation(size, newsize);
|
||||
}
|
||||
|
||||
if (0 == strncmp("-s", argv[0], strlen("-s"))) {
|
||||
size = atoi(argv[1]);
|
||||
TestMalloc(size);
|
||||
}
|
||||
|
||||
if (0 == strncmp("-r", argv[0], strlen("-r"))) {
|
||||
size = atoi(argv[1]);
|
||||
newsize = atoi(argv[2]);
|
||||
TestReAlloc(size,newsize);
|
||||
}
|
||||
|
||||
if (0 == strncmp("-c", argv[0], strlen("-c"))) {
|
||||
size = atoi(argv[1]);
|
||||
TestCalloc(size);
|
||||
}
|
||||
|
||||
if (0 == strncmp("-Fimm", argv[0], strlen("-Fimm"))) {
|
||||
FreeImmediatelly();
|
||||
}
|
||||
|
||||
if (0 == strncmp("-fend", argv[0], strlen("-fend"))) {
|
||||
FreeEnd();
|
||||
}
|
||||
|
||||
if (0 == strncmp("-grin", argv[0], strlen("-grin"))) {
|
||||
FendGrin();
|
||||
}
|
||||
|
||||
if (0 == strncmp("rw", argv[0], strlen("rw"))) {
|
||||
size = atoi(argv[1]);
|
||||
TestReadWrite(size, argv[2], argv[3]);
|
||||
}
|
||||
|
||||
if (0 == strncmp("exception",argv[0],strlen("exception"))) {
|
||||
size = atoi(argv[1]);
|
||||
TestException(size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************** end ***********************************/
|
||||
351
kernel/kernel_test/test_realtime.c
Normal file
351
kernel/kernel_test/test_realtime.c
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestRealtime.c
|
||||
* @brief support to test realtime function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <string.h>
|
||||
#include <dev_pin.h>
|
||||
|
||||
extern unsigned int usleep(unsigned int seconds);
|
||||
static BusType pin;
|
||||
|
||||
#ifdef ARCH_ARM
|
||||
#include <hardware_gpio.h>
|
||||
#define GPIO_C13 7
|
||||
#define GPIO_C2 17
|
||||
|
||||
void PinIrqIsr(void *args)
|
||||
{
|
||||
*(volatile unsigned int *)0x40020818 = 0x2000;
|
||||
|
||||
*(volatile unsigned int *)0x4002081a = 0x2000;
|
||||
}
|
||||
|
||||
int RealtimeIrqTest()
|
||||
{
|
||||
struct PinParam testpin_1;
|
||||
struct PinStat testpin_1_stat;
|
||||
struct PinParam testpin_2;
|
||||
int ret = 0;
|
||||
|
||||
struct BusConfigureInfo configure_info_1;
|
||||
struct BusConfigureInfo configure_info_2;
|
||||
struct BusBlockWriteParam write_param_1;
|
||||
|
||||
configure_info_1.configure_cmd = OPE_CFG;
|
||||
configure_info_1.private_data = (void *)&testpin_1;
|
||||
write_param_1.buffer = (void *)&testpin_1_stat;
|
||||
|
||||
configure_info_2.configure_cmd = OPE_CFG;
|
||||
configure_info_2.private_data = (void *)&testpin_2;
|
||||
|
||||
KPrintf("%s irq test\n",__func__);
|
||||
/* config test pin 1 as output*/
|
||||
testpin_1.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_1.pin = GPIO_C13;
|
||||
testpin_1.mode = GPIO_CFG_OUTPUT;
|
||||
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info_1);
|
||||
if (ret != EOK) {
|
||||
KPrintf("config testpin_1 %d failed!\n", GPIO_C13);
|
||||
return -ERROR;
|
||||
}
|
||||
|
||||
/* set test pin 1 as high*/
|
||||
testpin_1_stat.pin = GPIO_C13;
|
||||
testpin_1_stat.val = GPIO_LOW;
|
||||
BusDevWriteData(pin->owner_haldev, &write_param_1);
|
||||
|
||||
/* config test pin 2 as input*/
|
||||
testpin_2.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_2.pin = GPIO_C2;
|
||||
testpin_2.mode = GPIO_CFG_INPUT;
|
||||
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info_2);
|
||||
if (ret != EOK) {
|
||||
KPrintf("config testpin_2 %d input failed!\n", testpin_2.pin);
|
||||
return -ERROR;
|
||||
}
|
||||
|
||||
testpin_2.cmd = GPIO_IRQ_REGISTER;
|
||||
testpin_2.pin = GPIO_C2;
|
||||
testpin_2.irq_set.irq_mode = GPIO_IRQ_EDGE_BOTH;
|
||||
testpin_2.irq_set.hdr = PinIrqIsr;
|
||||
testpin_2.irq_set.args = NONE;
|
||||
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info_2);
|
||||
if (ret != EOK) {
|
||||
KPrintf("register testpin_2 %d irq failed!\n", testpin_2.pin);
|
||||
return -ERROR;
|
||||
}
|
||||
|
||||
testpin_2.cmd = GPIO_IRQ_ENABLE;
|
||||
testpin_2.pin = GPIO_C2;
|
||||
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info_2);
|
||||
if (ret != EOK) {
|
||||
KPrintf("enable testpin_2 %d irq failed!\n", testpin_2.pin);
|
||||
return -ERROR;
|
||||
}
|
||||
KPrintf("%s irq test\n",__func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RealtimeTaskSwitchTest()
|
||||
{
|
||||
struct PinParam testpin_1;
|
||||
struct PinStat testpin_1_stat;
|
||||
int ret = 0;
|
||||
|
||||
struct BusConfigureInfo configure_info_1;
|
||||
struct BusBlockWriteParam write_param_1;
|
||||
|
||||
configure_info_1.configure_cmd = OPE_CFG;
|
||||
configure_info_1.private_data = (void *)&testpin_1;
|
||||
write_param_1.buffer = (void *)&testpin_1_stat;
|
||||
|
||||
/* config test pin 1 as output*/
|
||||
testpin_1.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_1.pin = GPIO_C13;
|
||||
testpin_1.mode = GPIO_CFG_OUTPUT;
|
||||
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info_1);
|
||||
if (ret != EOK) {
|
||||
KPrintf("config testpin_1 %d failed!\n", GPIO_C13);
|
||||
return ;
|
||||
}
|
||||
|
||||
/* set test pin 1 as low*/
|
||||
testpin_1_stat.pin = GPIO_C13;
|
||||
testpin_1_stat.val = GPIO_LOW;
|
||||
BusDevWriteData(pin->owner_haldev, &write_param_1);
|
||||
|
||||
while (RET_TRUE) {
|
||||
DelayKTask(1);
|
||||
}
|
||||
}
|
||||
|
||||
void GpioSpeedTest()
|
||||
{
|
||||
struct PinParam testpin_1;
|
||||
struct PinStat testpin_1_stat;
|
||||
struct PinParam testpin_2;
|
||||
int ret = 0;
|
||||
|
||||
struct BusConfigureInfo configure_info_1;
|
||||
struct BusConfigureInfo configure_info_2;
|
||||
struct BusBlockWriteParam write_param_1;
|
||||
|
||||
configure_info_1.configure_cmd = OPE_CFG;
|
||||
configure_info_1.private_data = (void *)&testpin_1;
|
||||
write_param_1.buffer = (void *)&testpin_1_stat;
|
||||
|
||||
configure_info_2.configure_cmd = OPE_CFG;
|
||||
configure_info_2.private_data = (void *)&testpin_2;
|
||||
|
||||
/* config test pin 1 as output*/
|
||||
testpin_1.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_1.pin = GPIO_C13;
|
||||
testpin_1.mode = GPIO_CFG_OUTPUT;
|
||||
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info_1);
|
||||
if (ret != EOK) {
|
||||
KPrintf("config testpin_1 %d failed!\n", GPIO_C13);
|
||||
return ;
|
||||
}
|
||||
|
||||
testpin_2.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_2.pin = GPIO_C2;
|
||||
testpin_2.mode = GPIO_CFG_INPUT;
|
||||
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info_2);
|
||||
|
||||
/* set test pin 1 as low*/
|
||||
testpin_1_stat.pin = GPIO_C13;
|
||||
testpin_1_stat.val = GPIO_LOW;
|
||||
BusDevWriteData(pin->owner_haldev, &write_param_1);
|
||||
|
||||
while (RET_TRUE) {
|
||||
*(volatile unsigned int *)0x40020818 = 0x2000;
|
||||
|
||||
*(volatile unsigned int*)0x4002081a = 0x2000;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define GPIO_18 18
|
||||
#define GPIO_19 19
|
||||
|
||||
void PinIrqIsr(void *args)
|
||||
{
|
||||
*(volatile unsigned int *)0x3800100c |= 0x5;
|
||||
|
||||
*(volatile unsigned int *)0x3800100c &= ~0x5;
|
||||
}
|
||||
|
||||
int RealtimeIrqTest()
|
||||
{
|
||||
struct PinParam testpin_1;
|
||||
struct PinStat testpin_1_stat;
|
||||
struct PinParam testpin_2;
|
||||
|
||||
struct BusConfigureInfo configure_info_1;
|
||||
struct BusConfigureInfo configure_info_2;
|
||||
struct BusBlockWriteParam write_param_1;
|
||||
|
||||
configure_info_1.configure_cmd = OPE_CFG;
|
||||
configure_info_1.private_data = (void *)&testpin_1;
|
||||
write_param_1.buffer = (void *)&testpin_1_stat;
|
||||
|
||||
configure_info_2.configure_cmd = OPE_CFG;
|
||||
configure_info_2.private_data = (void *)&testpin_2;
|
||||
|
||||
KPrintf("%s irq test\n",__func__);
|
||||
/* config GPIO18 as output and set as low */
|
||||
testpin_1.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_1.pin = GPIO_18;
|
||||
testpin_1.mode = GPIO_CFG_OUTPUT;
|
||||
BusDrvConfigure(pin->owner_driver, &configure_info_1);
|
||||
|
||||
testpin_1_stat.pin = GPIO_18;
|
||||
testpin_1_stat.val = GPIO_LOW;
|
||||
BusDevWriteData(pin->owner_haldev, &write_param_1);
|
||||
|
||||
/* config GPIO18 as input */
|
||||
testpin_2.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_2.pin = GPIO_19;
|
||||
testpin_2.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(pin->owner_driver, &configure_info_2);
|
||||
|
||||
testpin_2.cmd = GPIO_IRQ_REGISTER;
|
||||
testpin_2.pin = GPIO_19;
|
||||
testpin_2.irq_set.irq_mode = GPIO_IRQ_EDGE_RISING;
|
||||
testpin_2.irq_set.hdr = PinIrqIsr;
|
||||
testpin_2.irq_set.args = NONE;
|
||||
BusDrvConfigure(pin->owner_driver, &configure_info_2);
|
||||
|
||||
testpin_2.cmd = GPIO_IRQ_ENABLE;
|
||||
testpin_2.pin = GPIO_19;
|
||||
BusDrvConfigure(pin->owner_driver, &configure_info_2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RealtimeTaskSwitchTest()
|
||||
{
|
||||
struct PinParam testpin_1;
|
||||
struct PinStat testpin_1_stat;
|
||||
|
||||
struct BusConfigureInfo configure_info_1;
|
||||
struct BusBlockWriteParam write_param_1;
|
||||
|
||||
configure_info_1.configure_cmd = OPE_CFG;
|
||||
configure_info_1.private_data = (void *)&testpin_1;
|
||||
write_param_1.buffer = (void *)&testpin_1_stat;
|
||||
|
||||
testpin_1.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_1.pin = GPIO_18;
|
||||
testpin_1.mode = GPIO_CFG_OUTPUT;
|
||||
BusDrvConfigure(pin->owner_driver, &configure_info_1);
|
||||
|
||||
testpin_1_stat.pin = GPIO_18;
|
||||
testpin_1_stat.val = GPIO_LOW;
|
||||
BusDevWriteData(pin->owner_haldev, &write_param_1);
|
||||
|
||||
while (RET_TRUE) {
|
||||
DelayKTask(10);
|
||||
}
|
||||
}
|
||||
|
||||
void GpioSpeedTest()
|
||||
{
|
||||
struct PinParam testpin_1;
|
||||
struct PinStat testpin_1_stat;
|
||||
|
||||
struct BusConfigureInfo configure_info_1;
|
||||
struct BusBlockWriteParam write_param_1;
|
||||
|
||||
configure_info_1.configure_cmd = OPE_CFG;
|
||||
configure_info_1.private_data = (void *)&testpin_1;
|
||||
write_param_1.buffer = (void *)&testpin_1_stat;
|
||||
|
||||
testpin_1.cmd = GPIO_CONFIG_MODE;
|
||||
testpin_1.pin = GPIO_18;
|
||||
testpin_1.mode = GPIO_CFG_OUTPUT;
|
||||
BusDrvConfigure(pin->owner_driver, &configure_info_1);
|
||||
|
||||
testpin_1_stat.pin = GPIO_18;
|
||||
testpin_1_stat.val = GPIO_LOW;
|
||||
BusDevWriteData(pin->owner_haldev, &write_param_1);
|
||||
|
||||
while (RET_TRUE) {
|
||||
*(volatile unsigned int *)0x3800100c |= 0x5;
|
||||
*(volatile unsigned int *)0x3800100c &= ~0x5;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************************************************************/
|
||||
static void UsageHelp(void)
|
||||
{
|
||||
KPrintf("TestRealtime.\n");
|
||||
}
|
||||
|
||||
int TestRealtime(int argc, char * argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
struct BusConfigureInfo configure_info;
|
||||
|
||||
if (NONE == argv || 0 == strncmp("-h", argv[0], strlen("-h")) || 0 == strncmp("usage", argv[0], strlen("usage"))) {
|
||||
UsageHelp();
|
||||
return -EINVALED;
|
||||
}
|
||||
|
||||
pin = BusFind(PIN_BUS_NAME);
|
||||
if (!pin) {
|
||||
KPrintf("find %s failed!\n", PIN_BUS_NAME);
|
||||
return -ERROR;
|
||||
}
|
||||
|
||||
pin->owner_driver = BusFindDriver(pin, PIN_DRIVER_NAME);
|
||||
pin->owner_haldev = BusFindDevice(pin, PIN_DEVICE_NAME);
|
||||
|
||||
configure_info.configure_cmd = OPE_INT;
|
||||
ret = BusDrvConfigure(pin->owner_driver, &configure_info);
|
||||
if (ret != EOK) {
|
||||
KPrintf("initialize %s failed!\n", PIN_BUS_NAME);
|
||||
return -ERROR;
|
||||
}
|
||||
|
||||
if (0 == strncmp("-irq",argv[0],strlen("-irq")) ) {
|
||||
RealtimeIrqTest(); ///< static creat single sem test
|
||||
}
|
||||
|
||||
if (0 == strncmp("-task",argv[0],strlen("-task")) ) {
|
||||
RealtimeTaskSwitchTest();
|
||||
}
|
||||
|
||||
if (0 == strncmp("-gpio",argv[0],strlen("-gpio")) ) {
|
||||
GpioSpeedTest();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
65
kernel/kernel_test/test_rtc.c
Normal file
65
kernel/kernel_test/test_rtc.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file TestRtc.c
|
||||
* @brief support to test rtc function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <device.h>
|
||||
|
||||
#ifdef RESOURCES_RTC
|
||||
|
||||
static int TestRtc(int argc, char *argv[])
|
||||
{
|
||||
time_t now;
|
||||
|
||||
struct RtcSetParam rtc_set_param;
|
||||
|
||||
KPrintf("TestRtc cmd %s\n", argv[1]);
|
||||
|
||||
if (0 == strcmp("-s", argv[1])) {
|
||||
rtc_set_param.rtc_set_cmd = OPER_RTC_SET_TIME;
|
||||
rtc_set_param.date_param.year = 2021;
|
||||
rtc_set_param.date_param.month = 4;
|
||||
rtc_set_param.date_param.day = 6;
|
||||
rtc_set_param.time_param.hour = 16;
|
||||
rtc_set_param.time_param.minute = 0;
|
||||
rtc_set_param.time_param.second = 0;
|
||||
|
||||
RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
|
||||
|
||||
rtc_set_param.rtc_set_cmd = OPER_RTC_GET_TIME;
|
||||
rtc_set_param.time = &now;
|
||||
|
||||
RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
|
||||
|
||||
KPrintf("%s\n", ctime(&now));
|
||||
} else if (0 == strcmp("-g", argv[1])) {
|
||||
rtc_set_param.rtc_set_cmd = OPER_RTC_GET_TIME;
|
||||
rtc_set_param.time = &now;
|
||||
|
||||
RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
|
||||
|
||||
KPrintf("%s\n", ctime(&now));
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4),
|
||||
TestRtc, TestRtc, Test the RTC Function);
|
||||
|
||||
#endif
|
||||
199
kernel/kernel_test/test_serial.c
Normal file
199
kernel/kernel_test/test_serial.c
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_serial.c
|
||||
* @brief support to test serial function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <device.h>
|
||||
#if defined (ARCH_RISCV)
|
||||
#include <connect_uart.h>
|
||||
#elif defined(ARCH_ARM)
|
||||
#include <connect_usart.h>
|
||||
#endif
|
||||
|
||||
//#define TEST_POSIX
|
||||
|
||||
#ifdef TEST_POSIX
|
||||
#include "user_api.h"
|
||||
#endif
|
||||
|
||||
#ifdef RESOURCES_SERIAL
|
||||
|
||||
static char test_str[] = "Hello AIIT!\r\n";
|
||||
|
||||
struct Bus *bus = NONE;
|
||||
struct Driver *bus_driver = NONE;
|
||||
struct HardwareDev *bus_device = NONE;
|
||||
|
||||
#ifdef TEST_POSIX
|
||||
static int uart3_fd = 0;
|
||||
#endif
|
||||
static int32 test_serial_task = 0;
|
||||
|
||||
static void TestSerialRecvTask(void *parameter)
|
||||
{
|
||||
int16 i = 0;
|
||||
char recv_data = 0;
|
||||
#ifdef TEST_POSIX
|
||||
char data_buffer[128] = {0};
|
||||
char data_size = 0;
|
||||
#endif
|
||||
struct BusBlockReadParam read_param;
|
||||
struct BusBlockWriteParam write_param;
|
||||
memset(&read_param, 0, sizeof(struct BusBlockReadParam));
|
||||
memset(&write_param, 0, sizeof(struct BusBlockWriteParam));
|
||||
|
||||
|
||||
|
||||
while(RET_TRUE) {
|
||||
#ifndef TEST_POSIX
|
||||
read_param.size = 1;
|
||||
read_param.buffer = &recv_data;
|
||||
read_param.read_length = 0;
|
||||
|
||||
BusDevReadData(bus_device, &read_param);
|
||||
for (i = 0; i < read_param.read_length; i ++) {
|
||||
KPrintf("TestSerialRecvTask i %d char 0x%x\n", i, recv_data);
|
||||
}
|
||||
|
||||
write_param.buffer = &recv_data;
|
||||
write_param.size = 1;
|
||||
BusDevWriteData(bus_device, &write_param);
|
||||
#else
|
||||
memset(data_buffer, 0, 128);
|
||||
data_size = read(uart3_fd, data_buffer, 128);
|
||||
KPrintf("uart 3 data size %d data %s\n", data_size, data_buffer);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static int SerialBusCheck(const char *bus_name, const char *driver_name, const char *device_name)
|
||||
{
|
||||
int ret = EOK;
|
||||
#ifndef TEST_POSIX
|
||||
struct SerialBus *serial_bus = NONE;
|
||||
struct SerialDriver *serial_driver = NONE;
|
||||
struct SerialHardwareDevice *serial_device = NONE;
|
||||
struct SerialCfgParam *serial_cfg_default = NONE;
|
||||
struct SerialDevParam *serial_dev_param = NONE;
|
||||
|
||||
struct BusConfigureInfo configure_info;
|
||||
|
||||
if(bus_name)
|
||||
{
|
||||
KPrintf("####test find bus %s\n", bus_name);
|
||||
bus = BusFind(bus_name);
|
||||
serial_bus = (struct SerialBus *)bus;
|
||||
KPrintf("####test find bus %8p serial_bus %8p\n", bus, serial_bus);
|
||||
}
|
||||
|
||||
if(driver_name)
|
||||
{
|
||||
KPrintf("####test find driver %s\n", driver_name);
|
||||
bus_driver = BusFindDriver(bus, driver_name);
|
||||
serial_driver = (struct SerialDriver *)bus_driver;
|
||||
serial_cfg_default = (struct SerialCfgParam *)serial_driver->private_data;
|
||||
KPrintf("####test bus_driver %8p serial_driver %8p done %8p serial_cfg_default %8p####\n",
|
||||
bus_driver, serial_driver, serial_driver->drv_done, serial_cfg_default);
|
||||
KPrintf("####hw cfg base 0x%x irq %d####\n", serial_cfg_default->hw_cfg.serial_register_base, serial_cfg_default->hw_cfg.serial_irq_interrupt);
|
||||
KPrintf("####data cfg rate %u order %u size %u bits %u invert %u parity %u stop %u####\n", serial_cfg_default->data_cfg.serial_baud_rate, serial_cfg_default->data_cfg.serial_bit_order, serial_cfg_default->data_cfg.serial_buffer_size,
|
||||
serial_cfg_default->data_cfg.serial_data_bits, serial_cfg_default->data_cfg.serial_invert_mode, serial_cfg_default->data_cfg.serial_parity_mode, serial_cfg_default->data_cfg.serial_stop_bits);
|
||||
}
|
||||
|
||||
if(device_name)
|
||||
{
|
||||
KPrintf("####test find device0 %s\n", device_name);
|
||||
bus_device = BusFindDevice(bus, device_name);
|
||||
serial_device = (struct SerialHardwareDevice *)bus_device;
|
||||
serial_dev_param = (struct SerialDevParam *)bus_device->private_data;
|
||||
KPrintf("####test bus_device %8p serial_dev %8p hwdone %8p devdone %8p####\n",
|
||||
bus_device, serial_device, serial_device->hwdev_done, serial_device->haldev.dev_done);
|
||||
KPrintf("####dev_param %8p work mode 0x%x set mode 0x%x stream mode 0x%x\n",
|
||||
serial_dev_param, serial_dev_param->serial_work_mode, serial_dev_param->serial_set_mode, serial_dev_param->serial_stream_mode);
|
||||
}
|
||||
|
||||
//BusDevRecvCallback(bus_device, test_serial_callback);
|
||||
|
||||
/*step 1: init bus_driver, change struct SerialCfgParam if necessary*/
|
||||
struct SerialCfgParam serial_cfg;
|
||||
memset(&serial_cfg, 0, sizeof(struct SerialCfgParam));
|
||||
configure_info.configure_cmd = OPE_INT;
|
||||
configure_info.private_data = &serial_cfg;
|
||||
BusDrvConfigure(bus_driver, &configure_info);
|
||||
KPrintf("BusDrvConfigure OPE_INT done\n");
|
||||
|
||||
/*step 2: match bus_driver with bus_device*/
|
||||
bus->match(bus_driver, bus_device);
|
||||
|
||||
/*step 3: open bus_device, configure struct SerialDevParam if necessary*/
|
||||
serial_dev_param->serial_set_mode = SIGN_OPER_INT_RX;
|
||||
serial_dev_param->serial_stream_mode = SIGN_OPER_STREAM;
|
||||
BusDevOpen(bus_device);
|
||||
KPrintf("BusDevOpen done\n");
|
||||
|
||||
/*step 4: write serial data, configure struct BusBlockWriteParam*/
|
||||
struct BusBlockWriteParam write_param;
|
||||
write_param.pos = 0;
|
||||
write_param.buffer = (void *)test_str;
|
||||
write_param.size = sizeof(test_str) - 1;
|
||||
BusDevWriteData(bus_device, &write_param);
|
||||
|
||||
//BusDevClose(bus_device);
|
||||
//KPrintf("BusDevClose done\n");
|
||||
#else
|
||||
uart3_fd = open("/dev/uart3_dev3", O_RDWR);
|
||||
if (uart3_fd < 0) {
|
||||
KPrintf("open fd error %d\n", uart3_fd);
|
||||
}
|
||||
KPrintf("open fd %d\n", uart3_fd);
|
||||
|
||||
struct SerialDataCfg cfg;
|
||||
cfg.serial_baud_rate = BAUD_RATE_115200;
|
||||
cfg.serial_data_bits = DATA_BITS_8;
|
||||
cfg.serial_stop_bits = STOP_BITS_1;
|
||||
cfg.serial_buffer_size = 128;
|
||||
cfg.serial_parity_mode = PARITY_NONE;
|
||||
cfg.serial_bit_order = 0;
|
||||
cfg.serial_invert_mode = 0;
|
||||
cfg.ext_uart_no = 0;
|
||||
cfg.port_configure = 0;
|
||||
|
||||
if (ret != ioctl(uart3_fd, OPE_INT, &cfg)) {
|
||||
KPrintf("ioctl fd error %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int TestSerial(void)
|
||||
{
|
||||
/*use serial device 3 to test serial function*/
|
||||
SerialBusCheck(SERIAL_BUS_NAME_3, SERIAL_DRV_NAME_3, SERIAL_3_DEVICE_NAME_0);
|
||||
|
||||
test_serial_task = KTaskCreate("TestSerialRecvTask",
|
||||
TestSerialRecvTask,
|
||||
NONE,
|
||||
2048,
|
||||
18);
|
||||
StartupKTask(test_serial_task);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
TestSerial, TestSerial, TestSerial );
|
||||
|
||||
#endif
|
||||
199
kernel/kernel_test/test_threadsched.c
Normal file
199
kernel/kernel_test/test_threadsched.c
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_threadsched.c
|
||||
* @brief support to test thread sched function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <string.h>
|
||||
#include <xs_assign.h>
|
||||
|
||||
extern long ShowTask(void);
|
||||
extern unsigned int msleep(uint64_t msec);
|
||||
|
||||
static int32 tid1 = NONE;
|
||||
static int32 tid2 = NONE;
|
||||
static int32 tid3 = NONE;
|
||||
static int32 tid4 = NONE;
|
||||
static int32 tid5 = NONE;
|
||||
|
||||
#define DYNAMIC_TASK_STACK_SIZE 3072
|
||||
#define PRIORITY 15
|
||||
static void Task1Entry(void *parameter)
|
||||
{
|
||||
int cnt = 10;
|
||||
DoubleLinklistType* node = NONE;
|
||||
DoubleLinklistType* head = NONE;
|
||||
struct TaskDescriptor *obj = NONE;
|
||||
TaskDyncSchedMembeType *tmp = NONE;
|
||||
register x_base level;
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
if (0 == strncmp(parameter,"-b",strlen("-b"))) { ///< if tasks bind to cpu 0
|
||||
head = &(Assign.smp_os_assign_ready_rector[0].priority_ready_vector[PRIORITY]);
|
||||
} else {
|
||||
head = &(Assign.os_assign_read_vector.priority_ready_vector[PRIORITY]);
|
||||
}
|
||||
#else
|
||||
head = &(Assign.os_assign_read_vector.priority_ready_vector[PRIORITY]);
|
||||
#endif
|
||||
while(cnt--) {
|
||||
#ifdef TOOL_SHELL
|
||||
ShowTask();
|
||||
#endif
|
||||
KPrintf("\n");
|
||||
|
||||
DOUBLE_LINKLIST_FOR_EACH(node, head) {
|
||||
tmp = SYS_DOUBLE_LINKLIST_ENTRY(node, struct TaskDyncSchedMember, sched_link);
|
||||
obj =CONTAINER_OF(tmp,struct TaskDescriptor, task_dync_sched_member);
|
||||
KPrintf("task ready table node name = %s node remaining_tick= %d node advance_cnt =%d\n",obj->task_base_info.name,
|
||||
obj->task_dync_sched_member.rest_timeslice, obj->task_dync_sched_member.advance_cnt);
|
||||
}
|
||||
#ifdef ARCH_SMP
|
||||
#ifdef SCHED_POLICY_FIFO
|
||||
MdelayKTask(30);
|
||||
#else
|
||||
msleep(30);
|
||||
#endif
|
||||
#else
|
||||
#ifdef ARCH_ARM
|
||||
MdelayKTask(3);
|
||||
#else
|
||||
MdelayKTask(80);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
KTaskDelete(tid2);
|
||||
KTaskDelete(tid3);
|
||||
KTaskDelete(tid4);
|
||||
KTaskDelete(tid5);
|
||||
|
||||
}
|
||||
|
||||
static void Task2Entry(void *parameter)
|
||||
{
|
||||
int i = 0;
|
||||
while(RET_TRUE) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
static void Task3Entry(void *parameter)
|
||||
{
|
||||
int i = 0;
|
||||
while(RET_TRUE) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
static void Task4Entry(void *parameter)
|
||||
{
|
||||
int i = 0;
|
||||
while(RET_TRUE) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
static void Task5Entry(void *parameter)
|
||||
{
|
||||
int i = 0;
|
||||
while(RET_TRUE) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTaskSchedTest(char* parm)
|
||||
{
|
||||
char t_parm[4];
|
||||
#ifdef ARCH_SMP
|
||||
if (0 == strncmp("-b", parm, strlen("-b")) || 0 == strncmp("-bind", parm, strlen("-bind"))){
|
||||
strncpy(t_parm,"-b", 4);
|
||||
}
|
||||
#endif
|
||||
tid1 = KTaskCreate("d_tid1",
|
||||
Task1Entry,
|
||||
t_parm,
|
||||
DYNAMIC_TASK_STACK_SIZE,
|
||||
16);
|
||||
if (tid1 >= 0)
|
||||
StartupKTask(tid1);
|
||||
|
||||
tid2 = KTaskCreate("d_tid2",
|
||||
Task2Entry,
|
||||
"d_tid2",
|
||||
1024,
|
||||
15);
|
||||
#ifdef ARCH_SMP
|
||||
if (0 == strncmp("-b", parm, strlen("-b")) || 0 == strncmp("-bind", parm, strlen("-bind"))){
|
||||
KTaskCoreCombine(tid2, 0);
|
||||
}
|
||||
#endif
|
||||
if (tid2 >= 0)
|
||||
StartupKTask(tid2);
|
||||
|
||||
tid3 = KTaskCreate("d_tid3",
|
||||
Task3Entry,
|
||||
"d_tid3",
|
||||
1024,
|
||||
15);
|
||||
#ifdef ARCH_SMP
|
||||
if (0 == strncmp("-b", parm, strlen("-b")) || 0 == strncmp("-bind", parm, strlen("-bind"))){
|
||||
KTaskCoreCombine(tid3, 0);
|
||||
}
|
||||
#endif
|
||||
if (tid3 >= 0)
|
||||
StartupKTask(tid3);
|
||||
|
||||
tid4 = KTaskCreate("d_tid4",
|
||||
Task4Entry,
|
||||
"d_tid4",
|
||||
1024,
|
||||
15);
|
||||
#ifdef ARCH_SMP
|
||||
if (0 == strncmp("-b", parm, strlen("-b")) || 0 == strncmp("-bind", parm, strlen("-bind"))){
|
||||
KTaskCoreCombine(tid4, 0);
|
||||
}
|
||||
#endif
|
||||
if (tid4 >= 0)
|
||||
StartupKTask(tid4);
|
||||
|
||||
tid5 = KTaskCreate("d_tid5",
|
||||
Task5Entry,
|
||||
"d_tid5",
|
||||
1024,
|
||||
15);
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
if (0 == strncmp("-b", parm, strlen("-b")) || 0 == strncmp("-bind", parm, strlen("-bind"))){
|
||||
KTaskCoreCombine(tid5, 0);
|
||||
}
|
||||
#endif
|
||||
if (tid5 >= 0)
|
||||
StartupKTask(tid5);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
static void UsageHelp(void)
|
||||
{
|
||||
KPrintf("test_task_ready_usage.\n");
|
||||
}
|
||||
|
||||
int TestTaskReadyAndSched(int argc, char * argv[])
|
||||
{
|
||||
DynamicTaskSchedTest(argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
116
kernel/kernel_test/test_timer.c
Normal file
116
kernel/kernel_test/test_timer.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_timer.c
|
||||
* @brief support to test timer function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
|
||||
extern long ShowTimer(void);
|
||||
/*****************************************************************************************************************/
|
||||
/***********************************test create timer with dynamic style *****************************************/
|
||||
|
||||
|
||||
static int32 dynamic_timer1;
|
||||
static int32 dynamic_timer2;
|
||||
static int dynamic_cnt = 0;
|
||||
|
||||
|
||||
static void DynamicTimeout1Entry(void *parameter)
|
||||
{
|
||||
KPrintf("periodic timer is timeout %d\n", dynamic_cnt);
|
||||
if (dynamic_cnt++>= 9){
|
||||
KTimerQuitRun(dynamic_timer1);
|
||||
KPrintf("periodic timer was stopped! \n");
|
||||
}
|
||||
}
|
||||
|
||||
static void DynamicTimeout2Entry(void *parameter)
|
||||
{
|
||||
KPrintf("one shot timer is timeout\n");
|
||||
}
|
||||
|
||||
int TestDynamicTimer(void)
|
||||
{
|
||||
dynamic_timer1 = KCreateTimer("d_tmr1", DynamicTimeout1Entry,
|
||||
NONE, 10,
|
||||
TIMER_TRIGGER_PERIODIC);
|
||||
|
||||
if (dynamic_timer1 != NONE) KTimerStartRun(dynamic_timer1);
|
||||
|
||||
dynamic_timer2 = KCreateTimer("d_tmr2", DynamicTimeout2Entry,
|
||||
NONE, 30,
|
||||
TIMER_TRIGGER_ONCE);
|
||||
|
||||
if (dynamic_timer2 != NONE) KTimerStartRun(dynamic_timer2);
|
||||
ShowTimer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestTmrD(void)
|
||||
{
|
||||
KPrintf("test dynamic timer\n");
|
||||
TestDynamicTimer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************test mixed timers with dynamic and static style **********************************/
|
||||
static int32 mixed_timer_d;
|
||||
static int32 test_delete_timer;
|
||||
|
||||
static int num = 0;
|
||||
|
||||
|
||||
static void MexedTimeout2Entry(void *parameter)
|
||||
{
|
||||
KPrintf("mixed\n");
|
||||
KTimerQuitRun(mixed_timer_d);
|
||||
}
|
||||
|
||||
int TimerMix(void)
|
||||
{
|
||||
mixed_timer_d = KCreateTimer("mix_t2", MexedTimeout2Entry, NONE, 30, TIMER_TRIGGER_ONCE);
|
||||
|
||||
if (mixed_timer_d != NONE) KTimerStartRun(mixed_timer_d);
|
||||
|
||||
test_delete_timer = KCreateTimer("del_t3", MexedTimeout2Entry, NONE, 30, TIMER_TRIGGER_ONCE);
|
||||
ShowTimer();
|
||||
if(test_delete_timer != NONE)
|
||||
KDeleteTimer(test_delete_timer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestTmrM(void)
|
||||
{
|
||||
KPrintf("test mixed timer\n");
|
||||
TimerMix();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestTmr(int argc, char*argv[]) {
|
||||
|
||||
KPrintf("/******************************************** START **************************************************/\n");
|
||||
TestTmrD();
|
||||
MdelayKTask(4000);
|
||||
KPrintf("/******************************************* boundary ************************************************/\n");
|
||||
TestTmrM();
|
||||
MdelayKTask(4000);
|
||||
KPrintf("/********************************************* END **************************************************/\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
81
kernel/kernel_test/test_touch.c
Normal file
81
kernel/kernel_test/test_touch.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_touch.c
|
||||
* @brief support to test touch function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include "bus_touch.h"
|
||||
#include "dev_touch.h"
|
||||
|
||||
int TestTouch(const char *bus_name, const char *driver_name, const char *device_name0)
|
||||
{
|
||||
struct Bus *bus;
|
||||
struct Driver *driver, *bus_driver;
|
||||
struct HardwareDev *device0;
|
||||
struct HardwareDev *bus_device0;
|
||||
struct TouchDataStandard datacfg;
|
||||
|
||||
struct TouchDataStandard data ={0,0};
|
||||
|
||||
struct BusConfigureInfo configure_info = {0,&data};
|
||||
|
||||
struct BusBlockReadParam read_param;
|
||||
memset(&read_param,0,sizeof(struct BusBlockReadParam ));
|
||||
|
||||
read_param.buffer = &data;
|
||||
|
||||
if(bus_name)
|
||||
{
|
||||
KPrintf("##test find bus %s\n", bus_name);
|
||||
bus = BusFind(bus_name);
|
||||
KPrintf("##test bus %p####\n", bus);
|
||||
}
|
||||
|
||||
if(driver_name)
|
||||
{
|
||||
KPrintf("##test find driver %s\n", driver_name);
|
||||
driver = TouchDriverFind(driver_name, TYPE_TOUCH_DRV);
|
||||
bus_driver = BusFindDriver(bus, driver_name);
|
||||
KPrintf("##test driver %p bus_driver %p##\n", driver, bus_driver);
|
||||
}
|
||||
|
||||
if(device_name0)
|
||||
{
|
||||
KPrintf("##test find device0 %s\n", device_name0);
|
||||
device0 = TouchDeviceFind(device_name0, TYPE_TOUCH_DEV);
|
||||
KPrintf("device0 :%p\n", device0);
|
||||
bus_device0 = BusFindDevice(bus, device_name0);
|
||||
KPrintf("bus_device0 :%p\n", bus_device0);
|
||||
}
|
||||
KPrintf("ttt\n");
|
||||
BusDrvConfigure(bus_driver, &configure_info);
|
||||
KPrintf("yyy\n");
|
||||
while(1)
|
||||
{
|
||||
BusDevReadData(bus_device0,&read_param);
|
||||
KPrintf("dev.x= %8d *** dev.y= %8d \r\n",data.x,data.y);
|
||||
MdelayKTask(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TouchTest(void)
|
||||
{
|
||||
TestTouch(TOUCH_BUS_NAME_1,TOUCH_DRV_NAME_1, TOUCH_1_DEVICE_NAME_0);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),TouchTest, TouchTest, Close AC task );
|
||||
237
kernel/kernel_test/user_api.h
Normal file
237
kernel/kernel_test/user_api.h
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file user_api.h
|
||||
* @brief define user api function and struct
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#ifndef __XS_USER_API_H__
|
||||
#define __XS_USER_API_H__
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <iot-vfs_posix.h>
|
||||
|
||||
#ifdef SEPARATE_COMPILE
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <kswitch.h>
|
||||
#if defined(FS_VFS)
|
||||
#include <iot-vfs.h>
|
||||
#ifndef TASK_ISOLATION
|
||||
#include <iot-vfs_posix.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <xs_service.h>
|
||||
|
||||
#define TASK_INFO 1
|
||||
#define MEM_INFO 2
|
||||
#define SEM_INFO 3
|
||||
#define EVENT_INFO 4
|
||||
#define MUTEX_INFO 5
|
||||
#define MEMPOOL_INFO 6
|
||||
#define MSGQUEUE_INFO 7
|
||||
#define DEVICE_INFO 8
|
||||
#define TIMER_INFO 9
|
||||
|
||||
int UserPrintInfo(unsigned long i);
|
||||
|
||||
struct utask
|
||||
{
|
||||
char name[NAME_NUM_MAX];
|
||||
void *func_entry;
|
||||
void *func_param;
|
||||
uint32 stack_size;
|
||||
uint8 prio;
|
||||
};
|
||||
typedef struct utask utask_x;
|
||||
|
||||
typedef void DIR;
|
||||
|
||||
int32 UserTaskCreate(utask_x utask);
|
||||
|
||||
x_err_t UserTaskStartup(int32 id);
|
||||
x_err_t UserTaskDelete(int32 id);
|
||||
void UserTaskQuit(void);
|
||||
x_err_t UserTaskDelay(int32 ms);
|
||||
x_err_t UserGetTaskName(int32 id ,char *name);
|
||||
int32 UserGetTaskID(void);
|
||||
uint8 UserGetTaskStat(int32 id);
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
x_err_t UserTaskCoreCombine(int32 id,uint8 core_id);
|
||||
x_err_t UserTaskCoreUnCombine(int32 id);
|
||||
uint8 UserGetTaskCombinedCore(int32 id);
|
||||
uint8 UserGetTaskRunningCore(int32 id);
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32 id);
|
||||
uint8 UserGetTaskPriority(int32 id);
|
||||
|
||||
|
||||
void *UserMalloc(x_size_t size);
|
||||
void *UserRealloc(void *pointer, x_size_t size);
|
||||
void *UserCalloc(x_size_t count, x_size_t size);
|
||||
void UserFree(void *pointer);
|
||||
|
||||
#ifdef KERNEL_MUTEX
|
||||
int32 UserMutexCreate();
|
||||
void UserMutexDelete(int32 mutex);
|
||||
int32 UserMutexObtain(int32 mutex, int32 wait_time);
|
||||
int32 UserMutexAbandon(int32 mutex);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_SEMAPHORE
|
||||
typedef int32 sem_t;
|
||||
sem_t UserSemaphoreCreate(uint16 val);
|
||||
x_err_t UserSemaphoreDelete(sem_t sem);
|
||||
x_err_t UserSemaphoreObtain(sem_t sem, int32 wait_time);
|
||||
x_err_t UserSemaphoreAbandon(sem_t sem);
|
||||
x_err_t UserSemaphoreSetValue(sem_t sem, uint16 val);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_EVENT
|
||||
EventIdType UserEventCreate(uint8 flag);
|
||||
void UserEventDelete(EventIdType event);
|
||||
x_err_t UserEventTrigger(EventIdType event, uint32 set);
|
||||
x_err_t UserEventProcess(EventIdType event, uint32 set, uint8 option,
|
||||
int32 wait_time, uint32 *Recved);
|
||||
x_err_t UserEventReinit(EventIdType event);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_MESSAGEQUEUE
|
||||
int32 UserMsgQueueCreate(x_size_t msg_size, x_size_t max_msgs);
|
||||
x_err_t UserMsgQueueDelete(int32 mq );
|
||||
x_err_t UserMsgQueueSendwait(int32 mq, const void *buffer,
|
||||
x_size_t size, int32 wait_time);
|
||||
x_err_t UserMsgQueueSend(int32 mq, const void *buffer, x_size_t size);
|
||||
x_err_t UserMsgQueueUrgentSend(int32 mq, const void *buffer, x_size_t size);
|
||||
x_err_t UserMsgQueueRecv(int32 mq, void *buffer, x_size_t size,int32 wait_time);
|
||||
x_err_t UserMsgQueueReinit(int32 mq);
|
||||
#endif
|
||||
|
||||
int open(const char *path, int flags, ...);
|
||||
int read(int fd, void *buf, size_t len);
|
||||
int write(int fd, const void *buf, size_t len);
|
||||
int close(int fd);
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
int rename(const char *from, const char *to);
|
||||
int unlink(const char *path);
|
||||
int stat(const char *path, struct stat *buf);
|
||||
int fstat(int fd, struct stat *buf);
|
||||
int fsync(int fd);
|
||||
int ftruncate(int fd, off_t length);
|
||||
|
||||
int mkdir(const char *path, mode_t mode);
|
||||
DIR *opendir(const char *path);
|
||||
int closedir(DIR *dirp);
|
||||
struct dirent *readdir(DIR *dirp);
|
||||
int rmdir(const char *path);
|
||||
int chdir(const char *path);
|
||||
char *getcwd(char *buf, size_t size);
|
||||
long telldir(DIR *dirp);
|
||||
void seekdir(DIR *dirp, off_t offset);
|
||||
void rewinddir(DIR *dirp);
|
||||
|
||||
#ifdef FS_VFS
|
||||
struct statfs {
|
||||
size_t f_bsize;
|
||||
size_t f_blocks;
|
||||
size_t f_bfree;
|
||||
};
|
||||
|
||||
int statfs(const char *path, struct statfs *buf);
|
||||
#endif
|
||||
|
||||
void UserPrintf(const char *fmt, ...);
|
||||
|
||||
#else
|
||||
struct utask
|
||||
{
|
||||
char name[NAME_NUM_MAX];
|
||||
void *func_entry;
|
||||
void *func_param;
|
||||
int32_t stack_size;
|
||||
uint8_t prio;
|
||||
};
|
||||
typedef struct utask utask_x;
|
||||
int32_t UserTaskCreate(utask_x utask);
|
||||
|
||||
#define UserTaskStartup StartupKTask
|
||||
#define UserTaskDelete KTaskDelete
|
||||
#define UserTaskQuit KTaskQuit
|
||||
#define UserTaskDelay MdelayKTask
|
||||
|
||||
x_err_t UserGetTaskName(int32_t id ,char *name);
|
||||
int32_t UserGetTaskID(void);
|
||||
uint8_t UserGetTaskStat(int32_t id);
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
#define UserTaskCoreCombine KTaskCoreCombine
|
||||
#define UserTaskCoreUnCombine KTaskCoreUnCombine
|
||||
|
||||
uint8_t UserGetTaskCombinedCore(int32_t id);
|
||||
uint8_t UserGetTaskRunningCore(int32_t id);
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32_t id);
|
||||
uint8_t UserGetTaskPriority(int32_t id);
|
||||
|
||||
#define UserMalloc x_malloc
|
||||
#define UserRealloc x_realloc
|
||||
#define UserCalloc x_calloc
|
||||
#define UserFree x_free
|
||||
|
||||
#ifdef KERNEL_MUTEX
|
||||
#define UserMutexCreate KMutexCreate
|
||||
#define UserMutexDelete KMutexDelete
|
||||
#define UserMutexObtain KMutexObtain
|
||||
#define UserMutexAbandon KMutexAbandon
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_SEMAPHORE
|
||||
#define UserSemaphoreCreate KSemaphoreCreate
|
||||
#define UserSemaphoreDelete KSemaphoreDelete
|
||||
#define UserSemaphoreObtain KSemaphoreObtain
|
||||
#define UserSemaphoreAbandon KSemaphoreAbandon
|
||||
#define UserSemaphoreSetValue KSemaphoreSetValue
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL_EVENT
|
||||
#define UserEventCreate KEventCreate
|
||||
#define UserEventDelete KEventDelete
|
||||
#define UserEventTrigger KEventTrigger
|
||||
#define UserEventProcess KEventProcess
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL_MESSAGEQUEUE
|
||||
#define UserMsgQueueCreate KCreateMsgQueue
|
||||
#define UserMsgQueueDelete KDeleteMsgQueue
|
||||
#define UserMsgQueueSendwait KMsgQueueSendwait
|
||||
#define UserMsgQueueSend KMsgQueueSend
|
||||
#define UserMsgQueueUrgentSend KMsgQueueUrgentSend
|
||||
#define UserMsgQueueRecv KMsgQueueRecv
|
||||
#define UserMsgQueueReinit KMsgQueueReinit
|
||||
#endif
|
||||
|
||||
#define UserPrintf KPrintf
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user