1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-01 03:26:58 +03:00

Move continuation stack from .bss onto sys stack (#4622)

This commit is contained in:
Ivan Grokhotkov
2018-04-18 11:19:49 +08:00
committed by GitHub
parent 16a4f22194
commit 5d5ea92a4d
9 changed files with 70 additions and 69 deletions

View File

@ -37,11 +37,30 @@ extern "C" {
#define LOOP_TASK_PRIORITY 1
#define LOOP_QUEUE_SIZE 1
#define OPTIMISTIC_YIELD_TIME_US 16000
extern "C" void call_user_start();
extern void loop();
extern void setup();
extern void (*__init_array_start)(void);
extern void (*__init_array_end)(void);
/* Not static, used in Esp.cpp */
struct rst_info resetInfo;
/* Not static, used in core_esp8266_postmortem.c.
* Placed into noinit section because we assign value to this variable
* before .bss is zero-filled, and need to preserve the value.
*/
cont_t* g_pcont __attribute__((section(".noinit")));
/* Event queue used by the main (arduino) task */
static os_event_t s_loop_queue[LOOP_QUEUE_SIZE];
/* Used to implement optimistic_yield */
static uint32_t s_micros_at_task_start;
extern "C" {
extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER;
const char* core_release =
@ -52,19 +71,10 @@ const char* core_release =
#endif
} // extern "C"
int atexit(void (*func)()) {
(void) func;
return 0;
}
extern "C" void ets_update_cpu_frequency(int freqmhz);
void initVariant() __attribute__((weak));
void initVariant() {
}
extern void loop();
extern void setup();
void preloop_update_frequency() __attribute__((weak));
void preloop_update_frequency() {
#if defined(F_CPU) && (F_CPU == 160000000L)
@ -73,17 +83,10 @@ void preloop_update_frequency() {
#endif
}
extern void (*__init_array_start)(void);
extern void (*__init_array_end)(void);
cont_t g_cont __attribute__ ((aligned (16)));
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
static uint32_t g_micros_at_task_start;
extern "C" void esp_yield() {
if (cont_can_yield(&g_cont)) {
cont_yield(&g_cont);
if (cont_can_yield(g_pcont)) {
cont_yield(g_pcont);
}
}
@ -92,7 +95,7 @@ extern "C" void esp_schedule() {
}
extern "C" void __yield() {
if (cont_can_yield(&g_cont)) {
if (cont_can_yield(g_pcont)) {
esp_schedule();
esp_yield();
}
@ -104,8 +107,8 @@ extern "C" void __yield() {
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
extern "C" void optimistic_yield(uint32_t interval_us) {
if (cont_can_yield(&g_cont) &&
(system_get_time() - g_micros_at_task_start) > interval_us)
if (cont_can_yield(g_pcont) &&
(system_get_time() - s_micros_at_task_start) > interval_us)
{
yield();
}
@ -125,9 +128,9 @@ static void loop_wrapper() {
static void loop_task(os_event_t *events) {
(void) events;
g_micros_at_task_start = system_get_time();
cont_run(&g_cont, &loop_wrapper);
if (cont_check(&g_cont) != 0) {
s_micros_at_task_start = system_get_time();
cont_run(g_pcont, &loop_wrapper);
if (cont_check(g_pcont) != 0) {
panic();
}
}
@ -145,6 +148,22 @@ void init_done() {
esp_schedule();
}
/* This is the entry point of the application.
* It gets called on the default stack, which grows down from the top
* of DRAM area.
* .bss has not been zeroed out yet, but .data and .rodata are in place.
* Cache is not enabled, so only ROM and IRAM functions can be called.
* Peripherals (except for SPI0 and UART0) are not initialized.
* This function does not return.
*/
extern "C" void ICACHE_RAM_ATTR app_entry(void)
{
/* Allocate continuation context on this stack, and save pointer to it. */
cont_t s_cont __attribute__((aligned(16)));
g_pcont = &s_cont;
/* Call the entry point of the SDK code. */
call_user_start();
}
extern "C" void user_init(void) {
struct rst_info *rtc_info_ptr = system_get_rst_info();
@ -156,10 +175,10 @@ extern "C" void user_init(void) {
initVariant();
cont_init(&g_cont);
cont_init(g_pcont);
ets_task(loop_task,
LOOP_TASK_PRIORITY, g_loop_queue,
LOOP_TASK_PRIORITY, s_loop_queue,
LOOP_QUEUE_SIZE);
system_init_done_cb(&init_done);