diff --git a/drivers/drivers_initialize.c b/drivers/drivers_initialize.c index 70b10f257cc..8a52b47c3d2 100644 --- a/drivers/drivers_initialize.c +++ b/drivers/drivers_initialize.c @@ -53,6 +53,26 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: drivers_early_initialize + * + * Description: + * drivers_early_initialize will be called once before OS initialization + * when no system resource is ready to use. + * + * drivers_early_initialize serves the purpose of bringing up drivers as + * early as possible, so they can be used even during OS initialization. + * It must not rely on any system resources, such as heap memory. + * + ****************************************************************************/ + +void drivers_early_initialize(void) +{ +#ifdef CONFIG_DRIVERS_NOTE + note_early_initialize(); +#endif +} + /**************************************************************************** * Name: drivers_initialize * diff --git a/drivers/note/note_initialize.c b/drivers/note/note_initialize.c index bcece5019f0..5d507289255 100644 --- a/drivers/note/note_initialize.c +++ b/drivers/note/note_initialize.c @@ -35,6 +35,46 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: note_early_initialize + * + * Description: + * Registers note drivers early, without depending on system features + * such as heap memory. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero on success. A negated errno value is returned on a failure. + * + ****************************************************************************/ + +int note_early_initialize(void) +{ + int ret = 0; + +#ifdef CONFIG_SEGGER_SYSVIEW + ret = note_sysview_initialize(); + if (ret < 0) + { + serr("note_sysview_initialize failed %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_DRIVERS_NOTESNAP + ret = notesnap_register(); + if (ret < 0) + { + serr("notesnap_register failed %d\n", ret); + return ret; + } +#endif + + return ret; +} + /**************************************************************************** * Name: note_initialize * @@ -46,7 +86,7 @@ * None. * * Returned Value: - * Zero on succress. A negated errno value is returned on a failure. + * Zero on success. A negated errno value is returned on a failure. * ****************************************************************************/ @@ -81,23 +121,5 @@ int note_initialize(void) } #endif -#ifdef CONFIG_SEGGER_SYSVIEW - ret = note_sysview_initialize(); - if (ret < 0) - { - serr("note_sysview_initialize failed %d\n", ret); - return ret; - } -#endif - -#ifdef CONFIG_DRIVERS_NOTESNAP - ret = notesnap_register(); - if (ret < 0) - { - serr("notesnap_register failed %d\n", ret); - return ret; - } -#endif - return ret; } diff --git a/include/nuttx/drivers/drivers.h b/include/nuttx/drivers/drivers.h index de025d7d00b..3dec1802258 100644 --- a/include/nuttx/drivers/drivers.h +++ b/include/nuttx/drivers/drivers.h @@ -43,6 +43,17 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Name: drivers_early_initialize + * + * Description: + * Performs one-time, early driver initialization that doesn't rely on OS + * resources being ready. + * + ****************************************************************************/ + +void drivers_early_initialize(void); + /**************************************************************************** * Name: drivers_initialize * diff --git a/include/nuttx/note/note_driver.h b/include/nuttx/note/note_driver.h index 8e1de970371..ddea0337432 100644 --- a/include/nuttx/note/note_driver.h +++ b/include/nuttx/note/note_driver.h @@ -112,6 +112,25 @@ struct note_driver_s #if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) +#ifdef CONFIG_DRIVERS_NOTE + +/**************************************************************************** + * Name: note_early_initialize + * + * Description: + * Early register sched note related drivers that do not rely on system + * features like mm. + * + * Input Parameters: + * None. + * + * Returned Value: + * Zero on success. A negative errno value is returned on a failure. + * + ****************************************************************************/ + +int note_early_initialize(void); + /**************************************************************************** * Name: note_initialize * @@ -123,11 +142,10 @@ struct note_driver_s * None. * * Returned Value: - * Zero on succress. A negated errno value is returned on a failure. + * Zero on success. A negative errno value is returned on a failure. * ****************************************************************************/ -#ifdef CONFIG_DRIVERS_NOTE int note_initialize(void); #endif diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index a74b5ea22a5..997612739c3 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -518,10 +518,6 @@ void nx_start(void) g_nx_initstate = OSINIT_BOOT; - /* Initialize RTOS Data ***************************************************/ - - sched_trace_begin(); - /* Initialize task list table *********************************************/ tasklist_initialize(); @@ -534,6 +530,12 @@ void nx_start(void) g_nx_initstate = OSINIT_TASKLISTS; + /* Initialize RTOS Data ***************************************************/ + + drivers_early_initialize(); + + sched_trace_begin(); + /* Initialize RTOS facilities *********************************************/ /* Initialize the semaphore facility. This has to be done very early