*
* \author Francesco Sacchi <batt@develer.com>
*
*
* \author Francesco Sacchi <batt@develer.com>
*
- * \brief System irq handler for Atmel AT91 ARM7 processors.
+ * \brief System IRQ handler for Atmel AT91 ARM7 processors.
*
* In Atmel AT91 ARM7TDMI processors, there are various
* peripheral interrupt sources.
* In general, every source has its own interrupt vector, so it
* is possible to assign a specific handler for each interrupt
*
* In Atmel AT91 ARM7TDMI processors, there are various
* peripheral interrupt sources.
* In general, every source has its own interrupt vector, so it
* is possible to assign a specific handler for each interrupt
* However, there are a few sources called "system sources" that
* However, there are a few sources called "system sources" that
- * share a common IRQ line and vector, called "system irq".
- * So a unic system irq handler is implemented here.
+ * share a common IRQ line and vector, called "system IRQ".
+ * So a unique system IRQ handler is implemented here.
* This module also contains an interface to manage every source
* This module also contains an interface to manage every source
- * indipendently. It is possible to assign to every system irq
- * a specific irq handler.
+ * independently. It is possible to assign to every system IRQ
+ * a specific IRQ handler.
*
* \see sysirq_setHandler
* \see sysirq_setEnable
*
* \see sysirq_setHandler
* \see sysirq_setEnable
-/**
- * Returns the state of the Periodic Interval Timer
- * interrupt.
- */
-static bool pit_enable(void)
-{
- return PIT_MR & BV(PITIEN);
-}
-
-/**
- * Returns the state of the Periodic Interval Timer
- * interrupt.
- * \return true is PIT has triggered and interrupt, false otherwise
- */
-static bool pit_trigger(void)
-{
- return PIT_SR & BV(PITS);
-}
-
/**
* Enable/disable the Periodic Interrupt Timer
* interrupt.
*/
/**
* Enable/disable the Periodic Interrupt Timer
* interrupt.
*/
-static void pit_setEnable(bool enable)
+INLINE static void pit_setEnable(bool enable)
{
if (enable)
PIT_MR |= BV(PITIEN);
{
if (enable)
PIT_MR |= BV(PITIEN);
{
/* PIT, Periodic Interval Timer (System timer)*/
{
{
/* PIT, Periodic Interval Timer (System timer)*/
{
- .enable = pit_enable,
- .trigger = pit_trigger,
.setEnable = pit_setEnable,
.handler = NULL,
},
.setEnable = pit_setEnable,
.handler = NULL,
},
+ * System IRQ dispatcher.
* This is the entry point for all system IRQs in AT91.
* This function checks for interrupt enable state of
* various sources (system timer, etc..) and calls
* the corresponding handler.
*/
* This is the entry point for all system IRQs in AT91.
* This function checks for interrupt enable state of
* various sources (system timer, etc..) and calls
* the corresponding handler.
*/
-static void sysirq_handler(void)
+static void sysirq_dispatcher(void)
{
#warning TODO add IRQ prologue/epilogue
for (int i = 0; i < countof(sysirq_tab); i++)
{
{
#warning TODO add IRQ prologue/epilogue
for (int i = 0; i < countof(sysirq_tab); i++)
{
- if (sysirq_tab[i].enable()
- && sysirq_tab[i].trigger()
+ if (sysirq_tab[i].enabled
&& sysirq_tab[i].handler)
sysirq_tab[i].handler();
}
&& sysirq_tab[i].handler)
sysirq_tab[i].handler();
}
#define SYSIRQ_PRIORITY 0 ///< default priority for system irqs.
#define SYSIRQ_PRIORITY 0 ///< default priority for system irqs.
- * Init system irq handling.
+ * Init system IRQ handling.
* \note all system interrupts are disabled.
*/
void sysirq_init(void)
* \note all system interrupts are disabled.
*/
void sysirq_init(void)
sysirq_tab[i].setEnable(false);
/* Set the vector. */
sysirq_tab[i].setEnable(false);
/* Set the vector. */
- AIC_SVR(SYSC_ID) = sysirq_handler;
- /* Initialize to edge triggered with defined priority. */
- AIC_SMR(SYSC_ID) = BV(AIC_SRCTYPE_INT_EDGE_TRIGGERED) | SYSIRQ_PRIORITY;
- /* Clear interrupt */
- AIC_ICCR = BV(SYSC_ID);
+ AIC_SVR(SYSC_ID) = sysirq_handler;
+ /* Initialize to edge triggered with defined priority. */
+ AIC_SMR(SYSC_ID) = BV(AIC_SRCTYPE_INT_EDGE_TRIGGERED) | SYSIRQ_PRIORITY;
+ /* Clear interrupt */
+ AIC_ICCR = BV(SYSC_ID);
+
- * Helper function used to set handler for system irq \a irq.
+ * Helper function used to set handler for system IRQ \a irq.
*/
void sysirq_setHandler(sysirq_t irq, sysirq_handler_t handler)
{
*/
void sysirq_setHandler(sysirq_t irq, sysirq_handler_t handler)
{
- * Helper function used to enable/disable system irq \a irq.
+ * Helper function used to enable/disable system IRQ \a irq.
*/
void sysirq_setEnable(sysirq_t irq, bool enable)
{
ASSERT(irq >= 0);
ASSERT(irq < SYSIRQ_CNT);
*/
void sysirq_setEnable(sysirq_t irq, bool enable)
{
ASSERT(irq >= 0);
ASSERT(irq < SYSIRQ_CNT);
sysirq_tab[irq].setEnable(enable);
sysirq_tab[irq].setEnable(enable);
+ sysirq_enabled = enable;
- * Helper function used to get system irq \a irq state.
+ * Helper function used to get system IRQ \a irq state.
-bool sysirq_enable(sysirq_t irq)
+bool sysirq_enabled(sysirq_t irq)
{
ASSERT(irq >= 0);
ASSERT(irq < SYSIRQ_CNT);
{
ASSERT(irq >= 0);
ASSERT(irq < SYSIRQ_CNT);
- return sysirq_tab[irq].enable();
+ return sysirq_tab[irq].enabled;
typedef void (* sysirq_handler_t)(void); ///< Type for system irq handler.
typedef void (* sysirq_setEnable_t)(bool); ///< Type for system irq enable/disable function.
typedef void (* sysirq_handler_t)(void); ///< Type for system irq handler.
typedef void (* sysirq_setEnable_t)(bool); ///< Type for system irq enable/disable function.
-typedef bool (* sysirq_enable_t)(void); ///< Type for system irq enable getter.
-typedef bool (* sysirq_trigger_t)(void); ///< Type for system irq trigger getter.
/**
* Structure used to define a system interrupt source.
*/
typedef struct SysIrq
{
/**
* Structure used to define a system interrupt source.
*/
typedef struct SysIrq
{
- sysirq_enable_t enable; ///< Getter for irq enable/disable state.
- sysirq_trigger_t trigger; ///< Getter for irq trigger state.
+ bool enabled; ///< Getter for irq enable/disable state.
sysirq_setEnable_t setEnable; ///< Setter for irq enable/disable state.
sysirq_handler_t handler; ///< IRQ handler.
} SysIrq;
sysirq_setEnable_t setEnable; ///< Setter for irq enable/disable state.
sysirq_handler_t handler; ///< IRQ handler.
} SysIrq;
void sysirq_init(void);
void sysirq_setHandler(sysirq_t irq, sysirq_handler_t handler);
void sysirq_setEnable(sysirq_t irq, bool enable);
void sysirq_init(void);
void sysirq_setHandler(sysirq_t irq, sysirq_handler_t handler);
void sysirq_setEnable(sysirq_t irq, bool enable);
-bool sysirq_enable(sysirq_t irq);
+bool sysirq_enabled(sysirq_t irq);
#endif /* ARCH_ARM_SYSIRQ_H */
#endif /* ARCH_ARM_SYSIRQ_H */
#warning Very untested!
INLINE static void timer_hw_irq(void)
{
#warning Very untested!
INLINE static void timer_hw_irq(void)
{
- /* Reset counters, this is needed to start timer and interrupt flags */
+ /* Reset counters, this is needed to reset timer and interrupt flags */
volatile uint32_t dummy = PIT_PIVR;
}
volatile uint32_t dummy = PIT_PIVR;
}
+ INLINE static bool timer_hw_triggered(void)
+ {
+ return PIT_SR & BV(PITS);
+ }
- static void timer_hw_init(void)
+ INLINE static void timer_hw_init(void)
{
cpuflags_t flags;
IRQ_SAVE_DISABLE(flags);
{
cpuflags_t flags;
IRQ_SAVE_DISABLE(flags);
- INLINE hptime_t timer_hw_hpread(void)
+ INLINE static hptime_t timer_hw_hpread(void)
{
/* In the upper part of PIT_PIIR there is unused data */
return PIT_PIIR & 0xfffff;
{
/* In the upper part of PIT_PIIR there is unused data */
return PIT_PIIR & 0xfffff;
+ *#* Revision 1.32 2007/10/08 12:14:32 batt
+ *#* Fix some review issues.
+ *#*
*#* Revision 1.31 2006/07/19 12:56:26 bernie
*#* Convert to new Doxygen style.
*#*
*#* Revision 1.31 2006/07/19 12:56:26 bernie
*#* Convert to new Doxygen style.
*#*
#ifndef CONFIG_TIMER_DISABLE_EVENTS
Timer *timer;
#endif
#ifndef CONFIG_TIMER_DISABLE_EVENTS
Timer *timer;
#endif
+ /*
+ * On systems sharing IRQ line and vector, this check is needed
+ * to ensure that IRQ is generated by timer source.
+ */
+ if (!timer_hw_triggered())
+ return;
+ /* Perform hw IRQ handling */
timer_hw_irq();
/* Update the master ms counter */
timer_hw_irq();
/* Update the master ms counter */
+ *#* Revision 1.32 2007/10/08 12:14:32 batt
+ *#* Fix some review issues.
+ *#*
*#* Revision 1.31 2007/10/07 12:30:55 batt
*#* Add default timer for AVR.
*#*
*#* Revision 1.31 2007/10/07 12:30:55 batt
*#* Add default timer for AVR.
*#*
/** Not needed, IRQ timer flag cleared automatically */
#define timer_hw_irq() do {} while (0)
/** Not needed, IRQ timer flag cleared automatically */
#define timer_hw_irq() do {} while (0)
+/** Not needed, timer IRQ handler called only for timer source */
+#define timer_hw_triggered() (true)
+
#endif /* DRV_TIMER_AVR_H */
#endif /* DRV_TIMER_AVR_H */