Function-style critical section macros
This commit is contained in:
parent
7b02a62da8
commit
fa6e7cb733
|
@ -53,8 +53,8 @@
|
||||||
//#define analogInputToDigitalPin(IO) IO
|
//#define analogInputToDigitalPin(IO) IO
|
||||||
|
|
||||||
#ifndef CRITICAL_SECTION_START
|
#ifndef CRITICAL_SECTION_START
|
||||||
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()
|
#define CRITICAL_SECTION_START() unsigned char _sreg = SREG; cli()
|
||||||
#define CRITICAL_SECTION_END SREG = _sreg
|
#define CRITICAL_SECTION_END() SREG = _sreg
|
||||||
#endif
|
#endif
|
||||||
#define ISRS_ENABLED() TEST(SREG, SREG_I)
|
#define ISRS_ENABLED() TEST(SREG, SREG_I)
|
||||||
#define ENABLE_ISRS() sei()
|
#define ENABLE_ISRS() sei()
|
||||||
|
|
|
@ -119,8 +119,8 @@ typedef int8_t pin_t;
|
||||||
//
|
//
|
||||||
// Interrupts
|
// Interrupts
|
||||||
//
|
//
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||||
#define ENABLE_ISRS() __enable_irq()
|
#define ENABLE_ISRS() __enable_irq()
|
||||||
#define DISABLE_ISRS() __disable_irq()
|
#define DISABLE_ISRS() __disable_irq()
|
||||||
|
|
|
@ -63,13 +63,13 @@ static pfnISR_Handler* get_relocated_table_addr() {
|
||||||
memcpy(&ram_tab, romtab, sizeof(ram_tab));
|
memcpy(&ram_tab, romtab, sizeof(ram_tab));
|
||||||
|
|
||||||
// Disable global interrupts
|
// Disable global interrupts
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
|
|
||||||
// Set the vector table base address to the SRAM copy
|
// Set the vector table base address to the SRAM copy
|
||||||
SCB->VTOR = (uint32_t)(&ram_tab);
|
SCB->VTOR = (uint32_t)(&ram_tab);
|
||||||
|
|
||||||
// Reenable interrupts
|
// Reenable interrupts
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
|
|
||||||
// Return the address of the table
|
// Return the address of the table
|
||||||
return (pfnISR_Handler*)(&ram_tab);
|
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();
|
pfnISR_Handler *isrtab = get_relocated_table_addr();
|
||||||
|
|
||||||
// Disable global interrupts
|
// Disable global interrupts
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
|
|
||||||
// Get the original handler
|
// Get the original handler
|
||||||
pfnISR_Handler oldHandler = isrtab[irq + 16];
|
pfnISR_Handler oldHandler = isrtab[irq + 16];
|
||||||
|
@ -89,7 +89,7 @@ pfnISR_Handler install_isr(IRQn_Type irq, pfnISR_Handler newHandler) {
|
||||||
isrtab[irq + 16] = newHandler;
|
isrtab[irq + 16] = newHandler;
|
||||||
|
|
||||||
// Reenable interrupts
|
// Reenable interrupts
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
|
|
||||||
// Return the original one
|
// Return the original one
|
||||||
return oldHandler;
|
return oldHandler;
|
||||||
|
|
|
@ -65,8 +65,8 @@ extern portMUX_TYPE spinlock;
|
||||||
#define NUM_SERIAL 1
|
#define NUM_SERIAL 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CRITICAL_SECTION_START portENTER_CRITICAL(&spinlock)
|
#define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock)
|
||||||
#define CRITICAL_SECTION_END portEXIT_CRITICAL(&spinlock)
|
#define CRITICAL_SECTION_END() portEXIT_CRITICAL(&spinlock)
|
||||||
#define ISRS_ENABLED() (spinlock.owner == portMUX_FREE_VAL)
|
#define ISRS_ENABLED() (spinlock.owner == portMUX_FREE_VAL)
|
||||||
#define ENABLE_ISRS() if (spinlock.owner != portMUX_FREE_VAL) portEXIT_CRITICAL(&spinlock)
|
#define ENABLE_ISRS() if (spinlock.owner != portMUX_FREE_VAL) portEXIT_CRITICAL(&spinlock)
|
||||||
#define DISABLE_ISRS() portENTER_CRITICAL(&spinlock)
|
#define DISABLE_ISRS() portENTER_CRITICAL(&spinlock)
|
||||||
|
|
|
@ -72,8 +72,8 @@ extern HalSerial usb_serial;
|
||||||
//
|
//
|
||||||
// Interrupts
|
// Interrupts
|
||||||
//
|
//
|
||||||
#define CRITICAL_SECTION_START
|
#define CRITICAL_SECTION_START()
|
||||||
#define CRITICAL_SECTION_END
|
#define CRITICAL_SECTION_END()
|
||||||
#define ISRS_ENABLED()
|
#define ISRS_ENABLED()
|
||||||
#define ENABLE_ISRS()
|
#define ENABLE_ISRS()
|
||||||
#define DISABLE_ISRS()
|
#define DISABLE_ISRS()
|
||||||
|
|
|
@ -119,8 +119,8 @@ extern "C" volatile uint32_t _millis;
|
||||||
//
|
//
|
||||||
// Interrupts
|
// Interrupts
|
||||||
//
|
//
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||||
#define ENABLE_ISRS() __enable_irq()
|
#define ENABLE_ISRS() __enable_irq()
|
||||||
#define DISABLE_ISRS() __disable_irq()
|
#define DISABLE_ISRS() __disable_irq()
|
||||||
|
|
|
@ -101,8 +101,8 @@ typedef int8_t pin_t;
|
||||||
//
|
//
|
||||||
// Interrupts
|
// Interrupts
|
||||||
//
|
//
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||||
#define ENABLE_ISRS() __enable_irq()
|
#define ENABLE_ISRS() __enable_irq()
|
||||||
#define DISABLE_ISRS() __disable_irq()
|
#define DISABLE_ISRS() __disable_irq()
|
||||||
|
|
|
@ -127,8 +127,8 @@
|
||||||
#define analogInputToDigitalPin(p) (p)
|
#define analogInputToDigitalPin(p) (p)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||||
#define ENABLE_ISRS() __enable_irq()
|
#define ENABLE_ISRS() __enable_irq()
|
||||||
#define DISABLE_ISRS() __disable_irq()
|
#define DISABLE_ISRS() __disable_irq()
|
||||||
|
|
|
@ -162,8 +162,8 @@ void HAL_idletask();
|
||||||
#define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
|
#define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_primask(); (void)__iCliRetVal()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_primask(); (void)__iCliRetVal()
|
||||||
#define CRITICAL_SECTION_END if (!primask) (void)__iSeiRetVal()
|
#define CRITICAL_SECTION_END() if (!primask) (void)__iSeiRetVal()
|
||||||
#define ISRS_ENABLED() (!__get_primask())
|
#define ISRS_ENABLED() (!__get_primask())
|
||||||
#define ENABLE_ISRS() ((void)__iSeiRetVal())
|
#define ENABLE_ISRS() ((void)__iSeiRetVal())
|
||||||
#define DISABLE_ISRS() ((void)__iCliRetVal())
|
#define DISABLE_ISRS() ((void)__iCliRetVal())
|
||||||
|
|
|
@ -127,8 +127,8 @@
|
||||||
#define analogInputToDigitalPin(p) (p)
|
#define analogInputToDigitalPin(p) (p)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||||
#define ENABLE_ISRS() __enable_irq()
|
#define ENABLE_ISRS() __enable_irq()
|
||||||
#define DISABLE_ISRS() __disable_irq()
|
#define DISABLE_ISRS() __disable_irq()
|
||||||
|
|
|
@ -70,8 +70,8 @@ typedef int8_t pin_t;
|
||||||
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
|
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||||
#define ENABLE_ISRS() __enable_irq()
|
#define ENABLE_ISRS() __enable_irq()
|
||||||
#define DISABLE_ISRS() __disable_irq()
|
#define DISABLE_ISRS() __disable_irq()
|
||||||
|
|
|
@ -73,8 +73,8 @@ typedef int8_t pin_t;
|
||||||
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
|
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CRITICAL_SECTION_START uint32_t primask = __get_primask(); __disable_irq()
|
#define CRITICAL_SECTION_START() uint32_t primask = __get_primask(); __disable_irq()
|
||||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||||
#define ISRS_ENABLED() (!__get_primask())
|
#define ISRS_ENABLED() (!__get_primask())
|
||||||
#define ENABLE_ISRS() __enable_irq()
|
#define ENABLE_ISRS() __enable_irq()
|
||||||
#define DISABLE_ISRS() __disable_irq()
|
#define DISABLE_ISRS() __disable_irq()
|
||||||
|
|
|
@ -129,9 +129,9 @@ void Servo::writeMicroseconds(int value) {
|
||||||
value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
|
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
|
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;
|
servo_info[channel].ticks = value;
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
#define SIG_DELAY() DELAY_US(1) // Approximate a 1µs delay on 32-bit ARM
|
||||||
#undef CRITICAL_SECTION_START
|
#undef CRITICAL_SECTION_START
|
||||||
#undef CRITICAL_SECTION_END
|
#undef CRITICAL_SECTION_END
|
||||||
#define CRITICAL_SECTION_START NOOP
|
#define CRITICAL_SECTION_START() NOOP
|
||||||
#define CRITICAL_SECTION_END NOOP
|
#define CRITICAL_SECTION_END() NOOP
|
||||||
#else
|
#else
|
||||||
#define SIG_DELAY() DELAY_NS(188) // Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
|
#define SIG_DELAY() DELAY_NS(188) // Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
|
||||||
#endif
|
#endif
|
||||||
|
@ -163,7 +163,7 @@ inline uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Max7219::noop() {
|
void Max7219::noop() {
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
SIG_DELAY();
|
SIG_DELAY();
|
||||||
WRITE(MAX7219_DIN_PIN, LOW);
|
WRITE(MAX7219_DIN_PIN, LOW);
|
||||||
for (uint8_t i = 16; i--;) {
|
for (uint8_t i = 16; i--;) {
|
||||||
|
@ -174,11 +174,11 @@ void Max7219::noop() {
|
||||||
WRITE(MAX7219_CLK_PIN, HIGH);
|
WRITE(MAX7219_CLK_PIN, HIGH);
|
||||||
SIG_DELAY();
|
SIG_DELAY();
|
||||||
}
|
}
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Max7219::putbyte(uint8_t data) {
|
void Max7219::putbyte(uint8_t data) {
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
for (uint8_t i = 8; i--;) {
|
for (uint8_t i = 8; i--;) {
|
||||||
SIG_DELAY();
|
SIG_DELAY();
|
||||||
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
||||||
|
@ -189,7 +189,7 @@ void Max7219::putbyte(uint8_t data) {
|
||||||
SIG_DELAY();
|
SIG_DELAY();
|
||||||
data <<= 1;
|
data <<= 1;
|
||||||
}
|
}
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Max7219::pulse_load() {
|
void Max7219::pulse_load() {
|
||||||
|
@ -202,12 +202,12 @@ void Max7219::pulse_load() {
|
||||||
|
|
||||||
void Max7219::send(const uint8_t reg, const uint8_t data) {
|
void Max7219::send(const uint8_t reg, const uint8_t data) {
|
||||||
SIG_DELAY();
|
SIG_DELAY();
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
SIG_DELAY();
|
SIG_DELAY();
|
||||||
putbyte(reg); // specify register
|
putbyte(reg); // specify register
|
||||||
SIG_DELAY();
|
SIG_DELAY();
|
||||||
putbyte(data); // put data
|
putbyte(data); // put data
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send out a single native row of bits to just one unit
|
// 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_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))
|
#define MAX7219_USE_TAIL (defined(MAX7219_DEBUG_PLANNER_TAIL) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
|
||||||
#if MAX7219_USE_HEAD || MAX7219_USE_TAIL
|
#if MAX7219_USE_HEAD || MAX7219_USE_TAIL
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
#if MAX7219_USE_HEAD
|
#if MAX7219_USE_HEAD
|
||||||
const uint8_t head = planner.block_buffer_head;
|
const uint8_t head = planner.block_buffer_head;
|
||||||
#endif
|
#endif
|
||||||
#if MAX7219_USE_TAIL
|
#if MAX7219_USE_TAIL
|
||||||
const uint8_t tail = planner.block_buffer_tail;
|
const uint8_t tail = planner.block_buffer_tail;
|
||||||
#endif
|
#endif
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
||||||
|
|
|
@ -63,13 +63,13 @@ void Buzzer::tick() {
|
||||||
|
|
||||||
if (state.tone.frequency > 0) {
|
if (state.tone.frequency > 0) {
|
||||||
#if ENABLED(EXTENSIBLE_UI)
|
#if ENABLED(EXTENSIBLE_UI)
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
ExtUI::onPlayTone(state.tone.frequency, state.tone.duration);
|
ExtUI::onPlayTone(state.tone.frequency, state.tone.duration);
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
#elif ENABLED(SPEAKER)
|
#elif ENABLED(SPEAKER)
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START();
|
||||||
::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration);
|
::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration);
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END();
|
||||||
#else
|
#else
|
||||||
on();
|
on();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue