kernel: init: provide access to kernel startup state

Device initialization may require use of generic services such as
starting up power rails, some of which may be controlled by GPIOs on
an external controller that can't be used until full kernel services
are available.  Generic services can check k_is_in_isr() and mediate
their behavior that way, but currently have no way to determine that
the kernel is not available.

Provide a function that indicates whether initialization is still in
pre-kernel stages where no kernel services are available.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2019-12-10 08:46:54 -06:00 committed by Andrew Boie
commit c326661ee6
3 changed files with 95 additions and 0 deletions

View file

@ -25,6 +25,21 @@ extern "C" {
#define _SYS_INIT_LEVEL_POST_KERNEL 2
#define _SYS_INIT_LEVEL_APPLICATION 3
extern s8_t z_sys_device_level;
/**
* @brief Test whether startup is in the before-main-task phase.
*
* This impacts which services are available for use, and the context
* in which functions are run.
*
* @return true if and only if start up is still running pre-kernel
* initialization.
*/
static inline bool k_is_pre_kernel(void)
{
return (z_sys_device_level < _SYS_INIT_LEVEL_POST_KERNEL);
}
/* A counter is used to avoid issues when two or more system devices
* are declared in the same C file with the same init function.