esp_system: introduce intermediary function to call after system init

This MR uses an intermediary function `start_app` to call after system
initialization instead of `app_main`.

In RTOS builds, freertos provides `start_app` and calls `app_main`.
In non-RTOS builds, user provides `start_app` directly.
This commit is contained in:
Renz Bagaporo
2020-06-10 21:13:31 +08:00
committed by Angus Gratton
parent 08cbfa6187
commit 98dc1b0188
4 changed files with 26 additions and 24 deletions

View File

@@ -63,4 +63,10 @@ set_source_files_properties(
_ESP_FREERTOS_INTERNAL
)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=app_main")
# The freertos component provides the `start_app` and `start_app_other_cores`
# if it is included in the build. It then calls `app_main`
# from the main task created, which must be provided by the user.
# Like for `start_app` and `start_app_other_cores`,
# we can't establish dependency on what we don't yet know, so we force the
# linker to not drop this symbol.
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u app_main")

View File

@@ -138,6 +138,8 @@ extern void _frxt_tick_timer_init(void);
/* Defined in xtensa_context.S */
extern void _xt_coproc_init(void);
extern void app_main(void);
static const char* TAG = "cpu_start"; // [refactor-todo]: might be appropriate to change in the future, but
// for now maintain the same log output
@@ -460,15 +462,6 @@ void __attribute__((weak)) vApplicationStackOverflowHook( TaskHandle_t xTask, c
esp_system_abort(buf);
}
// `esp_system` calls the app entry point app_main for core 0 and app_mainX for
// the rest of the cores which the app normally provides for non-os builds.
// If `freertos` is included in the build, wrap the call to app_main and provide
// our own definition of app_mainX so that we can do our own initializations for each
// core and start the scheduler.
//
// We now simply execute the real app_main in the context of the main task that
// we also start.
extern void __real_app_main(void);
static void main_task(void* args)
{
@@ -515,7 +508,7 @@ static void main_task(void* args)
}
#endif
__real_app_main();
app_main();
vTaskDelete(NULL);
}
@@ -530,7 +523,7 @@ static void main_task(void* args)
#if !CONFIG_FREERTOS_UNICORE
void app_mainX(void)
void start_app_other_cores(void)
{
// For now, we only support up to two core: 0 and 1.
if (xPortGetCoreID() >= 2) {
@@ -562,7 +555,7 @@ void app_mainX(void)
}
#endif
void __wrap_app_main(void)
void start_app(void)
{
#if CONFIG_ESP_INT_WDT
esp_int_wdt_init();