[app] change the app api to have an init and entry point
This commit is contained in:
31
app/app.c
31
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 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -245,7 +245,5 @@ STATIC_COMMAND_END(stringtests);
|
||||
#endif
|
||||
|
||||
APP_START(stringtests)
|
||||
.entry = 0,
|
||||
.flags = 0,
|
||||
APP_END
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user