Browse Source

Function-style critical section macros

pull/1/head
Scott Lahteine 5 years ago
parent
commit
fa6e7cb733
  1. 4
      Marlin/src/HAL/HAL_AVR/HAL.h
  2. 4
      Marlin/src/HAL/HAL_DUE/HAL.h
  3. 8
      Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp
  4. 4
      Marlin/src/HAL/HAL_ESP32/HAL.h
  5. 4
      Marlin/src/HAL/HAL_LINUX/HAL.h
  6. 4
      Marlin/src/HAL/HAL_LPC1768/HAL.h
  7. 4
      Marlin/src/HAL/HAL_SAMD51/HAL.h
  8. 4
      Marlin/src/HAL/HAL_STM32/HAL.h
  9. 4
      Marlin/src/HAL/HAL_STM32F1/HAL.h
  10. 4
      Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h
  11. 4
      Marlin/src/HAL/HAL_TEENSY31_32/HAL.h
  12. 4
      Marlin/src/HAL/HAL_TEENSY35_36/HAL.h
  13. 4
      Marlin/src/HAL/shared/servo.cpp
  14. 20
      Marlin/src/feature/Max7219_Debug_LEDs.cpp
  15. 8
      Marlin/src/libs/buzzer.cpp

4
Marlin/src/HAL/HAL_AVR/HAL.h

@ -53,8 +53,8 @@
//#define analogInputToDigitalPin(IO) IO
#ifndef CRITICAL_SECTION_START
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()
#define CRITICAL_SECTION_END SREG = _sreg
#define CRITICAL_SECTION_START() unsigned char _sreg = SREG; cli()
#define CRITICAL_SECTION_END() SREG = _sreg
#endif
#define ISRS_ENABLED() TEST(SREG, SREG_I)
#define ENABLE_ISRS() sei()

4
Marlin/src/HAL/HAL_DUE/HAL.h

@ -119,8 +119,8 @@ typedef int8_t pin_t;
//
// Interrupts
//
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()

8
Marlin/src/HAL/HAL_DUE/InterruptVectors.cpp

@ -63,13 +63,13 @@ static pfnISR_Handler* get_relocated_table_addr() {
memcpy(&ram_tab, romtab, sizeof(ram_tab));
// Disable global interrupts
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
// Set the vector table base address to the SRAM copy
SCB->VTOR = (uint32_t)(&ram_tab);
// Reenable interrupts
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
// Return the address of the table
return (pfnISR_Handler*)(&ram_tab);
@ -80,7 +80,7 @@ pfnISR_Handler install_isr(IRQn_Type irq, pfnISR_Handler newHandler) {
pfnISR_Handler *isrtab = get_relocated_table_addr();
// Disable global interrupts
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
// Get the original handler
pfnISR_Handler oldHandler = isrtab[irq + 16];
@ -89,7 +89,7 @@ pfnISR_Handler install_isr(IRQn_Type irq, pfnISR_Handler newHandler) {
isrtab[irq + 16] = newHandler;
// Reenable interrupts
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
// Return the original one
return oldHandler;

4
Marlin/src/HAL/HAL_ESP32/HAL.h

@ -65,8 +65,8 @@ extern portMUX_TYPE spinlock;
#define NUM_SERIAL 1
#endif
#define CRITICAL_SECTION_START portENTER_CRITICAL(&spinlock)
#define CRITICAL_SECTION_END portEXIT_CRITICAL(&spinlock)
#define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock)
#define CRITICAL_SECTION_END() portEXIT_CRITICAL(&spinlock)
#define ISRS_ENABLED() (spinlock.owner == portMUX_FREE_VAL)
#define ENABLE_ISRS() if (spinlock.owner != portMUX_FREE_VAL) portEXIT_CRITICAL(&spinlock)
#define DISABLE_ISRS() portENTER_CRITICAL(&spinlock)

4
Marlin/src/HAL/HAL_LINUX/HAL.h

@ -72,8 +72,8 @@ extern HalSerial usb_serial;
//
// Interrupts
//
#define CRITICAL_SECTION_START
#define CRITICAL_SECTION_END
#define CRITICAL_SECTION_START()
#define CRITICAL_SECTION_END()
#define ISRS_ENABLED()
#define ENABLE_ISRS()
#define DISABLE_ISRS()

4
Marlin/src/HAL/HAL_LPC1768/HAL.h

@ -119,8 +119,8 @@ extern "C" volatile uint32_t _millis;
//
// Interrupts
//
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()

4
Marlin/src/HAL/HAL_SAMD51/HAL.h

@ -101,8 +101,8 @@ typedef int8_t pin_t;
//
// Interrupts
//
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()

4
Marlin/src/HAL/HAL_STM32/HAL.h

@ -127,8 +127,8 @@
#define analogInputToDigitalPin(p) (p)
#endif
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()

4
Marlin/src/HAL/HAL_STM32F1/HAL.h

@ -162,8 +162,8 @@ void HAL_idletask();
#define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
#endif
#define CRITICAL_SECTION_START uint32_t primask = __get_primask(); (void)__iCliRetVal()
#define CRITICAL_SECTION_END if (!primask) (void)__iSeiRetVal()
#define CRITICAL_SECTION_START() uint32_t primask = __get_primask(); (void)__iCliRetVal()
#define CRITICAL_SECTION_END() if (!primask) (void)__iSeiRetVal()
#define ISRS_ENABLED() (!__get_primask())
#define ENABLE_ISRS() ((void)__iSeiRetVal())
#define DISABLE_ISRS() ((void)__iCliRetVal())

4
Marlin/src/HAL/HAL_STM32_F4_F7/HAL.h

@ -127,8 +127,8 @@
#define analogInputToDigitalPin(p) (p)
#endif
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()

4
Marlin/src/HAL/HAL_TEENSY31_32/HAL.h

@ -70,8 +70,8 @@ typedef int8_t pin_t;
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
#endif
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()

4
Marlin/src/HAL/HAL_TEENSY35_36/HAL.h

@ -73,8 +73,8 @@ typedef int8_t pin_t;
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
#endif
#define CRITICAL_SECTION_START uint32_t primask = __get_primask(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define CRITICAL_SECTION_START() uint32_t primask = __get_primask(); __disable_irq()
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_primask())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()

4
Marlin/src/HAL/shared/servo.cpp

@ -129,9 +129,9 @@ void Servo::writeMicroseconds(int value) {
value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
servo_info[channel].ticks = value;
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
}
}

20
Marlin/src/feature/Max7219_Debug_LEDs.cpp

@ -125,8 +125,8 @@ uint8_t Max7219::led_line[MAX7219_LINES]; // = { 0 };
#define SIG_DELAY() DELAY_US(1) // Approximate a 1µs delay on 32-bit ARM
#undef CRITICAL_SECTION_START
#undef CRITICAL_SECTION_END
#define CRITICAL_SECTION_START NOOP
#define CRITICAL_SECTION_END NOOP
#define CRITICAL_SECTION_START() NOOP
#define CRITICAL_SECTION_END() NOOP
#else
#define SIG_DELAY() DELAY_NS(188) // Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
#endif
@ -163,7 +163,7 @@ inline uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) {
}
void Max7219::noop() {
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
SIG_DELAY();
WRITE(MAX7219_DIN_PIN, LOW);
for (uint8_t i = 16; i--;) {
@ -174,11 +174,11 @@ void Max7219::noop() {
WRITE(MAX7219_CLK_PIN, HIGH);
SIG_DELAY();
}
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
}
void Max7219::putbyte(uint8_t data) {
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
for (uint8_t i = 8; i--;) {
SIG_DELAY();
WRITE(MAX7219_CLK_PIN, LOW); // tick
@ -189,7 +189,7 @@ void Max7219::putbyte(uint8_t data) {
SIG_DELAY();
data <<= 1;
}
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
}
void Max7219::pulse_load() {
@ -202,12 +202,12 @@ void Max7219::pulse_load() {
void Max7219::send(const uint8_t reg, const uint8_t data) {
SIG_DELAY();
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
SIG_DELAY();
putbyte(reg); // specify register
SIG_DELAY();
putbyte(data); // put data
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
}
// Send out a single native row of bits to just one unit
@ -574,14 +574,14 @@ void Max7219::idle_tasks() {
#define MAX7219_USE_HEAD (defined(MAX7219_DEBUG_PLANNER_HEAD) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
#define MAX7219_USE_TAIL (defined(MAX7219_DEBUG_PLANNER_TAIL) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
#if MAX7219_USE_HEAD || MAX7219_USE_TAIL
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
#if MAX7219_USE_HEAD
const uint8_t head = planner.block_buffer_head;
#endif
#if MAX7219_USE_TAIL
const uint8_t tail = planner.block_buffer_tail;
#endif
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
#endif
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)

8
Marlin/src/libs/buzzer.cpp

@ -63,13 +63,13 @@ void Buzzer::tick() {
if (state.tone.frequency > 0) {
#if ENABLED(EXTENSIBLE_UI)
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
ExtUI::onPlayTone(state.tone.frequency, state.tone.duration);
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
#elif ENABLED(SPEAKER)
CRITICAL_SECTION_START;
CRITICAL_SECTION_START();
::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration);
CRITICAL_SECTION_END;
CRITICAL_SECTION_END();
#else
on();
#endif

Loading…
Cancel
Save