summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-02-02 04:15:27 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2014-02-10 23:14:23 +0100
commit4495913c289d34271197dce0dc5f6c45f5ea62e6 (patch)
treebab4b2e477bcc1fdb5876cbf1ab36165de6aee46 /firmware/target/arm
parentc1609b08892ec6878c6cc1ea20689145d23a51e6 (diff)
downloadrockbox-4495913c289d34271197dce0dc5f6c45f5ea62e6.tar.gz
rockbox-4495913c289d34271197dce0dc5f6c45f5ea62e6.tar.bz2
rockbox-4495913c289d34271197dce0dc5f6c45f5ea62e6.zip
imx233: clean timrot a bit
Change-Id: Ic803a6b5c93978cd3246e553579ac8a1ba35e191
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/imx233/icoll-imx233.c3
-rw-r--r--firmware/target/arm/imx233/kernel-imx233.c2
-rw-r--r--firmware/target/arm/imx233/kernel-imx233.h2
-rw-r--r--firmware/target/arm/imx233/timer-imx233.c8
-rw-r--r--firmware/target/arm/imx233/timrot-imx233.c30
-rw-r--r--firmware/target/arm/imx233/timrot-imx233.h20
6 files changed, 45 insertions, 20 deletions
diff --git a/firmware/target/arm/imx233/icoll-imx233.c b/firmware/target/arm/imx233/icoll-imx233.c
index 20b526d4fb..b753af8d54 100644
--- a/firmware/target/arm/imx233/icoll-imx233.c
+++ b/firmware/target/arm/imx233/icoll-imx233.c
@@ -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) */
diff --git a/firmware/target/arm/imx233/kernel-imx233.c b/firmware/target/arm/imx233/kernel-imx233.c
index c3ee2e8bd3..104f2e5aee 100644
--- a/firmware/target/arm/imx233/kernel-imx233.c
+++ b/firmware/target/arm/imx233/kernel-imx233.c
@@ -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);
}
diff --git a/firmware/target/arm/imx233/kernel-imx233.h b/firmware/target/arm/imx233/kernel-imx233.h
index 58114f0c52..960f3f2431 100644
--- a/firmware/target/arm/imx233/kernel-imx233.h
+++ b/firmware/target/arm/imx233/kernel-imx233.h
@@ -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
diff --git a/firmware/target/arm/imx233/timer-imx233.c b/firmware/target/arm/imx233/timer-imx233.c
index d356afc457..f06c19fb76 100644
--- a/firmware/target/arm/imx233/timer-imx233.c
+++ b/firmware/target/arm/imx233/timer-imx233.c
@@ -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,14 +47,14 @@ 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);
+ false, &timer_fn);
return true;
}
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);
}
diff --git a/firmware/target/arm/imx233/timrot-imx233.c b/firmware/target/arm/imx233/timrot-imx233.c
index 848f640b5c..14b9bdca7b 100644
--- a/firmware/target/arm/imx233/timrot-imx233.c
+++ b/firmware/target/arm/imx233/timrot-imx233.c
@@ -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);
diff --git a/firmware/target/arm/imx233/timrot-imx233.h b/firmware/target/arm/imx233/timrot-imx233.h
index f7a7bc3f8d..e033673a83 100644
--- a/firmware/target/arm/imx233/timrot-imx233.h
+++ b/firmware/target/arm/imx233/timrot-imx233.h
@@ -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 */