@@ -37,11 +37,30 @@ extern "C" {
37
37
38
38
#define LOOP_TASK_PRIORITY 1
39
39
#define LOOP_QUEUE_SIZE 1
40
-
41
40
#define OPTIMISTIC_YIELD_TIME_US 16000
42
41
42
+ extern " C" void call_user_start ();
43
+ extern void loop ();
44
+ extern void setup ();
45
+ extern void (*__init_array_start)(void );
46
+ extern void (*__init_array_end)(void );
47
+
48
+ /* Not static, used in Esp.cpp */
43
49
struct rst_info resetInfo;
44
50
51
+ /* Not static, used in core_esp8266_postmortem.c.
52
+ * Placed into noinit section because we assign value to this variable
53
+ * before .bss is zero-filled, and need to preserve the value.
54
+ */
55
+ cont_t * g_pcont __attribute__ ((section(" .noinit" )));
56
+
57
+ /* Event queue used by the main (arduino) task */
58
+ static os_event_t s_loop_queue[LOOP_QUEUE_SIZE];
59
+
60
+ /* Used to implement optimistic_yield */
61
+ static uint32_t s_micros_at_task_start;
62
+
63
+
45
64
extern " C" {
46
65
extern const uint32_t __attribute__ ((section(" .ver_number" ))) core_version = ARDUINO_ESP8266_GIT_VER;
47
66
const char * core_release =
@@ -52,19 +71,10 @@ const char* core_release =
52
71
#endif
53
72
} // extern "C"
54
73
55
- int atexit (void (*func)()) {
56
- (void ) func;
57
- return 0 ;
58
- }
59
-
60
- extern " C" void ets_update_cpu_frequency (int freqmhz);
61
74
void initVariant () __attribute__((weak));
62
75
void initVariant () {
63
76
}
64
77
65
- extern void loop ();
66
- extern void setup ();
67
-
68
78
void preloop_update_frequency () __attribute__((weak));
69
79
void preloop_update_frequency () {
70
80
#if defined(F_CPU) && (F_CPU == 160000000L)
@@ -73,17 +83,10 @@ void preloop_update_frequency() {
73
83
#endif
74
84
}
75
85
76
- extern void (*__init_array_start)(void );
77
- extern void (*__init_array_end)(void );
78
-
79
- cont_t g_cont __attribute__ ((aligned (16 )));
80
- static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
81
-
82
- static uint32_t g_micros_at_task_start;
83
86
84
87
extern " C" void esp_yield () {
85
- if (cont_can_yield (&g_cont )) {
86
- cont_yield (&g_cont );
88
+ if (cont_can_yield (g_pcont )) {
89
+ cont_yield (g_pcont );
87
90
}
88
91
}
89
92
@@ -92,7 +95,7 @@ extern "C" void esp_schedule() {
92
95
}
93
96
94
97
extern " C" void __yield () {
95
- if (cont_can_yield (&g_cont )) {
98
+ if (cont_can_yield (g_pcont )) {
96
99
esp_schedule ();
97
100
esp_yield ();
98
101
}
@@ -104,8 +107,8 @@ extern "C" void __yield() {
104
107
extern " C" void yield (void ) __attribute__ ((weak, alias(" __yield" )));
105
108
106
109
extern " C" void optimistic_yield (uint32_t interval_us) {
107
- if (cont_can_yield (&g_cont ) &&
108
- (system_get_time () - g_micros_at_task_start ) > interval_us)
110
+ if (cont_can_yield (g_pcont ) &&
111
+ (system_get_time () - s_micros_at_task_start ) > interval_us)
109
112
{
110
113
yield ();
111
114
}
@@ -125,9 +128,9 @@ static void loop_wrapper() {
125
128
126
129
static void loop_task (os_event_t *events) {
127
130
(void ) events;
128
- g_micros_at_task_start = system_get_time ();
129
- cont_run (&g_cont , &loop_wrapper);
130
- if (cont_check (&g_cont ) != 0 ) {
131
+ s_micros_at_task_start = system_get_time ();
132
+ cont_run (g_pcont , &loop_wrapper);
133
+ if (cont_check (g_pcont ) != 0 ) {
131
134
panic ();
132
135
}
133
136
}
@@ -145,6 +148,22 @@ void init_done() {
145
148
esp_schedule ();
146
149
}
147
150
151
+ /* This is the entry point of the application.
152
+ * It gets called on the default stack, which grows down from the top
153
+ * of DRAM area.
154
+ * .bss has not been zeroed out yet, but .data and .rodata are in place.
155
+ * Cache is not enabled, so only ROM and IRAM functions can be called.
156
+ * Peripherals (except for SPI0 and UART0) are not initialized.
157
+ * This function does not return.
158
+ */
159
+ extern " C" void ICACHE_RAM_ATTR app_entry (void )
160
+ {
161
+ /* Allocate continuation context on this stack, and save pointer to it. */
162
+ cont_t s_cont __attribute__ ((aligned (16 )));
163
+ g_pcont = &s_cont;
164
+ /* Call the entry point of the SDK code. */
165
+ call_user_start ();
166
+ }
148
167
149
168
extern " C" void user_init (void ) {
150
169
struct rst_info *rtc_info_ptr = system_get_rst_info ();
@@ -156,10 +175,10 @@ extern "C" void user_init(void) {
156
175
157
176
initVariant ();
158
177
159
- cont_init (&g_cont );
178
+ cont_init (g_pcont );
160
179
161
180
ets_task (loop_task,
162
- LOOP_TASK_PRIORITY, g_loop_queue ,
181
+ LOOP_TASK_PRIORITY, s_loop_queue ,
163
182
LOOP_QUEUE_SIZE);
164
183
165
184
system_init_done_cb (&init_done);
0 commit comments