Provide a function to change timer interrrupt handlers
Function irq_register_timer_handler(int timer, void (*isr)(void)) lets you change the handler at runtime. This lets us set handlers without necessarily knowing the name at link-time. The old way of having weakly-linked tmr0_isr functions should still work.
This commit is contained in:
parent
76563958fe
commit
b2c64dc233
|
@ -40,4 +40,6 @@
|
||||||
void default_vreg_init(void);
|
void default_vreg_init(void);
|
||||||
void uart1_init(uint16_t inc, uint16_t mod, uint8_t samp);
|
void uart1_init(uint16_t inc, uint16_t mod, uint8_t samp);
|
||||||
|
|
||||||
|
void irq_register_timer_handler(int timer, void (*isr)(void));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
22
src/isr.c
22
src/isr.c
|
@ -35,6 +35,19 @@
|
||||||
|
|
||||||
#include <mc1322x.h>
|
#include <mc1322x.h>
|
||||||
|
|
||||||
|
static void (*tmr_isr_funcs[4])(void) = {
|
||||||
|
tmr0_isr,
|
||||||
|
tmr1_isr,
|
||||||
|
tmr2_isr,
|
||||||
|
tmr3_isr
|
||||||
|
};
|
||||||
|
|
||||||
|
void irq_register_timer_handler(int timer, void (*isr)(void))
|
||||||
|
{
|
||||||
|
tmr_isr_funcs[timer] = isr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
__attribute__ ((section (".irq")))
|
__attribute__ ((section (".irq")))
|
||||||
__attribute__ ((interrupt("IRQ")))
|
__attribute__ ((interrupt("IRQ")))
|
||||||
void irq(void)
|
void irq(void)
|
||||||
|
@ -48,11 +61,12 @@ void irq(void)
|
||||||
/* timer isrs are responsible for determining if they
|
/* timer isrs are responsible for determining if they
|
||||||
* caused an interrupt */
|
* caused an interrupt */
|
||||||
/* and clearing their own interrupt flags */
|
/* and clearing their own interrupt flags */
|
||||||
if(tmr0_isr != 0) { tmr0_isr(); }
|
if (tmr_isr_funcs[0] != 0) { (tmr_isr_funcs[0])(); }
|
||||||
if(tmr1_isr != 0) { tmr1_isr(); }
|
if (tmr_isr_funcs[1] != 0) { (tmr_isr_funcs[1])(); }
|
||||||
if(tmr2_isr != 0) { tmr2_isr(); }
|
if (tmr_isr_funcs[2] != 0) { (tmr_isr_funcs[2])(); }
|
||||||
if(tmr3_isr != 0) { tmr3_isr(); }
|
if (tmr_isr_funcs[3] != 0) { (tmr_isr_funcs[3])(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bit_is_set(pending, INT_NUM_MACA)) {
|
if(bit_is_set(pending, INT_NUM_MACA)) {
|
||||||
if(maca_isr != 0) { maca_isr(); }
|
if(maca_isr != 0) { maca_isr(); }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue