File tree 4 files changed +26
-5
lines changed
4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,16 @@ void ets_intr_unlock();
165
165
#define interrupts () xt_rsil(0 )
166
166
#define noInterrupts () xt_rsil(15 )
167
167
168
+ #define lockEnterVar (varSave, level ) __asm__ __volatile__ (" rsil %0," __STRINGIFY(level) : "=a" (varSave))
169
+ #define lockLeaveVar (varSave ) __asm__ __volatile__ (" wsr %0,ps; isync" :: " a" (varSave) : "memory")
170
+
171
+ #define lockDeclM () uint32_t intrState
172
+ #define lockEnterM () lockEnterVar(intrState, 0 )
173
+ #define lockLeaveM () lockLeaveVar(intrState)
174
+
175
+ #define lockEnter () lockDeclM(); lockEnterM()
176
+ #define lockLeave () lockLeaveM()
177
+
168
178
#define clockCyclesPerMicrosecond () ( F_CPU / 1000000L )
169
179
#define clockCyclesToMicroseconds (a ) ( (a) / clockCyclesPerMicrosecond() )
170
180
#define microsecondsToClockCycles (a ) ( (a) * clockCyclesPerMicrosecond () )
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ static scheduled_fn_t* sFirstUnused = 0;
17
17
18
18
static int sCount = 0 ;
19
19
20
+ IRAM_ATTR
20
21
static scheduled_fn_t * get_fn () {
21
22
scheduled_fn_t * result = NULL ;
22
23
// try to get an item from unused items list
@@ -39,24 +40,28 @@ static void recycle_fn(scheduled_fn_t* fn)
39
40
sFirstUnused = fn;
40
41
}
41
42
43
+ IRAM_ATTR
42
44
bool schedule_function_us (mFuncT fn, uint32_t repeat_us)
43
45
{
46
+ lockEnter ();
47
+
44
48
scheduled_fn_t * item = get_fn ();
45
49
if (!item) {
50
+ lockLeave ();
46
51
return false ;
47
52
}
48
53
item->mFunc = fn;
49
-
50
- uint32_t savedPS = xt_rsil (0 ); // noInterrupts();
51
54
item->mNext = sFirst ;
52
55
sFirst = item;
53
- xt_wsr_ps (savedPS); // interrupts();
54
56
55
57
if (repeat_us)
56
58
item->callNow .reset (repeat_us);
59
+
60
+ lockLeave ();
57
61
return true ;
58
62
}
59
63
64
+ IRAM_ATTR
60
65
bool schedule_function (std::function<void (void )> fn)
61
66
{
62
67
return schedule_function_us ([&fn](){ fn (); return false ; }, 0 );
@@ -70,10 +75,10 @@ void run_scheduled_functions()
70
75
toCall = item->mNext ;
71
76
if (item->callNow && !item->mFunc ())
72
77
{
73
- uint32_t savedPS = xt_rsil ( 0 ); // noInterrupts ();
78
+ lockEnter ();
74
79
if (sFirst == item)
75
80
sFirst = item->mNext ;
76
- xt_wsr_ps (savedPS); // interrupts ();
81
+ lockLeave ();
77
82
78
83
item->mFunc = mFuncT ();
79
84
recycle_fn (item);
Original file line number Diff line number Diff line change @@ -102,6 +102,9 @@ typedef enum {
102
102
#define ICACHE_RODATA_ATTR
103
103
#endif /* ICACHE_FLASH */
104
104
105
+ // counterpart https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp8266-compat.h
106
+ #define IRAM_ATTR ICACHE_RAM_ATTR
107
+
105
108
#define STORE_ATTR __attribute__((aligned(4)))
106
109
107
110
#ifndef __cplusplus
Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ typedef enum {
93
93
#define ICACHE_RAM_ATTR
94
94
#endif /* ICACHE_FLASH */
95
95
96
+ // counterpart https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp8266-compat.h
97
+ #define IRAM_ATTR ICACHE_RAM_ATTR
98
+
96
99
#define STORE_ATTR __attribute__((aligned(4)))
97
100
98
101
#ifndef __cplusplus
You can’t perform that action at this time.
0 commit comments