Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor
noteLinkerCall
noteLinkerCall
[linkerCall] In this example code we load and execute a task in much the same way that the "run" shell command does, though with much simpler error handling: dbg_bugcheck() prints a message and then calls the RTEMS fatal error handler. Note that the "extra" argument can be NULL if you don't want more information than the status code for an error. See the header file "elf/lnkStatus.h" for the definition of the type lnk_Status.

Code Block
languagecpp
#include <inttypes.h>
#include <rtems.h>

#include "debug/print.h"
#include "elf/linker.h"
#include "task/Task.h"

void launch(void) {
  uint32_t status = STS_K_SUCCESS;
  Task_Attributes myAttr;
  myAttr.name = rtems_build_name('M', 'Y', 'T', 'K');
  myAttr.stack_size = 40 * 1024;
  myAttr.priority = 200;
  myAttr.attributes = RTEMS_DEFAULT_ATTRIBUTES;
  myAttr.modes = RTEMS_NO_PREEMPT;
  myAttr.image = NULL;
  myAttr.argc = 0;
  myAttr.argv = NULL;
  Ldr_elf* mytask = lnk_load("myspace:mytask.exe", &myAttr, &status, NULL);
  if (!mytask) {dbg_bugcheck("mytask.exe did not load. DIE!\n");}
  rtems_id id;
  Task_status tstat = Task_Run(mytask, &myAttr, myAttr.argc, myAttr.argv, &id);
  if (tstat) {dbg_bugcheck("mytask.exe did not run. DIE!\n");}
  // At this point you'll have launched a new thread running your task code.
}