Browse Source

Function-style critical section macros

Scott Lahteine 5 years ago
parent
commit
fa6e7cb733

+ 2
- 2
Marlin/src/HAL/HAL_AVR/HAL.h View File

53
 //#define analogInputToDigitalPin(IO) IO
53
 //#define analogInputToDigitalPin(IO) IO
54
 
54
 
55
 #ifndef CRITICAL_SECTION_START
55
 #ifndef CRITICAL_SECTION_START
56
-  #define CRITICAL_SECTION_START  unsigned char _sreg = SREG; cli()
57
-  #define CRITICAL_SECTION_END    SREG = _sreg
56
+  #define CRITICAL_SECTION_START()  unsigned char _sreg = SREG; cli()
57
+  #define CRITICAL_SECTION_END()    SREG = _sreg
58
 #endif
58
 #endif
59
 #define ISRS_ENABLED() TEST(SREG, SREG_I)
59
 #define ISRS_ENABLED() TEST(SREG, SREG_I)
60
 #define ENABLE_ISRS()  sei()
60
 #define ENABLE_ISRS()  sei()

+ 2
- 2
Marlin/src/HAL/HAL_DUE/HAL.h View File

119
 //
119
 //
120
 // Interrupts
120
 // Interrupts
121
 //
121
 //
122
-#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
123
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
122
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_PRIMASK(); __disable_irq()
123
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
124
 #define ISRS_ENABLED() (!__get_PRIMASK())
124
 #define ISRS_ENABLED() (!__get_PRIMASK())
125
 #define ENABLE_ISRS()  __enable_irq()
125
 #define ENABLE_ISRS()  __enable_irq()
126
 #define DISABLE_ISRS() __disable_irq()
126
 #define DISABLE_ISRS() __disable_irq()

+ 4
- 4
Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp View File

63
   memcpy(&ram_tab, romtab, sizeof(ram_tab));
63
   memcpy(&ram_tab, romtab, sizeof(ram_tab));
64
 
64
 
65
   // Disable global interrupts
65
   // Disable global interrupts
66
-  CRITICAL_SECTION_START;
66
+  CRITICAL_SECTION_START();
67
 
67
 
68
   // Set the vector table base address to the SRAM copy
68
   // Set the vector table base address to the SRAM copy
69
   SCB->VTOR = (uint32_t)(&ram_tab);
69
   SCB->VTOR = (uint32_t)(&ram_tab);
70
 
70
 
71
   // Reenable interrupts
71
   // Reenable interrupts
72
-  CRITICAL_SECTION_END;
72
+  CRITICAL_SECTION_END();
73
 
73
 
74
   // Return the address of the table
74
   // Return the address of the table
75
   return (pfnISR_Handler*)(&ram_tab);
75
   return (pfnISR_Handler*)(&ram_tab);
80
   pfnISR_Handler *isrtab = get_relocated_table_addr();
80
   pfnISR_Handler *isrtab = get_relocated_table_addr();
81
 
81
 
82
   // Disable global interrupts
82
   // Disable global interrupts
83
-  CRITICAL_SECTION_START;
83
+  CRITICAL_SECTION_START();
84
 
84
 
85
   // Get the original handler
85
   // Get the original handler
86
   pfnISR_Handler oldHandler = isrtab[irq + 16];
86
   pfnISR_Handler oldHandler = isrtab[irq + 16];
89
   isrtab[irq + 16] = newHandler;
89
   isrtab[irq + 16] = newHandler;
90
 
90
 
91
   // Reenable interrupts
91
   // Reenable interrupts
92
-  CRITICAL_SECTION_END;
92
+  CRITICAL_SECTION_END();
93
 
93
 
94
   // Return the original one
94
   // Return the original one
95
   return oldHandler;
95
   return oldHandler;

+ 2
- 2
Marlin/src/HAL/HAL_ESP32/HAL.h View File

65
   #define NUM_SERIAL 1
65
   #define NUM_SERIAL 1
66
 #endif
66
 #endif
67
 
67
 
68
-#define CRITICAL_SECTION_START portENTER_CRITICAL(&spinlock)
69
-#define CRITICAL_SECTION_END   portEXIT_CRITICAL(&spinlock)
68
+#define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock)
69
+#define CRITICAL_SECTION_END()   portEXIT_CRITICAL(&spinlock)
70
 #define ISRS_ENABLED() (spinlock.owner == portMUX_FREE_VAL)
70
 #define ISRS_ENABLED() (spinlock.owner == portMUX_FREE_VAL)
71
 #define ENABLE_ISRS()  if (spinlock.owner != portMUX_FREE_VAL) portEXIT_CRITICAL(&spinlock)
71
 #define ENABLE_ISRS()  if (spinlock.owner != portMUX_FREE_VAL) portEXIT_CRITICAL(&spinlock)
72
 #define DISABLE_ISRS() portENTER_CRITICAL(&spinlock)
72
 #define DISABLE_ISRS() portENTER_CRITICAL(&spinlock)

+ 2
- 2
Marlin/src/HAL/HAL_LINUX/HAL.h View File

72
 //
72
 //
73
 // Interrupts
73
 // Interrupts
74
 //
74
 //
75
-#define CRITICAL_SECTION_START
76
-#define CRITICAL_SECTION_END
75
+#define CRITICAL_SECTION_START()
76
+#define CRITICAL_SECTION_END()
77
 #define ISRS_ENABLED()
77
 #define ISRS_ENABLED()
78
 #define ENABLE_ISRS()
78
 #define ENABLE_ISRS()
79
 #define DISABLE_ISRS()
79
 #define DISABLE_ISRS()

+ 2
- 2
Marlin/src/HAL/HAL_LPC1768/HAL.h View File

119
 //
119
 //
120
 // Interrupts
120
 // Interrupts
121
 //
121
 //
122
-#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
123
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
122
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_PRIMASK(); __disable_irq()
123
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
124
 #define ISRS_ENABLED() (!__get_PRIMASK())
124
 #define ISRS_ENABLED() (!__get_PRIMASK())
125
 #define ENABLE_ISRS()  __enable_irq()
125
 #define ENABLE_ISRS()  __enable_irq()
126
 #define DISABLE_ISRS() __disable_irq()
126
 #define DISABLE_ISRS() __disable_irq()

+ 2
- 2
Marlin/src/HAL/HAL_SAMD51/HAL.h View File

101
 //
101
 //
102
 // Interrupts
102
 // Interrupts
103
 //
103
 //
104
-#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
105
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
104
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_PRIMASK(); __disable_irq()
105
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
106
 #define ISRS_ENABLED() (!__get_PRIMASK())
106
 #define ISRS_ENABLED() (!__get_PRIMASK())
107
 #define ENABLE_ISRS()  __enable_irq()
107
 #define ENABLE_ISRS()  __enable_irq()
108
 #define DISABLE_ISRS() __disable_irq()
108
 #define DISABLE_ISRS() __disable_irq()

+ 2
- 2
Marlin/src/HAL/HAL_STM32/HAL.h View File

127
   #define analogInputToDigitalPin(p) (p)
127
   #define analogInputToDigitalPin(p) (p)
128
 #endif
128
 #endif
129
 
129
 
130
-#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
131
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
130
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_PRIMASK(); __disable_irq()
131
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
132
 #define ISRS_ENABLED() (!__get_PRIMASK())
132
 #define ISRS_ENABLED() (!__get_PRIMASK())
133
 #define ENABLE_ISRS()  __enable_irq()
133
 #define ENABLE_ISRS()  __enable_irq()
134
 #define DISABLE_ISRS() __disable_irq()
134
 #define DISABLE_ISRS() __disable_irq()

+ 2
- 2
Marlin/src/HAL/HAL_STM32F1/HAL.h View File

162
   #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
162
   #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
163
 #endif
163
 #endif
164
 
164
 
165
-#define CRITICAL_SECTION_START  uint32_t primask = __get_primask(); (void)__iCliRetVal()
166
-#define CRITICAL_SECTION_END    if (!primask) (void)__iSeiRetVal()
165
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_primask(); (void)__iCliRetVal()
166
+#define CRITICAL_SECTION_END()    if (!primask) (void)__iSeiRetVal()
167
 #define ISRS_ENABLED() (!__get_primask())
167
 #define ISRS_ENABLED() (!__get_primask())
168
 #define ENABLE_ISRS()  ((void)__iSeiRetVal())
168
 #define ENABLE_ISRS()  ((void)__iSeiRetVal())
169
 #define DISABLE_ISRS() ((void)__iCliRetVal())
169
 #define DISABLE_ISRS() ((void)__iCliRetVal())

+ 2
- 2
Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h View File

127
   #define analogInputToDigitalPin(p) (p)
127
   #define analogInputToDigitalPin(p) (p)
128
 #endif
128
 #endif
129
 
129
 
130
-#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
131
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
130
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_PRIMASK(); __disable_irq()
131
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
132
 #define ISRS_ENABLED() (!__get_PRIMASK())
132
 #define ISRS_ENABLED() (!__get_PRIMASK())
133
 #define ENABLE_ISRS()  __enable_irq()
133
 #define ENABLE_ISRS()  __enable_irq()
134
 #define DISABLE_ISRS() __disable_irq()
134
 #define DISABLE_ISRS() __disable_irq()

+ 2
- 2
Marlin/src/HAL/HAL_TEENSY31_32/HAL.h View File

70
   #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
70
   #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
71
 #endif
71
 #endif
72
 
72
 
73
-#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
74
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
73
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_PRIMASK(); __disable_irq()
74
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
75
 #define ISRS_ENABLED() (!__get_PRIMASK())
75
 #define ISRS_ENABLED() (!__get_PRIMASK())
76
 #define ENABLE_ISRS()  __enable_irq()
76
 #define ENABLE_ISRS()  __enable_irq()
77
 #define DISABLE_ISRS() __disable_irq()
77
 #define DISABLE_ISRS() __disable_irq()

+ 2
- 2
Marlin/src/HAL/HAL_TEENSY35_36/HAL.h View File

73
   #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
73
   #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
74
 #endif
74
 #endif
75
 
75
 
76
-#define CRITICAL_SECTION_START  uint32_t primask = __get_primask(); __disable_irq()
77
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
76
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_primask(); __disable_irq()
77
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
78
 #define ISRS_ENABLED() (!__get_primask())
78
 #define ISRS_ENABLED() (!__get_primask())
79
 #define ENABLE_ISRS()  __enable_irq()
79
 #define ENABLE_ISRS()  __enable_irq()
80
 #define DISABLE_ISRS() __disable_irq()
80
 #define DISABLE_ISRS() __disable_irq()

+ 2
- 2
Marlin/src/HAL/shared/servo.cpp View File

129
     value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
129
     value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
130
     value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
130
     value = usToTicks(value);  // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
131
 
131
 
132
-    CRITICAL_SECTION_START;
132
+    CRITICAL_SECTION_START();
133
     servo_info[channel].ticks = value;
133
     servo_info[channel].ticks = value;
134
-    CRITICAL_SECTION_END;
134
+    CRITICAL_SECTION_END();
135
   }
135
   }
136
 }
136
 }
137
 
137
 

+ 10
- 10
Marlin/src/feature/Max7219_Debug_LEDs.cpp View File

125
   #define SIG_DELAY() DELAY_US(1)   // Approximate a 1µs delay on 32-bit ARM
125
   #define SIG_DELAY() DELAY_US(1)   // Approximate a 1µs delay on 32-bit ARM
126
   #undef CRITICAL_SECTION_START
126
   #undef CRITICAL_SECTION_START
127
   #undef CRITICAL_SECTION_END
127
   #undef CRITICAL_SECTION_END
128
-  #define CRITICAL_SECTION_START NOOP
129
-  #define CRITICAL_SECTION_END   NOOP
128
+  #define CRITICAL_SECTION_START() NOOP
129
+  #define CRITICAL_SECTION_END()   NOOP
130
 #else
130
 #else
131
   #define SIG_DELAY() DELAY_NS(188) // Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
131
   #define SIG_DELAY() DELAY_NS(188) // Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
132
 #endif
132
 #endif
163
 }
163
 }
164
 
164
 
165
 void Max7219::noop() {
165
 void Max7219::noop() {
166
-  CRITICAL_SECTION_START;
166
+  CRITICAL_SECTION_START();
167
   SIG_DELAY();
167
   SIG_DELAY();
168
   WRITE(MAX7219_DIN_PIN, LOW);
168
   WRITE(MAX7219_DIN_PIN, LOW);
169
   for (uint8_t i = 16; i--;) {
169
   for (uint8_t i = 16; i--;) {
174
     WRITE(MAX7219_CLK_PIN, HIGH);
174
     WRITE(MAX7219_CLK_PIN, HIGH);
175
     SIG_DELAY();
175
     SIG_DELAY();
176
   }
176
   }
177
-  CRITICAL_SECTION_END;
177
+  CRITICAL_SECTION_END();
178
 }
178
 }
179
 
179
 
180
 void Max7219::putbyte(uint8_t data) {
180
 void Max7219::putbyte(uint8_t data) {
181
-  CRITICAL_SECTION_START;
181
+  CRITICAL_SECTION_START();
182
   for (uint8_t i = 8; i--;) {
182
   for (uint8_t i = 8; i--;) {
183
     SIG_DELAY();
183
     SIG_DELAY();
184
     WRITE(MAX7219_CLK_PIN, LOW);       // tick
184
     WRITE(MAX7219_CLK_PIN, LOW);       // tick
189
     SIG_DELAY();
189
     SIG_DELAY();
190
     data <<= 1;
190
     data <<= 1;
191
   }
191
   }
192
-  CRITICAL_SECTION_END;
192
+  CRITICAL_SECTION_END();
193
 }
193
 }
194
 
194
 
195
 void Max7219::pulse_load() {
195
 void Max7219::pulse_load() {
202
 
202
 
203
 void Max7219::send(const uint8_t reg, const uint8_t data) {
203
 void Max7219::send(const uint8_t reg, const uint8_t data) {
204
   SIG_DELAY();
204
   SIG_DELAY();
205
-  CRITICAL_SECTION_START;
205
+  CRITICAL_SECTION_START();
206
   SIG_DELAY();
206
   SIG_DELAY();
207
   putbyte(reg);          // specify register
207
   putbyte(reg);          // specify register
208
   SIG_DELAY();
208
   SIG_DELAY();
209
   putbyte(data);         // put data
209
   putbyte(data);         // put data
210
-  CRITICAL_SECTION_END;
210
+  CRITICAL_SECTION_END();
211
 }
211
 }
212
 
212
 
213
 // Send out a single native row of bits to just one unit
213
 // Send out a single native row of bits to just one unit
574
   #define MAX7219_USE_HEAD (defined(MAX7219_DEBUG_PLANNER_HEAD) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
574
   #define MAX7219_USE_HEAD (defined(MAX7219_DEBUG_PLANNER_HEAD) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
575
   #define MAX7219_USE_TAIL (defined(MAX7219_DEBUG_PLANNER_TAIL) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
575
   #define MAX7219_USE_TAIL (defined(MAX7219_DEBUG_PLANNER_TAIL) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
576
   #if MAX7219_USE_HEAD || MAX7219_USE_TAIL
576
   #if MAX7219_USE_HEAD || MAX7219_USE_TAIL
577
-    CRITICAL_SECTION_START;
577
+    CRITICAL_SECTION_START();
578
     #if MAX7219_USE_HEAD
578
     #if MAX7219_USE_HEAD
579
       const uint8_t head = planner.block_buffer_head;
579
       const uint8_t head = planner.block_buffer_head;
580
     #endif
580
     #endif
581
     #if MAX7219_USE_TAIL
581
     #if MAX7219_USE_TAIL
582
       const uint8_t tail = planner.block_buffer_tail;
582
       const uint8_t tail = planner.block_buffer_tail;
583
     #endif
583
     #endif
584
-    CRITICAL_SECTION_END;
584
+    CRITICAL_SECTION_END();
585
   #endif
585
   #endif
586
 
586
 
587
   #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
587
   #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)

+ 4
- 4
Marlin/src/libs/buzzer.cpp View File

63
 
63
 
64
     if (state.tone.frequency > 0) {
64
     if (state.tone.frequency > 0) {
65
       #if ENABLED(EXTENSIBLE_UI)
65
       #if ENABLED(EXTENSIBLE_UI)
66
-        CRITICAL_SECTION_START;
66
+        CRITICAL_SECTION_START();
67
         ExtUI::onPlayTone(state.tone.frequency, state.tone.duration);
67
         ExtUI::onPlayTone(state.tone.frequency, state.tone.duration);
68
-        CRITICAL_SECTION_END;
68
+        CRITICAL_SECTION_END();
69
       #elif ENABLED(SPEAKER)
69
       #elif ENABLED(SPEAKER)
70
-        CRITICAL_SECTION_START;
70
+        CRITICAL_SECTION_START();
71
         ::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration);
71
         ::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration);
72
-        CRITICAL_SECTION_END;
72
+        CRITICAL_SECTION_END();
73
       #else
73
       #else
74
         on();
74
         on();
75
       #endif
75
       #endif

Loading…
Cancel
Save