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:
maralvira 2010-11-07 14:27:01 +00:00
parent 65d3942c76
commit 4217eb2ebc
2 changed files with 24 additions and 8 deletions

View file

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org * This file is part of libmc1322x: see http://mc1322x.devl.org
* for details. * for details.
* *
* $Id: default_lowlevel.h,v 1.1 2010/06/10 14:49:31 maralvira Exp $ * $Id: default_lowlevel.h,v 1.2 2010/11/07 14:27:01 maralvira Exp $
*/ */
#ifndef LOWLEVEL_H #ifndef LOWLEVEL_H
@ -42,4 +42,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

View file

@ -30,12 +30,25 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org * This file is part of libmc1322x: see http://mc1322x.devl.org
* for details. * for details.
* *
* $Id: isr.c,v 1.3 2010/11/07 14:24:11 maralvira Exp $ * $Id: isr.c,v 1.4 2010/11/07 14:27:01 maralvira Exp $
*/ */
#include <mc1322x.h> #include <mc1322x.h>
#include <types.h> #include <types.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)
@ -44,16 +57,17 @@ void irq(void)
while ((pending = *NIPEND)) { 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 */ /* dispatch to individual timer isrs if they exist */
/* 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(); }
} }