imx233: clean timrot a bit

Change-Id: Ic803a6b5c93978cd3246e553579ac8a1ba35e191
This commit is contained in:
Amaury Pouly 2014-02-02 04:15:27 +01:00
parent c1609b0889
commit 4495913c28
6 changed files with 45 additions and 20 deletions

View file

@ -23,6 +23,7 @@
#include "rtc-imx233.h"
#include "kernel-imx233.h"
#include "string.h"
#include "timrot-imx233.h"
#define default_interrupt(name) \
extern __attribute__((weak, alias("UIRQ"))) void name(void)
@ -153,7 +154,7 @@ void irq_handler(void)
int irq_nr = (HW_ICOLL_VECTOR - HW_ICOLL_VBASE) / 4;
if(irq_count[irq_nr]++ > IRQ_STORM_THRESHOLD)
panicf("IRQ %d: storm detected", irq_nr);
if(irq_nr == INT_SRC_TIMER(TICK_TIMER_NR))
if(irq_nr == INT_SRC_TIMER(TIMER_TICK))
do_irq_stat();
(*(isr_t *)HW_ICOLL_VECTOR)();
/* acknowledge completion of IRQ (all use the same priority 0) */

View file

@ -32,7 +32,7 @@ static void tick_timer(void)
void tick_start(unsigned int interval_in_ms)
{
/* use the 1-kHz XTAL clock source */
imx233_setup_timer(TICK_TIMER_NR, true, interval_in_ms,
imx233_timrot_setup(TIMER_TICK, true, interval_in_ms,
BV_TIMROT_TIMCTRLn_SELECT__1KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1,
false, &tick_timer);
}

View file

@ -23,8 +23,6 @@
#include "kernel.h"
#define TICK_TIMER_NR 0
/* The i.MX233 uses in several places virtual channels to multiplex the work.
* To arbiter the use of the different channels, we use a simple channel arbiter
* based on a semaphore to count the number of channels in use, and a bitmask

View file

@ -22,8 +22,6 @@
#include "timrot-imx233.h"
#include "timer.h"
#define USER_TIMER_NR 1
static long timer_cycles = 0;
static void timer_fn(void)
@ -49,7 +47,7 @@ bool timer_set(long cycles, bool start)
bool timer_start(IF_COP_VOID(int core))
{
imx233_setup_timer(USER_TIMER_NR, true, timer_cycles,
imx233_timrot_setup(TIMER_USER, true, timer_cycles,
BV_TIMROT_TIMCTRLn_SELECT__32KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1,
false, &timer_fn);
return true;
@ -57,6 +55,6 @@ bool timer_start(IF_COP_VOID(int core))
void timer_stop(void)
{
imx233_setup_timer(USER_TIMER_NR, false, 0, BV_TIMROT_TIMCTRLn_SELECT__NEVER_TICK,
imx233_timrot_setup(TIMER_USER, false, 0, BV_TIMROT_TIMCTRLn_SELECT__NEVER_TICK,
BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, false, NULL);
}

View file

@ -20,8 +20,9 @@
****************************************************************************/
#include "timrot-imx233.h"
#include "clkctrl-imx233.h"
#include "string.h"
imx233_timer_fn_t timer_fns[4];
static imx233_timer_fn_t timer_fns[4];
#define define_timer_irq(nr) \
void INT_TIMER##nr(void) \
@ -36,28 +37,37 @@ define_timer_irq(1)
define_timer_irq(2)
define_timer_irq(3)
void imx233_setup_timer(unsigned timer_nr, bool reload, unsigned count,
void imx233_timrot_setup(unsigned timer_nr, bool reload, unsigned count,
unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn)
{
int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS);
/* only enable interrupt if function is set */
bool irq = fn != NULL;
timer_fns[timer_nr] = fn;
HW_TIMROT_TIMCTRLn(timer_nr) = BF_OR6(TIMROT_TIMCTRLn, SELECT(src),
PRESCALE(prescale), POLARITY(polarity), RELOAD(reload), IRQ(irq),
IRQ_EN(irq));
/* manual says count - 1 for reload timers */
HW_TIMROT_TIMCOUNTn(timer_nr) = reload ? count - 1 : reload;
HW_TIMROT_TIMCTRLn(timer_nr) = BF_OR7(TIMROT_TIMCTRLn, SELECT(src),
PRESCALE(prescale), POLARITY(polarity), RELOAD(reload), IRQ(irq),
IRQ_EN(irq), UPDATE(1));
imx233_icoll_enable_interrupt(INT_SRC_TIMER(timer_nr), irq);
/* finally update */
BF_SETn(TIMROT_TIMCTRLn, timer_nr, UPDATE);
HW_TIMROT_TIMCOUNTn(timer_nr) = reload ? count - 1 : count;
restore_interrupt(oldstatus);
}
struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr)
{
struct imx233_timrot_info_t info;
memset(&info, 0, sizeof(info));
info.src = BF_RDn(TIMROT_TIMCTRLn, timer_nr, SELECT);
info.prescale = BF_RDn(TIMROT_TIMCTRLn, timer_nr, PRESCALE);
info.reload = BF_RDn(TIMROT_TIMCTRLn, timer_nr, RELOAD);
info.polarity = BF_RDn(TIMROT_TIMCTRLn, timer_nr, POLARITY);
info.fixed_count = BF_RDn(TIMROT_TIMCOUNTn, timer_nr, FIXED_COUNT);
info.run_count = BF_RDn(TIMROT_TIMCOUNTn, timer_nr, RUNNING_COUNT);
return info;
}
void imx233_timrot_init(void)
{
imx233_reset_block(&HW_TIMROT_ROTCTRL);

View file

@ -26,10 +26,28 @@
#include "regs/regs-timrot.h"
/* list of timers */
enum
{
TIMER_TICK, /* for tick task */
TIMER_USER, /* for user timer */
};
struct imx233_timrot_info_t
{
unsigned fixed_count, run_count;
unsigned src;
unsigned prescale;
bool reload;
bool polarity;
bool irqen;
};
typedef void (*imx233_timer_fn_t)(void);
void imx233_timrot_init(void);
void imx233_setup_timer(unsigned timer_nr, bool reload, unsigned count,
void imx233_timrot_setup(unsigned timer_nr, bool reload, unsigned count,
unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn);
struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr);
#endif /* TIMROT_IMX233_H */