Skip to content

Commit e086ba3

Browse files
authored
Merge pull request #486 from tekka007/ESPCoreFix
Update MyMainESP8266 to compile with ESPlib 2.3.0
2 parents d15b4f6 + 24a0350 commit e086ba3

File tree

2 files changed

+78
-68
lines changed

2 files changed

+78
-68
lines changed

libraries/MySensors/core/MyHwESP8266.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#ifdef __cplusplus
2525
#include <Arduino.h>
26-
//#include <SPI.h>
2726
#endif
2827

2928
#define MY_SERIALDEVICE Serial
@@ -36,7 +35,7 @@
3635
#define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value))
3736
#define hwInit() MY_SERIALDEVICE.begin(MY_BAUD_RATE); MY_SERIALDEVICE.setDebugOutput(true)
3837
#define hwWatchdogReset() wdt_reset()
39-
#define hwReboot() wdt_enable(WDTO_15MS); while (1)
38+
#define hwReboot() ESP.restart();
4039
#define hwMillis() millis()
4140

4241
void hwReadConfigBlock(void* buf, void* adr, size_t length);
Lines changed: 77 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
//This may be used to change user task stack size:
3+
//#define CONT_STACKSIZE 4096
4+
#include "Schedule.h"
25
extern "C" {
36
#include "ets_sys.h"
47
#include "os_type.h"
@@ -7,129 +10,137 @@ extern "C" {
710
#include "user_interface.h"
811
#include "cont.h"
912
}
13+
#include <core_version.h>
1014

11-
#define LOOP_TASK_PRIORITY 0
15+
#define LOOP_TASK_PRIORITY 1
1216
#define LOOP_QUEUE_SIZE 1
1317

1418
#define OPTIMISTIC_YIELD_TIME_US 16000
1519

1620
struct rst_info resetInfo;
1721

18-
int atexit(void (*func)()) {
22+
extern "C" {
23+
extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER;
24+
const char* core_release =
25+
#ifdef ARDUINO_ESP8266_RELEASE
26+
ARDUINO_ESP8266_RELEASE;
27+
#else
28+
NULL;
29+
#endif
30+
} // extern "C"
31+
32+
int atexit(void(*func)()) {
1933
(void)func;
20-
return 0;
34+
return 0;
2135
}
2236

2337
extern "C" void ets_update_cpu_frequency(int freqmhz);
2438
void initVariant() __attribute__((weak));
2539
void initVariant() {
2640
}
2741

28-
29-
3042
void preloop_update_frequency() __attribute__((weak));
3143
void preloop_update_frequency() {
3244
#if defined(F_CPU) && (F_CPU == 160000000L)
33-
REG_SET_BIT(0x3ff00014, BIT(0));
34-
ets_update_cpu_frequency(160);
45+
REG_SET_BIT(0x3ff00014, BIT(0));
46+
ets_update_cpu_frequency(160);
3547
#endif
3648
}
3749

38-
extern void (*__init_array_start)(void);
39-
extern void (*__init_array_end)(void);
50+
extern void(*__init_array_start)(void);
51+
extern void(*__init_array_end)(void);
4052

41-
cont_t g_cont __attribute__ ((aligned (16)));
53+
cont_t g_cont __attribute__((aligned(16)));
4254
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
4355

4456
static uint32_t g_micros_at_task_start;
4557

46-
/*
47-
extern "C" void abort() {
48-
do {
49-
*((int*)0) = 0;
50-
} while(true);
51-
}*/
52-
5358
extern "C" void esp_yield() {
54-
if (cont_can_yield(&g_cont)) {
55-
cont_yield(&g_cont);
56-
}
59+
if (cont_can_yield(&g_cont)) {
60+
cont_yield(&g_cont);
61+
}
5762
}
5863

5964
extern "C" void esp_schedule() {
60-
system_os_post(LOOP_TASK_PRIORITY, 0, 0);
65+
ets_post(LOOP_TASK_PRIORITY, 0, 0);
6166
}
6267

6368
extern "C" void __yield() {
64-
if (cont_can_yield(&g_cont)) {
65-
esp_schedule();
66-
esp_yield();
67-
}
68-
else {
69-
abort();
70-
}
69+
if (cont_can_yield(&g_cont)) {
70+
esp_schedule();
71+
esp_yield();
72+
}
73+
else {
74+
panic();
75+
}
7176
}
7277

73-
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
78+
extern "C" void yield(void) __attribute__((weak, alias("__yield")));
7479

7580
extern "C" void optimistic_yield(uint32_t interval_us) {
76-
if (cont_can_yield(&g_cont) &&
77-
(system_get_time() - g_micros_at_task_start) > interval_us)
78-
{
79-
yield();
80-
}
81+
if (cont_can_yield(&g_cont) &&
82+
(system_get_time() - g_micros_at_task_start) > interval_us)
83+
{
84+
yield();
85+
}
8186
}
8287

8388
static void loop_wrapper() {
84-
static bool setup_done = false;
85-
if(!setup_done) {
86-
_begin(); // Startup MySensors library
87-
setup_done = true;
88-
}
89-
preloop_update_frequency();
90-
_process(); // Process incoming data
91-
loop();
92-
esp_schedule();
89+
static bool setup_done = false;
90+
preloop_update_frequency();
91+
if (!setup_done) {
92+
_begin(); // Startup MySensors library
93+
setup_done = true;
94+
}
95+
_process(); // Process incoming data
96+
run_scheduled_functions();
97+
esp_schedule();
9398
}
9499

95100
static void loop_task(os_event_t *events) {
96101
(void)events;
97-
g_micros_at_task_start = system_get_time();
98-
cont_run(&g_cont, &loop_wrapper);
99-
if(cont_check(&g_cont) != 0) {
100-
ets_printf("\r\nsketch stack overflow detected\r\n");
101-
abort();
102-
}
102+
g_micros_at_task_start = system_get_time();
103+
cont_run(&g_cont, &loop_wrapper);
104+
if (cont_check(&g_cont) != 0) {
105+
panic();
106+
}
103107
}
104108

105109
static void do_global_ctors(void) {
106-
void (**p)(void);
107-
for(p = &__init_array_start; p != &__init_array_end; ++p)
108-
(*p)();
110+
void(**p)(void) = &__init_array_end;
111+
while (p != &__init_array_start)
112+
(*--p)();
109113
}
110114

115+
extern "C" void __gdb_init() {}
116+
extern "C" void gdb_init(void) __attribute__((weak, alias("__gdb_init")));
117+
118+
extern "C" void __gdb_do_break() {}
119+
extern "C" void gdb_do_break(void) __attribute__((weak, alias("__gdb_do_break")));
120+
111121
void init_done() {
112-
system_set_os_print(1);
113-
do_global_ctors();
114-
esp_schedule();
122+
system_set_os_print(1);
123+
gdb_init();
124+
do_global_ctors();
125+
esp_schedule();
115126
}
116127

117128

118129
extern "C" void user_init(void) {
119-
struct rst_info *rtc_info_ptr = system_get_rst_info();
120-
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
130+
struct rst_info *rtc_info_ptr = system_get_rst_info();
131+
memcpy((void *)&resetInfo, (void *)rtc_info_ptr, sizeof(resetInfo));
121132

122-
uart_div_modify(0, UART_CLK_FREQ / (115200));
133+
uart_div_modify(0, UART_CLK_FREQ / (115200));
123134

124-
init();
135+
init();
125136

126-
initVariant();
137+
initVariant();
127138

128-
cont_init(&g_cont);
139+
cont_init(&g_cont);
129140

130-
system_os_task(loop_task,
131-
LOOP_TASK_PRIORITY, g_loop_queue,
132-
LOOP_QUEUE_SIZE);
141+
ets_task(loop_task,
142+
LOOP_TASK_PRIORITY, g_loop_queue,
143+
LOOP_QUEUE_SIZE);
133144

134-
system_init_done_cb(&init_done);
135-
}
145+
system_init_done_cb(&init_done);
146+
}

0 commit comments

Comments
 (0)