DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 13 Dec 2004 12:07:06 +0000 (12:07 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 13 Dec 2004 12:07:06 +0000 (12:07 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@316 38d2e660-2303-0410-9eaa-f027e97ec537

drv/buzzer.c
drv/eeprom.c
drv/ser_avr.c
drv/timer.c
drv/timer.h
drv/timer_avr.h
kern/proc.c
kern/signal.c

index 1d2c6e12bb2d07768a89e40849e014054b6399d7..89af625d9c281336092a492d73751e05e68f24d9 100755 (executable)
@@ -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.
  *#*
        #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);
 }
 
 
index e951daee5b20bcf2cdb71cdf3c5e518ed9b47947..57861376151b1151ee38817421cd8961273e169d 100755 (executable)
@@ -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 <mware/byteorder.h> /* cpu_to_be16() */
 #include <debug.h>
 #include <hw.h>
+#include <cpu.h>     // IRQ_SAVE_DISABLE(), IRQ_RESTORE()
 #include <config.h>  // CONFIG_EEPROM_VERIFY
 #include <macros.h>  // 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);
 }
 
 
index 37facaa2f7e39366a55a8275a4cd23470ae42890..a54d3764dd35cb79f9960e48bf711631c2609cbf 100755 (executable)
@@ -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))
index 00cd7cfd2a265e98432bb9d8e5019c72d1bf1a4b..e0208b8843675763eee70025a7cdbf850451c568 100755 (executable)
@@ -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
index a75adfd26e1ec8dc8e5077cdeb38a7981b18d339..e66ed6188cfd7157685f3ec27c09f61d87d15df0 100755 (executable)
@@ -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;
 }
index 2e2095df5b8e258c6018e9e16dfeb7afbf7aed81..52dea9cf362d754525e631114c2f169b6e0bf127 100755 (executable)
@@ -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 <avr/io.h> 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);
                TIMSK &= ~BV(TOIE0);
                TIMSK |= BV(OCIE0);
 
-               ENABLE_IRQRESTORE(flags);
+               IRQ_RESTORE(flags);
        }
 
        //! Frequency of the hardware high precision timer
        static void timer_hw_init(void)
        {
                cpuflags_t flags;
-               DISABLE_IRQSAVE(flags);
+               IRQ_SAVE_DISABLE(flags);
 
                /* Reset Timer overflow flag */
                TIFR |= BV(TOV1);
                /* Enable timer interrupt: Timer/Counter1 Overflow */
                TIMSK |= BV(TOIE1);
 
-               ENABLE_IRQRESTORE(flags);
+               IRQ_RESTORE(flags);
        }
 
        //! Frequency of the hardware high precision timer
        static void timer_hw_init(void)
        {
                cpuflags_t flags;
-               DISABLE_IRQSAVE(flags);
+               IRQ_SAVE_DISABLE(flags);
 
                /* Reset Timer flags */
                TIFR = BV(OCF2) | BV(TOV2);
                TIMSK &= ~BV(TOIE2);
                TIMSK |= BV(OCIE2);
 
-               ENABLE_IRQRESTORE(flags);
+               IRQ_RESTORE(flags);
        }
 
        //! Frequency of the hardware high precision timer
index 2301cee05c862bc5fe86c7722363c50e39db5d8a..dda2b018c180e8891af2c6660ce4485eb653046a 100755 (executable)
@@ -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();
 }
index 9b61120a8e46aa1e243254da302641e0ccffa90b..692cd44bf679b0f8c6b772f1a33152ce2532d243 100755 (executable)
@@ -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.
  *#*
 #include "hw.h"
 #include <debug.h>
 
-// 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 */