Introduction¶
OS startup behaviour¶
When MiraOS starts up, it will automatically call the function mira_setup()
which is the application's entry point. From here peripherals can be initialised, processes started, etc.
Note: processes started from mira_setup
must pause once with a call to PROCESS_PAUSE()
immediately after PROCESS_BEGIN()
to let the kernel finalise initialisation before executing the process.
Input/output¶
MiraOS can use file descriptors to use with dprintf
. These can be listed in the MIRA_IODEFS
list. The three first are the standard file descriptors stdin
, stdout
and stderr
.
MIRA_IODEFS(
MIRA_IODEF_NONE, /* fd 0: stdin */
MIRA_IODEF_NONE, /* fd 1: stdout */
MIRA_IODEF_NONE /* fd 2: stderr */
);
These can be mapped towards input/output routines, for instance write/read functions for a UART.
Example¶
To be able to have printf()
sending it's output to a serial terminal on a PC, we would need to map stdout
to UART0 and connect UART0 to the PC's serial port.
UART0 needs to be properly initialised for this to work.
MIRA_IODEFS(
MIRA_IODEF_NONE, /* fd 0: stdin */
MIRA_IODEF_UART(0), /* fd 1: stdout */
MIRA_IODEF_NONE /* fd 2: stderr */
);
Minimal MiraOS application¶
The following application is a minimal MiraOS application. It can be used as a starting point for your applications.
#include <mira.h>
MIRA_IODEFS(
MIRA_IODEF_NONE, /* fd 0: stdin */
MIRA_IODEF_NONE, /* fd 1: stdout */
MIRA_IODEF_NONE /* fd 2: stderr */
);
PROCESS(main_proc, "Main process");
void mira_setup(void)
{
process_start(&main_proc, NULL);
}
PROCESS_THREAD(main_proc, ev, data)
{
PROCESS_BEGIN();
/* Pause once, so we don't run anything before finish of startup */
PROCESS_PAUSE();
/* Here's the place for the process' code */
PROCESS_END();
}