#include #include #include #if defined(TEST_TARGET_ramt) #include #include #else #include "init.h" #include "command.h" #include "ramt.h" #include "kern.h" #endif #define TASK_PERIOD 5 // ms static uint8_t buffer[128]; static RAMT ramt_object; static void test_task(void) { static int count = 0; count += TASK_PERIOD; ramt_task(&ramt_object); if (count % 1000 == 0) { printf("result %08X\r\n", ramt_result(&ramt_object)); } } static void usage(void) { printf( "Usage: ramt [opt] [arg]\n" "\n" "options:\n" " -h Print help\n" " -v Print version\n" "\n" "argument:\n" " Test default read function\n" " Test default write function\n" ); } static int test(int argc, char *argv[]) { int period = 1000; // ms /* reset getopt */ command_opt_init(); while (1) { int opt = command_getopt(argc, argv, "p:hv"); if (opt == -1) break; switch (opt) { case 'p' : period = atoi(command_optarg); break; case 'v' : printf("ramt version %d.%d.%d\r\n", RAMT_V_MAJOR, RAMT_V_MINOR, RAMT_V_PATCH); return 0; case '?': printf("Unknown option `%c`\r\n", command_optopt); return -1; case 'h' : default: usage(); return 0; } } if (1 == command_optind) // no opt { test_task(); return 0; } ramt_object.base = (void *)buffer; ramt_object.size = sizeof(buffer); ramt_init(&ramt_object); ramt_start(&ramt_object, RAMT_MODE_NORMAL, 0xFFFFFFFF); #if defined(TEST_TARGET_ramt) while (1) { test_task(); usleep(1000 * period); } #else printf("create task %d\r\n", task_create(TASK_PERIOD, test_task)); #endif return 0; } #if defined(TEST_TARGET_ramt) int main(int argc, char *argv[]) { return test(argc, argv); } #else void test_ramt(void) { command_export("ramt", test); } init_export_app(test_ramt); #endif