2022-05-26 10:48:49 -04:00
/*
* SPDX - FileCopyrightText : 2015 - 2022 Espressif Systems ( Shanghai ) CO LTD
*
* SPDX - License - Identifier : Apache - 2.0
*/
2020-02-05 06:57:40 -05:00
# pragma once
# include "esp_attr.h"
2020-02-05 09:40:15 -05:00
# include "soc/soc_caps.h"
# include "hal/cpu_hal.h"
2020-02-13 07:43:23 -05:00
# include "sdkconfig.h"
2020-02-16 08:29:29 -05:00
# ifdef __cplusplus
extern " C " {
# endif
2020-02-05 09:40:15 -05:00
// Port layer defines the entry point. It then transfer control to a `sys_startup_fn_t`, stored in this
// array, one per core.
typedef void ( * sys_startup_fn_t ) ( void ) ;
2020-02-13 07:43:23 -05:00
2021-03-01 23:59:44 -05:00
/* This array of per-CPU system layer startup functions is initialized in the non-port part of esp_system */
2020-02-13 07:43:23 -05:00
# if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
2021-03-01 23:59:44 -05:00
extern sys_startup_fn_t const g_startup_fn [ SOC_CPU_CORES_NUM ] ;
2020-02-13 07:43:23 -05:00
# else
2021-03-01 23:59:44 -05:00
extern sys_startup_fn_t const g_startup_fn [ 1 ] ;
2020-02-13 07:43:23 -05:00
# endif
2020-02-05 09:40:15 -05:00
// Utility to execute `sys_startup_fn_t` for the current core.
# define SYS_STARTUP_FN() ((*g_startup_fn[(cpu_hal_get_core_id())])())
2020-02-13 07:43:23 -05:00
# if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
2020-02-05 09:40:15 -05:00
void startup_resume_other_cores ( void ) ;
2020-02-13 07:43:23 -05:00
# endif
2020-02-05 09:40:15 -05:00
2020-02-05 06:57:40 -05:00
typedef struct {
void ( * fn ) ( void ) ;
uint32_t cores ;
} esp_system_init_fn_t ;
/*
* Declare an component initialization function that will execute on the specified cores ( ex . if BIT0 = = 1 , will execute
* on CORE0 , CORE1 if BIT1 and so on ) .
2020-11-10 02:40:01 -05:00
*
2020-02-05 06:57:40 -05:00
* @ note Initialization functions should be placed in a compilation unit where at least one other
* symbol is referenced ' meaningfully ' in another compilation unit , otherwise this gets discarded during linking . ( By
* ' meaningfully ' we mean the reference should not itself get optimized out by the compiler / discarded by the linker ) .
*/
# define ESP_SYSTEM_INIT_FN(f, c, ...) \
static void __attribute__ ( ( used ) ) __VA_ARGS__ __esp_system_init_fn_ # # f ( void ) ; \
static __attribute__ ( ( used ) ) esp_system_init_fn_t _SECTION_ATTR_IMPL ( " .esp_system_init_fn " , f ) \
esp_system_init_fn_ # # f = { . fn = ( __esp_system_init_fn_ # # f ) , . cores = ( c ) } ; \
2020-11-10 02:40:01 -05:00
static __attribute__ ( ( used ) ) __VA_ARGS__ void __esp_system_init_fn_ # # f ( void ) // [refactor-todo] this can be made public API if we allow components to declare init functions,
2020-02-05 06:57:40 -05:00
// instead of calling them explicitly
2020-11-10 02:40:01 -05:00
extern uint64_t g_startup_time ; // Startup time that serves as the point of origin for system time. Should be set by the entry
2020-06-23 04:46:06 -04:00
// function in the port layer. May be 0 as well if this is not backed by a persistent counter, in which case
// startup time = system time = 0 at the point the entry function sets this variable.
2020-02-16 08:29:29 -05:00
# ifdef __cplusplus
}
# endif