Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added a reference to the system architecture page for a list of modules.

...

Section


Column

Most of the flight code is organized in modules. On this page, you will learn about a few important modules and how modules work in generalThis page describes the essential functions of a module and how these functions are called.


Column
width250px


Panel
titleIn this page

Table of Contents



...

As you can see, a module is just a bunch of code that must contain three essential things:

Initialize FunctionThis function is called by the System module on startup. It usually contains all the initialization code neccessary for the module to work, as the name suggests.
Start FunctionAnother function called by the System module on startup, just a few lines after all the module initialization functions are called. This function usually contains code to set up Tasks (aka Threads).
MODULE_INITCALLIn order for the above two functions to get called, a module must call the MODULE_INITCALL macro. This will be described further in the next section.

Module Code Execution

So, say you've created a new module. It has a start- and an initialize function. Where are these functions called from? How does LibrePilot know about these functions?

...

On startup, the System module calls another macro - MODULE_INITIALISE_ALL - which loops through all initialization function pointers and calls the functions they point to. Remember, this is possible because all initialize functions are put in one place (the .initcall section). As mentioned before, a few lines later, the System module calls the MODULE_TASKCREATE_ALL macro, which in turn loops through all the start function pointers and calls the corresponding functions.

Tip
titleFun Fact

The Linux kernel makes use of pretty much the same initcall mechanism. You can find a more detailed description of how it works here.


Tip
titleTip

Have a look at the LibrePilot System Architecture page in the Developer Manual section of the documentation for descriptions of a few important modules.