mirror of
https://gitee.com/Lamdonn/varch.git
synced 2026-04-30 19:09:14 +08:00
328 lines
7.3 KiB
C
328 lines
7.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#if defined(TEST_TARGET_icom)
|
|
#include <varch/command.h>
|
|
#include <varch/unitt.h>
|
|
#include <varch/icom.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "unitt.h"
|
|
#include "kern.h"
|
|
#include "icom.h"
|
|
#endif
|
|
|
|
/************************************************************************************/
|
|
/************************************* Unit Test ************************************/
|
|
/************************************************************************************/
|
|
|
|
// #define EXIT_TEST
|
|
extern uint64_t unitt_clock(void);
|
|
|
|
static int test_0(void)
|
|
{
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
if (0)
|
|
{
|
|
|
|
#if defined (EXIT_TEST)
|
|
exit(0);
|
|
#endif
|
|
return UNITT_E_FAIL;
|
|
}
|
|
}
|
|
|
|
return UNITT_E_OK;
|
|
}
|
|
|
|
static void unitt_task(void)
|
|
{
|
|
static UNITT_TCASE rand_tests[] = {
|
|
UNITT_TCASE(test_0),
|
|
// UNITT_TCASE(test_1),
|
|
// UNITT_TCASE(test_2),
|
|
};
|
|
|
|
static UNITT suites[] = {
|
|
{ "icom suite", rand_tests, sizeof(rand_tests) / sizeof(rand_tests[0]) , unitt_clock },
|
|
};
|
|
|
|
UNITT_EXE(suites);
|
|
}
|
|
|
|
/************************************************************************************/
|
|
/************************************* Base Test ************************************/
|
|
/************************************************************************************/
|
|
|
|
static uint8_t icomBuffer0[1024] = {0};
|
|
static uint8_t icomBuffer1[1024] = {0};
|
|
|
|
static int dev0_rx_callback(uint16_t channel, uint8_t *data, uint32_t length);
|
|
static int dev1_rx_callback(uint16_t channel, uint8_t *data, uint32_t length);
|
|
|
|
static ICOM dev0ICOM = {
|
|
.init = 0,
|
|
.txconfig = (ICOM_CHNCFG[1]){
|
|
{
|
|
.base = icomBuffer0,
|
|
.size = sizeof(icomBuffer0),
|
|
.callback = NULL,
|
|
},
|
|
},
|
|
.rxconfig = (ICOM_CHNCFG[1]){
|
|
{
|
|
.base = icomBuffer1,
|
|
.size = sizeof(icomBuffer1),
|
|
.callback = dev0_rx_callback,
|
|
},
|
|
},
|
|
.txcount = 1,
|
|
.rxcount = 1,
|
|
.inv = NULL,
|
|
.wbinv = NULL,
|
|
};
|
|
|
|
static ICOM dev1ICOM = {
|
|
.init = 0,
|
|
.txconfig = (ICOM_CHNCFG[1]){
|
|
{
|
|
.base = icomBuffer1,
|
|
.size = sizeof(icomBuffer1),
|
|
.callback = NULL,
|
|
},
|
|
},
|
|
.rxconfig = (ICOM_CHNCFG[1]){
|
|
{
|
|
.base = icomBuffer0,
|
|
.size = sizeof(icomBuffer0),
|
|
// .callback = dev1_rx_callback,
|
|
.callback = NULL,
|
|
},
|
|
},
|
|
.txcount = 1,
|
|
.rxcount = 1,
|
|
.inv = NULL,
|
|
.wbinv = NULL,
|
|
};
|
|
|
|
static int dev0_rx_callback(uint16_t channel, uint8_t *data, uint32_t length)
|
|
{
|
|
printf("[%d]: %s\r\n", length, data);
|
|
return 0;
|
|
}
|
|
|
|
static int dev1_rx_callback(uint16_t channel, uint8_t *data, uint32_t length)
|
|
{
|
|
printf("[%d]: %s\r\n", length, data);
|
|
// printf("[%d]\r\n", length);
|
|
// for (int i = 0; i < length; i++)
|
|
// {
|
|
// printf("%02x ", data[i]);
|
|
// }
|
|
// printf("\r\n");
|
|
icom_transmit(&dev1ICOM, 0, "Copy that!", 11);
|
|
return 0;
|
|
}
|
|
|
|
static void dev0_task(void);
|
|
static void dev1_task(void);
|
|
|
|
static void dev0_task(void)
|
|
{
|
|
static uint8_t init = 0;
|
|
static uint32_t count = 0;
|
|
|
|
if (!init)
|
|
{
|
|
icom_init(&dev0ICOM);
|
|
init = 1;
|
|
}
|
|
|
|
count += 10;
|
|
if (count >= 25200000) count = 0;
|
|
|
|
if (count % 10 == 0)
|
|
{
|
|
icom_task(&dev0ICOM);
|
|
}
|
|
|
|
if (count % 1000 == 0)
|
|
{
|
|
uint8_t txonline = 0, rxonline = 0;
|
|
icom_txchannel_online(&dev0ICOM, 0, &txonline);
|
|
icom_rxchannel_online(&dev0ICOM, 0, &rxonline);
|
|
printf("online %d,%d\r\n", txonline, rxonline);
|
|
icom_transmit(&dev0ICOM, 0, "Hello dev1", 11);
|
|
|
|
static int time = 0;
|
|
if (time >= 3)
|
|
{
|
|
task_create(10, dev1_task);
|
|
}
|
|
else
|
|
{
|
|
time++;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void dev1_task(void)
|
|
{
|
|
static uint8_t init = 0;
|
|
static uint32_t count = 0;
|
|
|
|
if (!init)
|
|
{
|
|
icom_init(&dev1ICOM);
|
|
init = 1;
|
|
}
|
|
|
|
count += 10;
|
|
if (count >= 25200000) count = 0;
|
|
|
|
char rxBuffer[1024];
|
|
uint32_t length = sizeof(rxBuffer);
|
|
if (ICOM_E_OK == icom_receive(&dev1ICOM, 0, rxBuffer, &length))
|
|
{
|
|
printf("[%d]: %s\r\n", length, rxBuffer);
|
|
}
|
|
|
|
if (count % 10 == 0)
|
|
{
|
|
icom_task(&dev1ICOM);
|
|
}
|
|
|
|
if (count % 1000 == 0)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
static void test_base(void)
|
|
{
|
|
task_create(10, dev0_task);
|
|
// task_create(10, dev1_task);
|
|
}
|
|
|
|
/************************************************************************************/
|
|
/************************************* Command ************************************/
|
|
/************************************************************************************/
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: icom [opt] [arg] ...\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -e <execute> Specifies the function to execute, the default is the <base> test\n"
|
|
" <base> Test base function\n"
|
|
" <ut> Unit test\n"
|
|
" ...\n"
|
|
" -h Print help\n"
|
|
" -v Print version\n"
|
|
" -u [<period>] Unit test period, unit ms, the default is 1000ms\n"
|
|
"\n"
|
|
);
|
|
}
|
|
|
|
static int test(int argc, char *argv[])
|
|
{
|
|
char *execute = NULL;
|
|
int ut_period = 1000;
|
|
|
|
/* reset getopt */
|
|
command_opt_init();
|
|
|
|
while (1)
|
|
{
|
|
int opt = command_getopt(argc, argv, "e:hvu::");
|
|
if (opt == -1) break;
|
|
|
|
switch (opt)
|
|
{
|
|
// Add others opt here
|
|
case 'u' :
|
|
if (command_optarg) ut_period = atoi(command_optarg);
|
|
break;
|
|
case 'e' :
|
|
execute = command_optarg;
|
|
break;
|
|
case 'v' :
|
|
printf("icom version %d.%d.%d\r\n", ICOM_V_MAJOR, ICOM_V_MINOR, ICOM_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
if (execute)
|
|
{
|
|
if (!strcmp(execute, "base"))
|
|
{
|
|
test_base();
|
|
}
|
|
else if (!strcmp(execute, "ut"))
|
|
{
|
|
#if defined(TEST_TARGET_icom)
|
|
while (1)
|
|
{
|
|
unitt_task();
|
|
usleep(1000 * ut_period);
|
|
}
|
|
#else
|
|
printf("create task %d\r\n", task_create(ut_period, unitt_task));
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
{
|
|
test_base();
|
|
}
|
|
|
|
#if 0
|
|
if (1 == command_optind) // no opt
|
|
{
|
|
|
|
}
|
|
|
|
for (int index = command_optind; index < argc; index++)
|
|
{
|
|
if (!strcmp(argv[index], "base"))
|
|
{
|
|
test_base();
|
|
}
|
|
}
|
|
|
|
if (1 == argc)
|
|
{
|
|
test_base();
|
|
}
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
/************************************************************************************/
|
|
/************************************ Test entry ************************************/
|
|
/************************************************************************************/
|
|
|
|
#if defined(TEST_TARGET_icom)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_icom(void)
|
|
{
|
|
command_export("icom", test);
|
|
}
|
|
init_export_app(test_icom);
|
|
#endif
|