mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-06 16:56:42 +08:00
110 lines
2.1 KiB
C
110 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
#if defined(TEST_TARGET_kern)
|
|
#include <varch/command.h>
|
|
#include <varch/kern.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "kern.h"
|
|
#endif
|
|
|
|
static unsigned int get_msec(void)
|
|
{
|
|
struct timeval mstime;
|
|
unsigned int ms = 0;
|
|
gettimeofday(&mstime, NULL);
|
|
ms = mstime.tv_sec * 1000 + mstime.tv_usec / 1000;
|
|
return ms;
|
|
}
|
|
|
|
static void task1(void)
|
|
{
|
|
static int count = 0;
|
|
printf("task1 running! %d\r\n", ++count);
|
|
}
|
|
|
|
static void task2(void)
|
|
{
|
|
static int count = 0;
|
|
printf("task2 running! %d\r\n", ++count);
|
|
}
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: kern [opt] [arg]\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -h Print help\n"
|
|
" -v Print version\n"
|
|
"\n"
|
|
"argument:\n"
|
|
" <read> Test default read function\n"
|
|
" <write> Test default write function\n"
|
|
);
|
|
}
|
|
|
|
static int test(int argc, char *argv[])
|
|
{
|
|
/* reset getopt */
|
|
command_opt_init();
|
|
|
|
while (1)
|
|
{
|
|
int opt = command_getopt(argc, argv, "hv");
|
|
if (opt == -1) break;
|
|
|
|
switch (opt)
|
|
{
|
|
case 'v' :
|
|
printf("kern version %d.%d.%d\r\n", KERN_V_MAJOR, KERN_V_MINOR, KERN_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
#if defined(TEST_TARGET_kern)
|
|
if (kern_init(get_msec, 1) == KE_OK)
|
|
{
|
|
printf("kern init success!\r\n");
|
|
}
|
|
else
|
|
{
|
|
printf("*** kern init fail!\r\n");
|
|
return 0;
|
|
}
|
|
|
|
printf("create task %d\r\n", task_create(1000, task1));
|
|
printf("create task %d\r\n", task_create(500, task2));
|
|
|
|
kern_schedule();
|
|
#else
|
|
printf("create task %d\r\n", task_create(1000, task1));
|
|
printf("create task %d\r\n", task_create(500, task2));
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if defined(TEST_TARGET_kern)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_kern(void)
|
|
{
|
|
command_export("kern", test);
|
|
}
|
|
init_export_app(test_kern);
|
|
#endif
|