[app] change the app api to have an init and entry point
diff --git a/app/app.c b/app/app.c
index c80f097..2aad5f4 100644
--- a/app/app.c
+++ b/app/app.c
@@ -24,19 +24,25 @@
#include <app.h>
#include <kernel/thread.h>
-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;
- for (app = &__apps_start; app != &__apps_end; app++) {
-// printf("app '%s'\n", app->name);
+ const struct app_descriptor *app;
- if (app->entry && app->flags & APP_FLAG_BOOT_START) {
+ /* call all the init routines */
+ for (app = &__apps_start; app != &__apps_end; app++) {
+ if (app->init)
+ app->init(app);
+ }
+
+ /* 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 @@
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 e646683..bdf67c5 100644
--- a/app/shell/shell.c
+++ b/app/shell/shell.c
@@ -24,14 +24,18 @@
#include <debug.h>
#include <lib/console.h>
-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 69bdbbe..6664346 100644
--- a/app/stringtests/string_tests.c
+++ b/app/stringtests/string_tests.c
@@ -245,7 +245,5 @@
#endif
APP_START(stringtests)
- .entry = 0,
- .flags = 0,
APP_END
diff --git a/app/tests/tests.c b/app/tests/tests.c
index 9e04918..1a8130b 100644
--- a/app/tests/tests.c
+++ b/app/tests/tests.c
@@ -35,12 +35,12 @@
#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 1a9a93c..f06bf27 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