mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Implement global init for esp8266
This commit is contained in:
parent
c55b5a89eb
commit
e199fc349c
@ -17,19 +17,29 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include "ets_sys.h"
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
|
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
|
||||||
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
|
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
|
||||||
|
|
||||||
|
extern "C" void abort()
|
||||||
|
{
|
||||||
|
os_printf(" x_x ");
|
||||||
|
while(true){}
|
||||||
|
}
|
||||||
|
|
||||||
void __cxa_pure_virtual(void) {
|
void __cxa_pure_virtual(void) {
|
||||||
// We might want to write some diagnostics to uart in this case
|
// We might want to write some diagnostics to uart in this case
|
||||||
//std::terminate();
|
//std::terminate();
|
||||||
while(true) {}
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __cxa_deleted_virtual(void) {
|
void __cxa_deleted_virtual(void) {
|
||||||
// We might want to write some diagnostics to uart in this case
|
// We might want to write some diagnostics to uart in this case
|
||||||
//std::terminate();
|
//std::terminate();
|
||||||
while(true) {}
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ extern "C" {
|
|||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
|
#include "cont.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
//Declared weak in Arduino.h to allow user redefinitions.
|
//Declared weak in Arduino.h to allow user redefinitions.
|
||||||
@ -40,29 +41,74 @@ extern void setup();
|
|||||||
#define LOOP_TASK_PRIORITY 0
|
#define LOOP_TASK_PRIORITY 0
|
||||||
#define LOOP_QUEUE_SIZE 1
|
#define LOOP_QUEUE_SIZE 1
|
||||||
|
|
||||||
|
cont_t g_cont;
|
||||||
|
|
||||||
os_event_t loop_queue[LOOP_QUEUE_SIZE];
|
os_event_t loop_queue[LOOP_QUEUE_SIZE];
|
||||||
|
|
||||||
void loop_task(os_event_t *events)
|
bool g_setup_done = false;
|
||||||
|
|
||||||
|
extern "C" void loop_schedule()
|
||||||
{
|
{
|
||||||
loop();
|
|
||||||
system_os_post(LOOP_TASK_PRIORITY, 0, 0);
|
system_os_post(LOOP_TASK_PRIORITY, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void loop_wrapper()
|
||||||
|
{
|
||||||
|
if (!g_setup_done)
|
||||||
|
{
|
||||||
|
g_setup_done = true;
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
loop();
|
||||||
|
loop_schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void loop_task(os_event_t *events)
|
||||||
|
{
|
||||||
|
cont_run(&g_cont, &loop_wrapper);
|
||||||
|
if (cont_check(&g_cont) != 0)
|
||||||
|
{
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void (*__init_array_start)(void);
|
||||||
|
extern void (*__init_array_end)(void);
|
||||||
|
|
||||||
|
static void do_global_ctors(void)
|
||||||
|
{
|
||||||
|
void (**p)(void);
|
||||||
|
for (p = &__init_array_start; p != &__init_array_end; ++p)
|
||||||
|
(*p)();
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_done()
|
||||||
|
{
|
||||||
|
loop_schedule();
|
||||||
|
|
||||||
|
int i = ((char*)__init_array_end) - (char*)__init_array_start;
|
||||||
|
os_printf("\r\nInit array size: %d\r\n", i);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void user_init(void)
|
void user_init(void)
|
||||||
{
|
{
|
||||||
|
do_global_ctors();
|
||||||
|
uart_div_modify(0, UART_CLK_FREQ / (115200));
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
initVariant();
|
initVariant();
|
||||||
|
|
||||||
|
cont_init(&g_cont);
|
||||||
|
|
||||||
system_os_task( loop_task,
|
system_os_task( loop_task,
|
||||||
LOOP_TASK_PRIORITY,
|
LOOP_TASK_PRIORITY,
|
||||||
loop_queue,
|
loop_queue,
|
||||||
LOOP_QUEUE_SIZE);
|
LOOP_QUEUE_SIZE);
|
||||||
setup();
|
|
||||||
loop_task(0);
|
system_init_done_cb(&init_done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user