diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 00:38:09 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 00:53:28 -0700 |
commit | 2478a549b9f64c50310da41c861b8f86fdea2861 (patch) | |
tree | 3a62960f83453f354cbf309ac0722ed2ea6c27c7 /02-usart/include/kern/init.h | |
parent | 9dab2bf91ed3e6af7c7b07590ccc8c3b211a763a (diff) | |
download | stm32l4-2478a549b9f64c50310da41c861b8f86fdea2861.tar.gz stm32l4-2478a549b9f64c50310da41c861b8f86fdea2861.tar.bz2 stm32l4-2478a549b9f64c50310da41c861b8f86fdea2861.zip |
Add new system for startup.
Now instead of init() and main() being responsible for all
initialization, individual modules can link in their own
initialization routines.
There are 7 levels for these initializiation routines.
So far these are how the levels are defined
level 0 - Here the world is dark. Nothing is initialized.
This level is responsible for initializing the
system clock.
level 1 - The system clock has been configured, but nothing else. Not
even global variables. This level is responsible for loading
the data sections from flash and clearing the .bss section.
level 2 - USART2 is enabled and set to be the main kernel logging
vehicle. From this point on klogf(...) can be used.
level 3 - The NVIC is reset to point to the flash. From this point
on interrupts can be received. I expect this is where
most core initialization routines will take place
levels 4 to 7 - User initializiation levels.
main - main() is called after all 8 initialization levels have executed,
so in a sense main() is like a 9th initialization level, except
that there is can be only one main() routine whereas there can be
multiple initalization routines per level.
Diffstat (limited to '02-usart/include/kern/init.h')
-rw-r--r-- | 02-usart/include/kern/init.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/02-usart/include/kern/init.h b/02-usart/include/kern/init.h new file mode 100644 index 0000000..737b85f --- /dev/null +++ b/02-usart/include/kern/init.h @@ -0,0 +1,67 @@ +#ifndef INIT_H_ +#define INIT_H_ + +/** Globals annotated with _no_init will not be set during init1 bootup + * where the data segement is loaded from flash and the bss segment is + * cleared. + * + * This is useful for routines that run in the init0 boot procedure + * that need persistent globals. + * + * Note that initializing a global annotated with _no_init will have + * no effect as the variable will remain uninitialized until explicitly + * set by by the program. + */ +#define _no_init \ + __attribute((__section__(".noinit"))) + +#define init0 \ + static void init0fn(); \ + static __attribute((__section__(".init0"))) \ + __attribute((__used__)) \ + void(*init0_ptr)() = init0fn; \ + static void init0fn +#define init1 \ + static void init1fn(); \ + static __attribute((__section__(".init1"))) \ + __attribute((__used__)) \ + void(*init1_ptr)() = init1fn; \ + static void init1fn +#define init2 \ + static void init2fn(); \ + static __attribute((__section__(".init2"))) \ + __attribute((__used__)) \ + void(*init2_ptr)() = init2fn; \ + static void init2fn +#define init3 \ + static void init3fn(); \ + static __attribute((__section__(".init3"))) \ + __attribute((__used__)) \ + void(*init3_ptr)() = init3fn; \ + static void init3fn +#define init4 \ + static void init4fn(); \ + static __attribute((__section__(".init4"))) \ + __attribute((__used__)) \ + void(*init4_ptr)() = init4fn; \ + static void init4fn +#define init5 \ + static void init5fn(); \ + static __attribute((__section__(".init5"))) \ + __attribute((__used__)) \ + void(*init5_ptr)() = init5fn; \ + static void init5fn +#define init6 \ + static void init6fn(); \ + static __attribute((__section__(".init6"))) \ + __attribute((__used__)) \ + void(*init6_ptr)() = init6fn; \ + static void init6fn +#define init7 \ + static void init7fn(); \ + static __attribute((__section__(".init7"))) \ + __attribute((__used__)) \ + void(*init7_ptr)() = init7fn; \ + static void init7fn + +#endif /* INIT_H_ */ |