blob: 547659a8b2bba1940fa707d253b82b45c0d3d5ed [file] [log] [blame]
Travis Geiselbrecht68372232009-01-24 21:21:08 -08001/*
2 * Copyright (c) 2009 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <debug.h>
24#include <app.h>
25#include <kernel/thread.h>
26
Travis Geiselbrecht668383c2009-01-24 21:44:52 -080027extern const struct app_descriptor __apps_start;
28extern const struct app_descriptor __apps_end;
Travis Geiselbrecht68372232009-01-24 21:21:08 -080029
Travis Geiselbrecht668383c2009-01-24 21:44:52 -080030static void start_app(const struct app_descriptor *app);
Travis Geiselbrecht68372232009-01-24 21:21:08 -080031
32/* one time setup */
33void apps_init(void)
34{
Travis Geiselbrecht668383c2009-01-24 21:44:52 -080035 const struct app_descriptor *app;
Travis Geiselbrecht68372232009-01-24 21:21:08 -080036
Travis Geiselbrecht668383c2009-01-24 21:44:52 -080037 /* call all the init routines */
38 for (app = &__apps_start; app != &__apps_end; app++) {
39 if (app->init)
40 app->init(app);
41 }
42
43 /* start any that want to start on boot */
44 for (app = &__apps_start; app != &__apps_end; app++) {
45 if (app->entry && (app->flags & APP_FLAG_DONT_START_ON_BOOT) == 0) {
Travis Geiselbrecht68372232009-01-24 21:21:08 -080046 start_app(app);
47 }
48 }
49}
50
51static int app_thread_entry(void *arg)
52{
Travis Geiselbrecht668383c2009-01-24 21:44:52 -080053 const struct app_descriptor *app = (const struct app_descriptor *)arg;
Travis Geiselbrecht68372232009-01-24 21:21:08 -080054
55 app->entry(app, NULL);
56
57 return 0;
58}
59
Travis Geiselbrecht668383c2009-01-24 21:44:52 -080060static void start_app(const struct app_descriptor *app)
Travis Geiselbrecht68372232009-01-24 21:21:08 -080061{
neetid826d9da2011-12-07 18:55:53 -080062 thread_t *thr;
Travis Geiselbrecht68372232009-01-24 21:21:08 -080063 printf("starting app %s\n", app->name);
Travis Geiselbrecht668383c2009-01-24 21:44:52 -080064
neetid826d9da2011-12-07 18:55:53 -080065 thr = thread_create(app->name, &app_thread_entry, (void *)app, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
66 if(!thr)
67 {
68 return;
69 }
70 thread_resume(thr);
Travis Geiselbrecht68372232009-01-24 21:21:08 -080071}
72