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
2 changed files with 22 additions and 6 deletions
|
@ -40,4 +40,6 @@
|
|||
void default_vreg_init(void);
|
||||
void uart1_init(uint16_t inc, uint16_t mod, uint8_t samp);
|
||||
|
||||
void irq_register_timer_handler(int timer, void (*isr)(void));
|
||||
|
||||
#endif
|
||||
|
|
26
src/isr.c
26
src/isr.c
|
@ -35,6 +35,19 @@
|
|||
|
||||
#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__ ((interrupt("IRQ")))
|
||||
void irq(void)
|
||||
|
@ -43,16 +56,17 @@ void irq(void)
|
|||
|
||||
while ((pending = *NIPEND)) {
|
||||
|
||||
if(bit_is_set(pending, INT_NUM_TMR)) {
|
||||
if(bit_is_set(pending, INT_NUM_TMR)) {
|
||||
/* dispatch to individual timer isrs if they exist */
|
||||
/* timer isrs are responsible for determining if they
|
||||
* caused an interrupt */
|
||||
/* and clearing their own interrupt flags */
|
||||
if(tmr0_isr != 0) { tmr0_isr(); }
|
||||
if(tmr1_isr != 0) { tmr1_isr(); }
|
||||
if(tmr2_isr != 0) { tmr2_isr(); }
|
||||
if(tmr3_isr != 0) { tmr3_isr(); }
|
||||
}
|
||||
if (tmr_isr_funcs[0] != 0) { (tmr_isr_funcs[0])(); }
|
||||
if (tmr_isr_funcs[1] != 0) { (tmr_isr_funcs[1])(); }
|
||||
if (tmr_isr_funcs[2] != 0) { (tmr_isr_funcs[2])(); }
|
||||
if (tmr_isr_funcs[3] != 0) { (tmr_isr_funcs[3])(); }
|
||||
}
|
||||
|
||||
if(bit_is_set(pending, INT_NUM_MACA)) {
|
||||
if(maca_isr != 0) { maca_isr(); }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue