feat support PRIV_SHELL_CMD_FUNCTION to fit heterogeneous OS

This commit is contained in:
Liu_Weichao
2022-09-26 17:04:04 +08:00
parent fd69c3d400
commit dbca22a1a6
64 changed files with 916 additions and 893 deletions

View File

@@ -4,10 +4,6 @@ menu "test app"
default n
if USER_TEST
config USER_TEST_SPI_FLASH
bool "Config test spi flash"
default n
menuconfig USER_TEST_ADC
bool "Config test adc"
default n

View File

@@ -1,8 +1,4 @@
SRC_FILES :=
ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y)
SRC_FILES += test_spi_flash.c
endif
SRC_FILES := test_shell.c
ifeq ($(CONFIG_USER_TEST_ADC),y)
SRC_FILES += test_adc.c

View File

@@ -0,0 +1,11 @@
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')
cwd = GetCurrentDir()
DEPENDS = [""]
SOURCES = ['test_shell.c']
path = [cwd]
objs = DefineGroup('app_test', src = SOURCES, depend = DEPENDS,CPPPATH = path)
Return("objs")

View File

@@ -22,7 +22,7 @@
#include <string.h>
#include <transform.h>
void test_adc()
void TestAdc(void)
{
int adc_fd;
uint8 adc_channel = 0x0;
@@ -56,6 +56,4 @@ void test_adc()
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
adc, test_adc, read 3.3 voltage data from adc);
PRIV_SHELL_CMD_FUNCTION(TestAdc, a adc test sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@@ -22,7 +22,7 @@
#include <string.h>
#include <transform.h>
void test_dac()
void TestDac(void)
{
int dac_fd;
uint16 dac_set_value = 800;
@@ -56,5 +56,4 @@ void test_dac()
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
test_dac, test_dac, set digital data to dac);
PRIV_SHELL_CMD_FUNCTION(TestDac, a dac test sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@@ -1,11 +1,25 @@
/*
* 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.
*/
#ifdef ADD_XIZI_FETURES
#include <xizi.h>
#endif
/**
* @file: test_extsram.c
* @brief: a extsram test application
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include <stdio.h>
#include <stdint.h>
#include "transform.h"
#include <transform.h>
/* parameters for sram peripheral */
// /* stm32f4 Bank3:0X68000000 */
@@ -22,7 +36,7 @@
#define TICK_PER_SECOND 100
int extsram_test(void)
int ExtsramTest(void)
{
int i = 0;
uint32_t start_time = 0, time_cast = 0;
@@ -89,9 +103,4 @@ int extsram_test(void)
return 0;
}
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
sram_test, sram_test, sram_test);
#endif
PRIV_SHELL_CMD_FUNCTION(ExtsramTest, a extsram test sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@@ -0,0 +1,42 @@
/*
* 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_shell.c
* @brief: a application of shell function
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*/
#include <transform.h>
void TestShellMain(int argc, char *agrv[])
{
printf("%dparameter(s)\r\n", argc);
for (char i = 1; i < argc; i++) {
printf("%s\r\n", agrv[i]);
}
}
PRIV_SHELL_CMD_FUNCTION(TestShellMain, a shell main sample 1, PRIV_SHELL_CMD_MAIN_ATTR);
void TestShellMainVoid(void)
{
printf("XiUOS test_shell_main_void\r\n");
}
PRIV_SHELL_CMD_FUNCTION(TestShellMainVoid, a shell main sample 2, PRIV_SHELL_CMD_MAIN_ATTR);
void TestShellFunc(int i, char ch, char *str)
{
printf("input int: %d, char: %c, string: %s\r\n", i, ch, str);
}
PRIV_SHELL_CMD_FUNCTION(TestShellFunc, a shell func sample, PRIV_SHELL_CMD_FUNC_ATTR);

View File

@@ -1,161 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2016-09-28 armink first version.
*/
/**
* @file test_spi_flash.c
* @brief support to test spi flash function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-17
*/
/*************************************************
File name: test_spi_flash.c
Description: support spi flash function test
Others: add spi flash test cmd from SFUD/blob/master/demo/stm32f2xx_rtt/RT-Thread-2.1.0/components/drivers/spi/spi_flash_sfud.c
https://github.com/armink/SFUD/
History:
1. Date: 2021-05-17
Author: AIIT XUOS Lab
Modification:
1. support spi flash open, read and write function
*************************************************/
#include <xizi.h>
#include <device.h>
#include <flash_spi.h>
#include <user_api.h>
#define SPI_FLASH_PATH "/dev/spi1_W25Q64"
#define FlashDataPrint(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
static int spi_flash_fd;
void FlashOpen(void)
{
x_err_t ret = EOK;
spi_flash_fd = open(SPI_FLASH_PATH, O_RDWR);
if (spi_flash_fd < 0) {
KPrintf("open spi flash fd error %d\n", spi_flash_fd);
}
KPrintf("Spi Flash init succeed\n");
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
FlashOpen, FlashOpen, open spi flash device);
void FlashRead(int argc, char *argv[])
{
x_size_t i, j = 0;
uint32 addr;
uint32 size;
uint8 data[16];
struct BusBlockReadParam read_param;
memset(&read_param, 0, sizeof(struct BusBlockReadParam));
memset(data, 0, 16);
if (3 != argc) {
KPrintf("FlashRead cmd format: FlashRead addr size.\n");
return;
} else {
addr = strtol(argv[1], NULL, 0);
size = strtol(argv[2], NULL, 0);
read_param.buffer = data;
read_param.pos = addr;
read_param.size = size;
if (read_param.buffer) {
read(spi_flash_fd, &read_param, size);
if (size == read_param.read_length) {
KPrintf("Read the %s flash data success. Start from 0x%08X, size is %ld. The data is:\n",
SPI_FLASH_PATH, addr, size);
KPrintf("Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
for (i = 0; i < size; i += 16) {
KPrintf("[%08X] ", addr + i);
/* dump hex */
for (j = 0; j < 16; j++) {
if (i + j < size) {
KPrintf("%02X ", data[i + j]);
} else {
KPrintf(" ");
}
}
/* dump char for hex */
for (j = 0; j < 16; j++) {
if (i + j < size) {
KPrintf("%c", FlashDataPrint(data[i + j]) ? data[i + j] : '.');
}
}
KPrintf("\n");
}
KPrintf("\n");
}
} else {
KPrintf("SpiFlashRead alloc read buffer failed!\n");
}
}
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
FlashRead, FlashRead, read data from spi flash device);
void FlashWrite(int argc, char *argv[])
{
x_err_t ret = EOK;
x_size_t i, j = 0;
uint32 addr;
uint32 size;
uint8 data[16];
struct BusBlockWriteParam write_param;
memset(&write_param, 0, sizeof(struct BusBlockWriteParam));
memset(data, 0, 16);
if (argc < 3) {
KPrintf("FlashWrite cmd format: FlashWrite addr data.\n");
return;
} else {
addr = strtol(argv[1], NULL, 0);
size = argc - 2;
write_param.buffer = data;
write_param.pos = addr;
write_param.size = size;
if (data) {
for (i = 0; i < size; i++) {
data[i] = strtol(argv[2 + i], NULL, 0);
}
ret = write(spi_flash_fd, &write_param, size);
if (EOK == ret) {
KPrintf("Write the %s flash data success. Start from 0x%08X, size is %ld.\n",
SPI_FLASH_PATH, addr, size);
KPrintf("Write data: ");
for (i = 0; i < size; i++) {
KPrintf("%d ", data[i]);
}
KPrintf(".\n");
}
} else {
KPrintf("SpiFlashWrite alloc write buffer failed!\n");
}
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
FlashWrite, FlashWrite, write data to spi flash device);