Startup Entry and Interrupt
With GNU Arm Embedded Toolchain developers can achieve powerful control over the code generation.
NVIC Table (startup.c)
Unlike other GCC toolchains, the GCC embedded compiler allows developer the define the NVIC table at developer specified flash address.
The program entry upon reset is called ResetISR
in our code, which is the second entry of the NVIC table.
By the way, the first entry of the NVIC table is the startup stack pointer.
ResetISR
ResetISR
is the entry point of the firmware. Hornet provided the standard implementation of ResetISR
. Here is what it does,
- Initialized data needs to be copied over from flash to main RAM, from section
_etext
(in flash memory) over to region_data
(in main RAM ends with_edata
). - Uninitialized data shall be cleared to zero (between
_bss
and_ebss
). - Jump to hornet’s built-in
hornet_main()
function, which performs the following,- Initializes the FreeRTOS heap (through
vPortDefineHeapRegions
call). Read “RAM Layout” for more details. - Perform hardware, protocol stack and firmware initialization. Read “Hornet Initialization” for more details.
- Start FreeRTOS task scheduler. It will run in infinite loop and shall never return.
- Initializes the FreeRTOS heap (through
Interrupt Handlers
Interrupt handlers are also defined in NVIC table. Depends on the peripheral the board supports, the interrupt handlers shall be customized by developer.
For exmaple, if board needs to drive serial ports, i2c and SPI, the entries to corresponding interrupt handlers shall be specified in corresponding NVIC locations.
We won’t provide a “one size fit all” solution because unused code will take up space and make firmware size unnecessarily big.
The NVIC Table Code
The NVIC table is defined in startup.c
.
Note the table will be put to an address specified as .vectors
.
__attribute__ ((section(".vectors"), used))
void (* const gVectors[])(void) =
{
((void (*)(void))INIT_STACK), // Stack pointer at (uint32_t)pui32Stack + sizeof(pui32Stack)
ResetISR, // Reset handler
NmiSR, // The NMI handler
// ...
The Polling
Hornet runs in “tickless idle mode”, in which vApplicationIdleHook
function is constantly called between sleeps (and possibly interrupt handlings).
Hornet OS provides the standard implementation of vApplicationIdleHook
.