From 680ecaecd7ed77d044fbf333ce97e533b04bbfa3 Mon Sep 17 00:00:00 2001 From: bernie Date: Mon, 13 Dec 2004 12:07:06 +0000 Subject: [PATCH] DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@316 38d2e660-2303-0410-9eaa-f027e97ec537 --- drv/buzzer.c | 42 +++++++++++++----------------------------- drv/eeprom.c | 8 ++++++-- drv/ser_avr.c | 7 +++++-- drv/timer.c | 18 +++++++++--------- drv/timer.h | 8 ++++---- drv/timer_avr.h | 15 +++++++++------ kern/proc.c | 15 ++++++++------- kern/signal.c | 18 +++++++++++------- 8 files changed, 65 insertions(+), 66 deletions(-) diff --git a/drv/buzzer.c b/drv/buzzer.c index 1d2c6e12..89af625d 100755 --- a/drv/buzzer.c +++ b/drv/buzzer.c @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.12 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.11 2004/12/08 09:11:53 bernie *#* Rename time_t to mtime_t. *#* @@ -76,36 +79,17 @@ #define IS_BUZZER_ON (PORTG & BV(PG0)) /*! - * Buzzer manipulation macros + * \name Buzzer manipulation macros. * * \note Some PORTG functions are being used from * interrupt code, so we must be careful to * avoid race conditions. + * \{ */ - #define BUZZER_ON \ - do { \ - cpuflags_t _flags; \ - DISABLE_IRQSAVE(_flags); \ - PORTG |= BV(PG0); \ - ENABLE_IRQRESTORE(_flags); \ - } while (0) - - #define BUZZER_OFF \ - do { \ - cpuflags_t _flags; \ - DISABLE_IRQSAVE(_flags); \ - PORTG &= ~BV(PG0); \ - ENABLE_IRQRESTORE(_flags); \ - } while (0) - - #define BUZZER_INIT \ - do { \ - cpuflags_t _flags; \ - DISABLE_IRQSAVE(_flags); \ - PORTG &= ~BV(PG0); \ - DDRG |= BV(PG0); \ - ENABLE_IRQRESTORE(_flags); \ - } while (0) + #define BUZZER_ON ATOMIC(PORTG |= BV(PG0)) + #define BUZZER_OFF ATOMIC(PORTG &= ~BV(PG0)) + #define BUZZER_INIT ATOMIC(PORTG &= ~BV(PG0); DDRG |= BV(PG0);) + /*\}*/ #elif defined(__IAR_SYSTEMS_ICC) || defined(__IAR_SYSTEMS_ICC__) /* 80C196 */ @@ -159,9 +143,9 @@ static void buz_softint(void) void buz_beep(mtime_t time) { cpuflags_t flags; + IRQ_SAVE_DISABLE(flags); /* Remove the software interrupt if it was already queued */ - DISABLE_IRQSAVE(flags); if (buz_timer_running) timer_abort(&buz_timer); @@ -173,7 +157,7 @@ void buz_beep(mtime_t time) buz_timer.delay = time; timer_add(&buz_timer); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } @@ -194,7 +178,7 @@ void buz_repeat_start(mtime_t duration, mtime_t interval) void buz_repeat_stop(void) { cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Remove the software interrupt if it was already queued */ if (buz_timer_running) @@ -206,7 +190,7 @@ void buz_repeat_stop(void) buz_repeat_interval = 0; BUZZER_OFF; - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } diff --git a/drv/eeprom.c b/drv/eeprom.c index e951daee..57861376 100755 --- a/drv/eeprom.c +++ b/drv/eeprom.c @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.14 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.13 2004/11/16 20:58:51 bernie *#* Add write verify. *#* @@ -63,6 +66,7 @@ #include /* cpu_to_be16() */ #include #include +#include // IRQ_SAVE_DISABLE(), IRQ_RESTORE() #include // CONFIG_EEPROM_VERIFY #include // MIN() @@ -470,7 +474,7 @@ void eeprom_erase(e2addr_t addr, size_t count) void eeprom_init(void) { cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* * This is pretty useless according to AVR's datasheet, @@ -500,7 +504,7 @@ void eeprom_init(void) TWSR = 0; TWCR = BV(TWEN); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } diff --git a/drv/ser_avr.c b/drv/ser_avr.c index 37facaa2..a54d3764 100755 --- a/drv/ser_avr.c +++ b/drv/ser_avr.c @@ -38,6 +38,9 @@ /*#* *#* $Log$ + *#* Revision 1.21 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.20 2004/12/13 11:51:43 bernie *#* Fix a latent bug with reentrant serial IRQs. *#* @@ -476,7 +479,7 @@ static void spi_starttx(struct SerialHardware *_hw) struct AvrSerial *hw = (struct AvrSerial *)_hw; cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Send data only if the SPI is not already transmitting */ if (!hw->sending && !fifo_isempty(&ser_spi->txfifo)) @@ -485,7 +488,7 @@ static void spi_starttx(struct SerialHardware *_hw) SPDR = fifo_pop(&ser_spi->txfifo); } - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } static void spi_setbaudrate(UNUSED(struct SerialHardware *, _hw), UNUSED(unsigned long, rate)) diff --git a/drv/timer.c b/drv/timer.c index 00cd7cfd..e0208b88 100755 --- a/drv/timer.c +++ b/drv/timer.c @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.23 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.22 2004/12/08 09:12:09 bernie *#* Rename time_t to mtime_t. *#* @@ -146,7 +149,7 @@ void timer_add(Timer *timer) Timer *node; cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Calculate expiration time for this timer */ timer->tick = _clock + timer->delay; @@ -172,19 +175,16 @@ void timer_add(Timer *timer) /* Enqueue timer request into the list */ INSERTBEFORE(&timer->link, &node->link); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } /*! - * Remove a timer from the timer queue before it has expired + * Remove a timer from the timer queue before it has expired. */ Timer *timer_abort(Timer *timer) { - cpuflags_t flags; - DISABLE_IRQSAVE(flags); - REMOVE(&timer->link); - ENABLE_IRQRESTORE(flags); + ATOMIC(REMOVE(&timer->link)); return timer; } @@ -193,7 +193,7 @@ Timer *timer_abort(Timer *timer) /*! - * Wait for the specified amount of time (expressed in ms) + * Wait for the specified amount of time (expressed in ms). */ void timer_delay(mtime_t time) { @@ -229,7 +229,7 @@ void timer_delay(mtime_t time) #ifndef CONFIG_TIMER_DISABLE_UDELAY /*! - * Wait for the specified amount of time (expressed in microseconds) + * Wait for the specified amount of time (expressed in microseconds). * * \bug In AVR arch the maximum amount of time that can be used as * delay could be very limited, depending on the hardware timer diff --git a/drv/timer.h b/drv/timer.h index a75adfd2..e66ed618 100755 --- a/drv/timer.h +++ b/drv/timer.h @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.22 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.21 2004/12/09 08:35:21 bernie *#* Replace IPTR with iptr_t. *#* @@ -173,11 +176,8 @@ extern volatile mtime_t _clock; INLINE mtime_t timer_ticks(void) { mtime_t result; - cpuflags_t flags; - DISABLE_IRQSAVE(flags); - result = _clock; - ENABLE_IRQRESTORE(flags); + ATOMIC(result = _clock); return result; } diff --git a/drv/timer_avr.h b/drv/timer_avr.h index 2e2095df..52dea9cf 100755 --- a/drv/timer_avr.h +++ b/drv/timer_avr.h @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.21 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.20 2004/11/16 20:59:46 bernie *#* Include explicitly. *#* @@ -96,7 +99,7 @@ static void timer_hw_init(void) { cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Reset Timer flags */ TIFR = BV(OCF0) | BV(TOV0); @@ -117,7 +120,7 @@ TIMSK &= ~BV(TOIE0); TIMSK |= BV(OCIE0); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } //! Frequency of the hardware high precision timer @@ -136,7 +139,7 @@ static void timer_hw_init(void) { cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Reset Timer overflow flag */ TIFR |= BV(TOV1); @@ -153,7 +156,7 @@ /* Enable timer interrupt: Timer/Counter1 Overflow */ TIMSK |= BV(TOIE1); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } //! Frequency of the hardware high precision timer @@ -172,7 +175,7 @@ static void timer_hw_init(void) { cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Reset Timer flags */ TIFR = BV(OCF2) | BV(TOV2); @@ -194,7 +197,7 @@ TIMSK &= ~BV(TOIE2); TIMSK |= BV(OCIE2); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } //! Frequency of the hardware high precision timer diff --git a/kern/proc.c b/kern/proc.c index 2301cee0..dda2b018 100755 --- a/kern/proc.c +++ b/kern/proc.c @@ -17,6 +17,9 @@ /*#* *#* $Log$ + *#* Revision 1.23 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.22 2004/12/13 11:51:08 bernie *#* DISABLE_INTS/ENABLE_INTS: Convert to IRQ_DISABLE/IRQ_ENABLE. *#* @@ -251,9 +254,7 @@ struct Process *proc_new_with_name(UNUSED(const char*, name), void (*entry)(void CPU_PUSH_WORD(proc->stack, CPU_REG_INIT_VALUE(i)); /* Add to ready list */ - DISABLE_IRQSAVE(flags); - SCHED_ENQUEUE(proc); - ENABLE_IRQRESTORE(flags); + ATOMIC(SCHED_ENQUEUE(proc)); #if CONFIG_KERN_MONITOR monitor_add(proc, name, stack_base, stacksize); @@ -294,7 +295,7 @@ void proc_schedule(void) old_process = CurrentProcess; /* Poll on the ready queue for the first ready process */ - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); while (!(CurrentProcess = (struct Process *)REMHEAD(&ProcReadyList))) { /* @@ -311,7 +312,7 @@ void proc_schedule(void) SCHEDULER_IDLE; IRQ_DISABLE; } - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); /* * Optimization: don't switch contexts when the active @@ -387,9 +388,9 @@ void proc_switch(void) /* Just like proc_schedule, this function must not have auto variables. */ static cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); SCHED_ENQUEUE(CurrentProcess); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); proc_schedule(); } diff --git a/kern/signal.c b/kern/signal.c index 9b61120a..692cd44b 100755 --- a/kern/signal.c +++ b/kern/signal.c @@ -66,6 +66,9 @@ /*#* *#* $Log$ + *#* Revision 1.10 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* *#* Revision 1.9 2004/12/08 08:57:35 bernie *#* Rename sigset_t to sigmask_t. *#* @@ -103,7 +106,6 @@ #include "hw.h" #include -// FIXME #if CONFIG_KERN_SIGNALS /*! @@ -115,10 +117,11 @@ sigmask_t sig_check(sigmask_t sigs) sigmask_t result; cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); result = CurrentProcess->sig_recv & sigs; CurrentProcess->sig_recv &= ~sigs; - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); + return result; } @@ -132,7 +135,7 @@ sigmask_t sig_wait(sigmask_t sigs) sigmask_t result; cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Loop until we get at least one of the signals */ while (!(result = CurrentProcess->sig_recv & sigs)) @@ -148,7 +151,8 @@ sigmask_t sig_wait(sigmask_t sigs) /* Signals found: clear them and return */ CurrentProcess->sig_recv &= ~sigs; - ENABLE_IRQRESTORE(flags); + + IRQ_RESTORE(flags); return result; } @@ -162,7 +166,7 @@ sigmask_t sig_wait(sigmask_t sigs) void sig_signal(Process *proc, sigmask_t sigs) { cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); /* Set the signals */ proc->sig_recv |= sigs; @@ -175,7 +179,7 @@ void sig_signal(Process *proc, sigmask_t sigs) SCHED_ENQUEUE(proc); } - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); } #endif /* CONFIG_KERN_SIGNALS */ -- 2.25.1