From 668383c506daed03bfc286b83f647768cd5e1f0a Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sat, 24 Jan 2009 21:44:52 -0800 Subject: [PATCH] [app] change the app api to have an init and entry point --- app/app.c | 29 ++++++++++++++++------------- app/shell/shell.c | 10 +++++++--- app/stringtests/string_tests.c | 2 -- app/tests/tests.c | 6 +++--- include/app.h | 13 +++++++------ 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/app/app.c b/app/app.c index c80f09738..2aad5f467 100644 --- a/app/app.c +++ b/app/app.c @@ -24,19 +24,25 @@ #include #include -extern const struct _app_descriptor __apps_start; -extern const struct _app_descriptor __apps_end; +extern const struct app_descriptor __apps_start; +extern const struct app_descriptor __apps_end; -static void start_app(const struct _app_descriptor *app); +static void start_app(const struct app_descriptor *app); /* one time setup */ void apps_init(void) { - const struct _app_descriptor *app; + const struct app_descriptor *app; + + /* call all the init routines */ for (app = &__apps_start; app != &__apps_end; app++) { -// printf("app '%s'\n", app->name); + if (app->init) + app->init(app); + } - if (app->entry && app->flags & APP_FLAG_BOOT_START) { + /* start any that want to start on boot */ + for (app = &__apps_start; app != &__apps_end; app++) { + if (app->entry && (app->flags & APP_FLAG_DONT_START_ON_BOOT) == 0) { start_app(app); } } @@ -44,20 +50,17 @@ void apps_init(void) static int app_thread_entry(void *arg) { - const struct _app_descriptor *app = (const struct _app_descriptor *)arg; + const struct app_descriptor *app = (const struct app_descriptor *)arg; app->entry(app, NULL); return 0; } -static void start_app(const struct _app_descriptor *app) +static void start_app(const struct app_descriptor *app) { printf("starting app %s\n", app->name); - if (app->flags & APP_FLAG_THREAD) { - thread_resume(thread_create(app->name, &app_thread_entry, (void *)app, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); - } else { - app->entry(app, NULL); - } + + thread_resume(thread_create(app->name, &app_thread_entry, (void *)app, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); } diff --git a/app/shell/shell.c b/app/shell/shell.c index e646683a4..bdf67c5b8 100644 --- a/app/shell/shell.c +++ b/app/shell/shell.c @@ -24,14 +24,18 @@ #include #include -static void shell_init(const struct _app_descriptor *app, void *args) +static void shell_init(const struct app_descriptor *app) { console_init(); +} + +static void shell_entry(const struct app_descriptor *app, void *args) +{ console_start(); } APP_START(shell) - .entry = shell_init, - .flags = APP_FLAG_BOOT_START | APP_FLAG_THREAD, + .init = shell_init, + .entry = shell_entry, APP_END diff --git a/app/stringtests/string_tests.c b/app/stringtests/string_tests.c index 69bdbbeeb..666434669 100644 --- a/app/stringtests/string_tests.c +++ b/app/stringtests/string_tests.c @@ -245,7 +245,5 @@ STATIC_COMMAND_END(stringtests); #endif APP_START(stringtests) - .entry = 0, - .flags = 0, APP_END diff --git a/app/tests/tests.c b/app/tests/tests.c index 9e0491837..1a8130bb8 100644 --- a/app/tests/tests.c +++ b/app/tests/tests.c @@ -35,12 +35,12 @@ STATIC_COMMAND_END(tests); #endif -static void tests_init(const struct _app_descriptor *app, void *args) +static void tests_init(const struct app_descriptor *app) { } APP_START(tests) - .entry = tests_init, - .flags = APP_FLAG_BOOT_START, + .init = tests_init, + .flags = 0, APP_END diff --git a/include/app.h b/include/app.h index 1a9a93cff..f06bf2718 100644 --- a/include/app.h +++ b/include/app.h @@ -27,21 +27,22 @@ void apps_init(void); /* one time setup */ /* app entry point */ -struct _app_descriptor; -typedef void (*app_entry)(const struct _app_descriptor *, void *args); +struct app_descriptor; +typedef void (*app_init)(const struct app_descriptor *); +typedef void (*app_entry)(const struct app_descriptor *, void *args); /* app startup flags */ -#define APP_FLAG_BOOT_START 0x1 -#define APP_FLAG_THREAD 0x2 +#define APP_FLAG_DONT_START_ON_BOOT 0x1 /* each app needs to define one of these to define its startup conditions */ -struct _app_descriptor { +struct app_descriptor { const char *name; + app_init init; app_entry entry; unsigned int flags; }; -#define APP_START(appname) struct _app_descriptor _app_##appname __SECTION(".apps") = { .name = #appname, +#define APP_START(appname) struct app_descriptor _app_##appname __SECTION(".apps") = { .name = #appname, #define APP_END }; #endif