mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-01 03:26:58 +03:00
Pass timeout to optimistic_yield, add cont_can_yield check
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
/*
|
||||
/*
|
||||
main.cpp - platform initialization and context switching
|
||||
emulation
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
@ -64,16 +64,16 @@ 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_last_task_yield;
|
||||
static uint32_t g_micros_at_task_start;
|
||||
|
||||
|
||||
extern "C" void abort() {
|
||||
while(1) {
|
||||
}
|
||||
do {
|
||||
*((int*)0) = 0;
|
||||
} while(true);
|
||||
}
|
||||
|
||||
extern "C" void esp_yield() {
|
||||
g_micros_at_last_task_yield = system_get_time();
|
||||
cont_yield(&g_cont);
|
||||
}
|
||||
|
||||
@ -82,16 +82,22 @@ extern "C" void esp_schedule() {
|
||||
}
|
||||
|
||||
extern "C" void __yield() {
|
||||
esp_schedule();
|
||||
esp_yield();
|
||||
if (cont_can_yield(&g_cont)) {
|
||||
esp_schedule();
|
||||
esp_yield();
|
||||
}
|
||||
else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
|
||||
|
||||
extern "C" void optimistic_yield(void) {
|
||||
if (!ETS_INTR_WITHINISR() &&
|
||||
(system_get_time() - g_micros_at_last_task_yield) > OPTIMISTIC_YIELD_TIME_US)
|
||||
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)
|
||||
{
|
||||
__yield();
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,10 +113,10 @@ static void loop_wrapper() {
|
||||
}
|
||||
|
||||
static void loop_task(os_event_t *events) {
|
||||
g_micros_at_last_task_yield = system_get_time();
|
||||
g_micros_at_task_start = system_get_time();
|
||||
cont_run(&g_cont, &loop_wrapper);
|
||||
if(cont_check(&g_cont) != 0) {
|
||||
ets_printf("\r\nheap collided with sketch stack\r\n");
|
||||
ets_printf("\r\nsketch stack overflow detected\r\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
@ -127,13 +133,11 @@ void init_done() {
|
||||
esp_schedule();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void user_init(void) {
|
||||
|
||||
extern "C" void user_init(void) {
|
||||
struct rst_info *rtc_info_ptr = system_get_rst_info();
|
||||
|
||||
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
|
||||
|
||||
|
||||
uart_div_modify(0, UART_CLK_FREQ / (115200));
|
||||
|
||||
init();
|
||||
@ -143,10 +147,8 @@ void user_init(void) {
|
||||
cont_init(&g_cont);
|
||||
|
||||
system_os_task(loop_task,
|
||||
LOOP_TASK_PRIORITY, g_loop_queue,
|
||||
LOOP_QUEUE_SIZE);
|
||||
LOOP_TASK_PRIORITY, g_loop_queue,
|
||||
LOOP_QUEUE_SIZE);
|
||||
|
||||
system_init_done_cb(&init_done);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user