Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
[app] change the app api to have an init and entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
travisg committed Jan 25, 2009
1 parent 3f14b66 commit 668383c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
29 changes: 16 additions & 13 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,43 @@
#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;
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);
}
}
}

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));
}

10 changes: 7 additions & 3 deletions app/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 0 additions & 2 deletions app/stringtests/string_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,5 @@ STATIC_COMMAND_END(stringtests);
#endif

APP_START(stringtests)
.entry = 0,
.flags = 0,
APP_END

6 changes: 3 additions & 3 deletions app/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

13 changes: 7 additions & 6 deletions include/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 668383c

Please sign in to comment.