mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-05 12:42:22 +03:00
Allman now (#6080)
* switch restyle script for CI * remove confirmation * restyle with allman
This commit is contained in:
committed by
david gauchard
parent
625c3a62c4
commit
98125f8860
@ -1,24 +1,24 @@
|
||||
/*
|
||||
main.cpp - platform initialization and context switching
|
||||
emulation
|
||||
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.
|
||||
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
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
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
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//This may be used to change user task stack size:
|
||||
//#define CONT_STACKSIZE 4096
|
||||
@ -48,10 +48,10 @@ extern void (*__init_array_end)(void);
|
||||
/* Not static, used in Esp.cpp */
|
||||
struct rst_info resetInfo;
|
||||
|
||||
/* Not static, used in core_esp8266_postmortem.c and other places.
|
||||
* Placed into noinit section because we assign value to this variable
|
||||
* before .bss is zero-filled, and need to preserve the value.
|
||||
*/
|
||||
/* Not static, used in core_esp8266_postmortem.c and other places.
|
||||
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 */
|
||||
@ -62,21 +62,23 @@ 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 =
|
||||
extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER;
|
||||
const char* core_release =
|
||||
#ifdef ARDUINO_ESP8266_RELEASE
|
||||
ARDUINO_ESP8266_RELEASE;
|
||||
ARDUINO_ESP8266_RELEASE;
|
||||
#else
|
||||
NULL;
|
||||
NULL;
|
||||
#endif
|
||||
} // extern "C"
|
||||
|
||||
void initVariant() __attribute__((weak));
|
||||
void initVariant() {
|
||||
void initVariant()
|
||||
{
|
||||
}
|
||||
|
||||
void preloop_update_frequency() __attribute__((weak));
|
||||
void preloop_update_frequency() {
|
||||
void preloop_update_frequency()
|
||||
{
|
||||
#if defined(F_CPU) && (F_CPU == 160000000L)
|
||||
REG_SET_BIT(0x3ff00014, BIT(0));
|
||||
ets_update_cpu_frequency(160);
|
||||
@ -84,40 +86,49 @@ void preloop_update_frequency() {
|
||||
}
|
||||
|
||||
|
||||
extern "C" void esp_yield() {
|
||||
if (cont_can_yield(g_pcont)) {
|
||||
extern "C" void esp_yield()
|
||||
{
|
||||
if (cont_can_yield(g_pcont))
|
||||
{
|
||||
cont_yield(g_pcont);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void esp_schedule() {
|
||||
extern "C" void esp_schedule()
|
||||
{
|
||||
ets_post(LOOP_TASK_PRIORITY, 0, 0);
|
||||
}
|
||||
|
||||
extern "C" void __yield() {
|
||||
if (cont_can_yield(g_pcont)) {
|
||||
extern "C" void __yield()
|
||||
{
|
||||
if (cont_can_yield(g_pcont))
|
||||
{
|
||||
esp_schedule();
|
||||
esp_yield();
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
panic();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
|
||||
extern "C" void yield(void) __attribute__((weak, alias("__yield")));
|
||||
|
||||
extern "C" void optimistic_yield(uint32_t interval_us) {
|
||||
extern "C" void optimistic_yield(uint32_t interval_us)
|
||||
{
|
||||
if (cont_can_yield(g_pcont) &&
|
||||
(system_get_time() - s_micros_at_task_start) > interval_us)
|
||||
(system_get_time() - s_micros_at_task_start) > interval_us)
|
||||
{
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void loop_wrapper() {
|
||||
static void loop_wrapper()
|
||||
{
|
||||
static bool setup_done = false;
|
||||
preloop_update_frequency();
|
||||
if(!setup_done) {
|
||||
if (!setup_done)
|
||||
{
|
||||
setup();
|
||||
setup_done = true;
|
||||
}
|
||||
@ -126,56 +137,72 @@ static void loop_wrapper() {
|
||||
esp_schedule();
|
||||
}
|
||||
|
||||
static void loop_task(os_event_t *events) {
|
||||
static void loop_task(os_event_t *events)
|
||||
{
|
||||
(void) events;
|
||||
s_micros_at_task_start = system_get_time();
|
||||
cont_run(g_pcont, &loop_wrapper);
|
||||
if (cont_check(g_pcont) != 0) {
|
||||
if (cont_check(g_pcont) != 0)
|
||||
{
|
||||
panic();
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
|
||||
struct object { long placeholder[ 10 ]; };
|
||||
void __register_frame_info (const void *begin, struct object *ob);
|
||||
extern char __eh_frame[];
|
||||
struct object
|
||||
{
|
||||
long placeholder[ 10 ];
|
||||
};
|
||||
void __register_frame_info(const void *begin, struct object *ob);
|
||||
extern char __eh_frame[];
|
||||
}
|
||||
|
||||
static void do_global_ctors(void) {
|
||||
static void do_global_ctors(void)
|
||||
{
|
||||
static struct object ob;
|
||||
__register_frame_info( __eh_frame, &ob );
|
||||
__register_frame_info(__eh_frame, &ob);
|
||||
|
||||
void (**p)(void) = &__init_array_end;
|
||||
while (p != &__init_array_start)
|
||||
{
|
||||
(*--p)();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
extern void __unhandled_exception(const char *str);
|
||||
extern void __unhandled_exception(const char *str);
|
||||
|
||||
static void __unhandled_exception_cpp()
|
||||
{
|
||||
static void __unhandled_exception_cpp()
|
||||
{
|
||||
#ifndef __EXCEPTIONS
|
||||
abort();
|
||||
#else
|
||||
static bool terminating;
|
||||
if (terminating)
|
||||
abort();
|
||||
terminating = true;
|
||||
/* Use a trick from vterminate.cc to get any std::exception what() */
|
||||
try {
|
||||
__throw_exception_again;
|
||||
} catch (const std::exception& e) {
|
||||
__unhandled_exception( e.what() );
|
||||
} catch (...) {
|
||||
__unhandled_exception( "" );
|
||||
}
|
||||
#else
|
||||
static bool terminating;
|
||||
if (terminating)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
terminating = true;
|
||||
/* Use a trick from vterminate.cc to get any std::exception what() */
|
||||
try
|
||||
{
|
||||
__throw_exception_again;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
__unhandled_exception(e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
__unhandled_exception("");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void init_done() {
|
||||
void init_done()
|
||||
{
|
||||
system_set_os_print(1);
|
||||
gdb_init();
|
||||
std::set_terminate(__unhandled_exception_cpp);
|
||||
@ -183,56 +210,56 @@ 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.
|
||||
*/
|
||||
/* 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.
|
||||
*/
|
||||
/*
|
||||
A bit of explanation for this entry point:
|
||||
A bit of explanation for this entry point:
|
||||
|
||||
SYS is the SDK task/context used by the upperlying system to run its
|
||||
administrative tasks (at least WLAN and lwip's receive callbacks and
|
||||
Ticker). NONOS-SDK is designed to run user's non-threaded code in
|
||||
another specific task/context with its own stack in BSS.
|
||||
SYS is the SDK task/context used by the upperlying system to run its
|
||||
administrative tasks (at least WLAN and lwip's receive callbacks and
|
||||
Ticker). NONOS-SDK is designed to run user's non-threaded code in
|
||||
another specific task/context with its own stack in BSS.
|
||||
|
||||
Some clever fellows found that the SYS stack was a large and quite unused
|
||||
piece of ram that we could use for the user's stack instead of using user's
|
||||
main memory, thus saving around 4KB on ram/heap.
|
||||
Some clever fellows found that the SYS stack was a large and quite unused
|
||||
piece of ram that we could use for the user's stack instead of using user's
|
||||
main memory, thus saving around 4KB on ram/heap.
|
||||
|
||||
A problem arose later, which is that this stack can heavily be used by
|
||||
the SDK for some features. One of these features is WPS. We still don't
|
||||
know if other features are using this, or if this memory is going to be
|
||||
used in future SDK releases.
|
||||
A problem arose later, which is that this stack can heavily be used by
|
||||
the SDK for some features. One of these features is WPS. We still don't
|
||||
know if other features are using this, or if this memory is going to be
|
||||
used in future SDK releases.
|
||||
|
||||
WPS beeing flawed by its poor security, or not beeing used by lots of
|
||||
users, it has been decided that we are still going to use that memory for
|
||||
user's stack and disable the use of WPS.
|
||||
WPS beeing flawed by its poor security, or not beeing used by lots of
|
||||
users, it has been decided that we are still going to use that memory for
|
||||
user's stack and disable the use of WPS.
|
||||
|
||||
app_entry() jumps to app_entry_custom() defined as "weakref" calling
|
||||
itself a weak customizable function, allowing to use another one when
|
||||
this is required (see core_esp8266_app_entry_noextra4k.cpp, used by WPS).
|
||||
app_entry() jumps to app_entry_custom() defined as "weakref" calling
|
||||
itself a weak customizable function, allowing to use another one when
|
||||
this is required (see core_esp8266_app_entry_noextra4k.cpp, used by WPS).
|
||||
|
||||
(note: setting app_entry() itself as "weak" is not sufficient and always
|
||||
(note: setting app_entry() itself as "weak" is not sufficient and always
|
||||
ends up with the other "noextra4k" one linked, maybe because it has a
|
||||
default ENTRY(app_entry) value in linker scripts).
|
||||
|
||||
References:
|
||||
https://github.com/esp8266/Arduino/pull/4553
|
||||
https://github.com/esp8266/Arduino/pull/4622
|
||||
https://github.com/esp8266/Arduino/issues/4779
|
||||
https://github.com/esp8266/Arduino/pull/4889
|
||||
References:
|
||||
https://github.com/esp8266/Arduino/pull/4553
|
||||
https://github.com/esp8266/Arduino/pull/4622
|
||||
https://github.com/esp8266/Arduino/issues/4779
|
||||
https://github.com/esp8266/Arduino/pull/4889
|
||||
|
||||
*/
|
||||
|
||||
extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) __attribute__((weak));
|
||||
extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void)
|
||||
{
|
||||
/* Allocate continuation context on this SYS stack,
|
||||
and save pointer to it. */
|
||||
/* Allocate continuation context on this SYS stack,
|
||||
and save pointer to it. */
|
||||
cont_t s_cont __attribute__((aligned(16)));
|
||||
g_pcont = &s_cont;
|
||||
|
||||
@ -240,20 +267,21 @@ extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void)
|
||||
call_user_start();
|
||||
}
|
||||
|
||||
static void ICACHE_RAM_ATTR app_entry_custom (void) __attribute__((weakref("app_entry_redefinable")));
|
||||
static void ICACHE_RAM_ATTR app_entry_custom(void) __attribute__((weakref("app_entry_redefinable")));
|
||||
|
||||
extern "C" void ICACHE_RAM_ATTR app_entry (void)
|
||||
extern "C" void ICACHE_RAM_ATTR app_entry(void)
|
||||
{
|
||||
return app_entry_custom();
|
||||
}
|
||||
|
||||
extern "C" void preinit (void) __attribute__((weak));
|
||||
extern "C" void preinit (void)
|
||||
extern "C" void preinit(void) __attribute__((weak));
|
||||
extern "C" void preinit(void)
|
||||
{
|
||||
/* do nothing by default */
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
@ -268,8 +296,8 @@ extern "C" void user_init(void) {
|
||||
preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable.
|
||||
|
||||
ets_task(loop_task,
|
||||
LOOP_TASK_PRIORITY, s_loop_queue,
|
||||
LOOP_QUEUE_SIZE);
|
||||
LOOP_TASK_PRIORITY, s_loop_queue,
|
||||
LOOP_QUEUE_SIZE);
|
||||
|
||||
system_init_done_cb(&init_done);
|
||||
}
|
||||
|
Reference in New Issue
Block a user