1
1
2
+ // This may be used to change user task stack size:
3
+ // #define CONT_STACKSIZE 4096
4
+ #include " Schedule.h"
2
5
extern " C" {
3
6
#include " ets_sys.h"
4
7
#include " os_type.h"
@@ -7,129 +10,137 @@ extern "C" {
7
10
#include " user_interface.h"
8
11
#include " cont.h"
9
12
}
13
+ #include < core_version.h>
10
14
11
- #define LOOP_TASK_PRIORITY 0
15
+ #define LOOP_TASK_PRIORITY 1
12
16
#define LOOP_QUEUE_SIZE 1
13
17
14
18
#define OPTIMISTIC_YIELD_TIME_US 16000
15
19
16
20
struct rst_info resetInfo;
17
21
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)()) {
19
33
(void )func;
20
- return 0 ;
34
+ return 0 ;
21
35
}
22
36
23
37
extern " C" void ets_update_cpu_frequency (int freqmhz);
24
38
void initVariant () __attribute__((weak));
25
39
void initVariant () {
26
40
}
27
41
28
-
29
-
30
42
void preloop_update_frequency () __attribute__((weak));
31
43
void preloop_update_frequency () {
32
44
#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 );
35
47
#endif
36
48
}
37
49
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 );
40
52
41
- cont_t g_cont __attribute__ ((aligned (16 )));
53
+ cont_t g_cont __attribute__ ((aligned(16 )));
42
54
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
43
55
44
56
static uint32_t g_micros_at_task_start;
45
57
46
- /*
47
- extern "C" void abort() {
48
- do {
49
- *((int*)0) = 0;
50
- } while(true);
51
- }*/
52
-
53
58
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
+ }
57
62
}
58
63
59
64
extern " C" void esp_schedule () {
60
- system_os_post (LOOP_TASK_PRIORITY, 0 , 0 );
65
+ ets_post (LOOP_TASK_PRIORITY, 0 , 0 );
61
66
}
62
67
63
68
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
+ }
71
76
}
72
77
73
- extern " C" void yield (void ) __attribute__ ((weak, alias(" __yield" )));
78
+ extern " C" void yield (void ) __attribute__((weak, alias(" __yield" )));
74
79
75
80
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
+ }
81
86
}
82
87
83
88
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 ();
93
98
}
94
99
95
100
static void loop_task (os_event_t *events) {
96
101
(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\n sketch 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
+ }
103
107
}
104
108
105
109
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)();
109
113
}
110
114
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
+
111
121
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 ();
115
126
}
116
127
117
128
118
129
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));
121
132
122
- uart_div_modify (0 , UART_CLK_FREQ / (115200 ));
133
+ uart_div_modify (0 , UART_CLK_FREQ / (115200 ));
123
134
124
- init ();
135
+ init ();
125
136
126
- initVariant ();
137
+ initVariant ();
127
138
128
- cont_init (&g_cont);
139
+ cont_init (&g_cont);
129
140
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);
133
144
134
- system_init_done_cb (&init_done);
135
- }
145
+ system_init_done_cb (&init_done);
146
+ }
0 commit comments