Hi all,
I'm working on a project where I need to periodically poll several
input pins with at least 5 kHz frequency as I need to be able to
detect the correct sequence of binary input signals.
I tried to use the timer1 interrupt from a kernel module, after
compiling a 2.4 kernel without the
fasttimer api, but I am not able to get it right.
After configuring and starting the timer, the interrupt handler is
called once and after that the system
seems to hang (all LEDs flashing simultaneously).
I am neither sure if I am configuring the timer appropriately, nor do
I know precisely whether it is actually possible to use timer1 from a
kernel module without breaking internal kernel operation.
This is the code I am using, it's pretty much the code copied from the
fasttimer/ircontrol code,
so it may be fundamentally wrong in a kernel module:
static irqreturn_t irqTimer0_interrupt(int irq, void *dev_id, struct
pt_regs *regs)
{
r_timer_ctrl_shadow = *R_TIMER_CTRL;
/* acknowledge the timer1 irq */ *R_TIMER_CTRL =
r_timer_ctrl_shadow = r_timer_ctrl_shadow |
IO_STATE(R_TIMER_CTRL, i1, clr);
*R_IRQ_MASK0_CLR = IO_STATE(R_IRQ_MASK0_CLR, timer1, clr);
*R_TIMER_CTRL = r_timer_ctrl_shadow =
(r_timer_ctrl_shadow & ~IO_MASK(R_TIMER_CTRL, tm1)) |
IO_STATE(R_TIMER_CTRL, tm1, stop_ld);
return IRQ_HANDLED;
}
void init_timer()
{
unsigned long div = 2;
// Clear timer1 irq
*R_IRQ_MASK0_CLR = IO_STATE(R_IRQ_MASK0_CLR, timer1, clr);
// Set timer values
r_timer_ctrl_shadow = *R_TIMER_CTRL;
*R_TIMER_CTRL = r_timer_ctrl_shadow =
(r_timer_ctrl_shadow &
~IO_MASK(R_TIMER_CTRL, timerdiv1) &
~IO_MASK(R_TIMER_CTRL, tm1) &
~IO_MASK(R_TIMER_CTRL, clksel1)) |
IO_FIELD(R_TIMER_CTRL, timerdiv1, FREQ_DIVIDER) |
IO_STATE(R_TIMER_CTRL, tm1, stop_ld) |
IO_FIELD(R_TIMER_CTRL, clksel1, 10);
*R_TIMER_CTRL = r_timer_ctrl_shadow =
(r_timer_ctrl_shadow & ~IO_MASK(R_TIMER_CTRL, tm1)) |
IO_STATE(R_TIMER_CTRL, tm1, run);
/* enable timer1 irq */
*R_IRQ_MASK0_SET = IO_STATE(R_IRQ_MASK0_SET, timer1, set);
}
Any help on this topic will be appreciated. Thanks a lot!
Dietmar