2022-05-26 10:48:49 -04:00
|
|
|
/*
|
2024-01-29 20:40:10 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
2022-05-26 10:48:49 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-02-05 06:57:40 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
2022-05-17 17:42:54 -04:00
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_bit_defs.h"
|
2024-04-20 06:19:31 -04:00
|
|
|
#if !CONFIG_IDF_TARGET_LINUX
|
2022-07-21 07:24:42 -04:00
|
|
|
#include "esp_cpu.h"
|
2024-04-20 06:19:31 -04:00
|
|
|
#endif
|
2020-02-05 09:40:15 -05:00
|
|
|
|
|
|
|
#include "soc/soc_caps.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.
|
2022-07-21 07:24:42 -04:00
|
|
|
#define SYS_STARTUP_FN() ((*g_startup_fn[(esp_cpu_get_core_id())])())
|
2020-02-05 09:40:15 -05:00
|
|
|
|
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
|
|
|
|
2022-05-17 17:42:54 -04:00
|
|
|
/**
|
|
|
|
* Internal structure describing ESP_SYSTEM_INIT_FN startup functions
|
|
|
|
*/
|
2020-02-05 06:57:40 -05:00
|
|
|
typedef struct {
|
2022-05-17 17:42:54 -04:00
|
|
|
esp_err_t (*fn)(void); /*!< Pointer to the startup function */
|
2023-11-24 12:32:37 -05:00
|
|
|
uint16_t cores; /*!< Bit mask of cores where the function has to be called */
|
|
|
|
uint16_t stage; /*!< Init stage number (0 or 1) */
|
2020-02-05 06:57:40 -05:00
|
|
|
} esp_system_init_fn_t;
|
|
|
|
|
2023-11-24 12:32:37 -05:00
|
|
|
#define ESP_SYSTEM_INIT_STAGE_CORE 0
|
|
|
|
#define ESP_SYSTEM_INIT_STAGE_SECONDARY 1
|
|
|
|
|
2022-05-17 17:42:54 -04:00
|
|
|
/**
|
|
|
|
* @brief Define a system initialization function which will be executed on the specified cores
|
|
|
|
*
|
|
|
|
* @param f function name (identifier)
|
2023-11-24 12:32:37 -05:00
|
|
|
* @param stage_ init stage name (CORE or SECONDARY)
|
2022-05-17 17:42:54 -04:00
|
|
|
* @param c bit mask of cores to execute the function on (ex. if BIT0 is set, the function
|
|
|
|
* will be executed on CPU 0, if BIT1 is set - on CPU 1, and so on)
|
|
|
|
* @param priority integer, priority of the initialization function. Higher values mean that
|
|
|
|
* the function will be executed later in the process.
|
|
|
|
* @param (varargs) optional, additional attributes for the function declaration (such as IRAM_ATTR)
|
|
|
|
*
|
|
|
|
* The function defined using this macro must return ESP_OK on success. Any other value will be
|
|
|
|
* logged and the startup process will abort.
|
2020-11-10 02:40:01 -05:00
|
|
|
*
|
2022-05-17 17:42:54 -04:00
|
|
|
* Initialization functions should be placed in a compilation unit where at least one other
|
|
|
|
* symbol is referenced in another compilation unit. This means that the reference should not itself
|
|
|
|
* get optimized out by the compiler or discarded by the linker if the related feature is used.
|
|
|
|
* It is, on the other hand, a good practice to make sure the initialization function does get
|
|
|
|
* discarded if the related feature is not used.
|
2020-02-05 06:57:40 -05:00
|
|
|
*/
|
2023-11-24 12:32:37 -05:00
|
|
|
#define ESP_SYSTEM_INIT_FN(f, stage_, c, priority, ...) \
|
2022-05-17 17:42:54 -04:00
|
|
|
static esp_err_t __VA_ARGS__ __esp_system_init_fn_##f(void); \
|
|
|
|
static __attribute__((used)) _SECTION_ATTR_IMPL(".esp_system_init_fn", priority) \
|
2023-11-24 12:32:37 -05:00
|
|
|
esp_system_init_fn_t esp_system_init_fn_##f = { \
|
|
|
|
.fn = ( __esp_system_init_fn_##f), \
|
|
|
|
.cores = (c), \
|
|
|
|
.stage = ESP_SYSTEM_INIT_STAGE_##stage_ \
|
|
|
|
}; \
|
2022-05-17 17:42:54 -04:00
|
|
|
static esp_err_t __esp_system_init_fn_##f(void)
|
|
|
|
|
|
|
|
#ifdef CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
#define ESP_SYSTEM_INIT_ALL_CORES BIT(0)
|
|
|
|
#else
|
|
|
|
#define ESP_SYSTEM_INIT_ALL_CORES (BIT(SOC_CPU_CORES_NUM) - 1)
|
|
|
|
#endif
|
2020-02-05 06:57:40 -05:00
|
|
|
|
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
|
2024-01-29 20:40:10 -05: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-06-23 04:46:06 -04:00
|
|
|
|
2020-02-16 08:29:29 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|