app.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  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. extern const struct app_descriptor __apps_start[];
  27. extern const struct app_descriptor __apps_end[];
  28. static void start_app(const struct app_descriptor *app);
  29. /* one time setup */
  30. void apps_init(void)
  31. {
  32. const struct app_descriptor *app;
  33. /* call all the init routines */
  34. for (app = __apps_start; app != __apps_end; app++) {
  35. if (app->init)
  36. app->init(app);
  37. }
  38. /* start any that want to start on boot */
  39. for (app = __apps_start; app != __apps_end; app++) {
  40. if (app->entry && (app->flags & APP_FLAG_DONT_START_ON_BOOT) == 0) {
  41. start_app(app);
  42. }
  43. }
  44. }
  45. static int app_thread_entry(void *arg)
  46. {
  47. const struct app_descriptor *app = (const struct app_descriptor *)arg;
  48. app->entry(app, NULL);
  49. return 0;
  50. }
  51. static void start_app(const struct app_descriptor *app)
  52. {
  53. thread_t *thr;
  54. printf("starting app %s\n", app->name);
  55. thr = thread_create(app->name, &app_thread_entry, (void *)app, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
  56. if(!thr)
  57. {
  58. return;
  59. }
  60. thread_resume(thr);
  61. }