Function-style critical section macros

This commit is contained in:
Scott Lahteine 2020-02-11 01:13:02 -06:00
parent 7b02a62da8
commit fa6e7cb733
15 changed files with 42 additions and 42 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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;

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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())

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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();
}
}

View File

@ -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)

View File

@ -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