diff options
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/imx233/icoll-imx233.c | 3 | ||||
-rw-r--r-- | firmware/target/arm/imx233/kernel-imx233.c | 2 | ||||
-rw-r--r-- | firmware/target/arm/imx233/kernel-imx233.h | 2 | ||||
-rw-r--r-- | firmware/target/arm/imx233/timer-imx233.c | 8 | ||||
-rw-r--r-- | firmware/target/arm/imx233/timrot-imx233.c | 30 | ||||
-rw-r--r-- | firmware/target/arm/imx233/timrot-imx233.h | 20 |
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 @@ | |||
23 | #include "rtc-imx233.h" | 23 | #include "rtc-imx233.h" |
24 | #include "kernel-imx233.h" | 24 | #include "kernel-imx233.h" |
25 | #include "string.h" | 25 | #include "string.h" |
26 | #include "timrot-imx233.h" | ||
26 | 27 | ||
27 | #define default_interrupt(name) \ | 28 | #define default_interrupt(name) \ |
28 | extern __attribute__((weak, alias("UIRQ"))) void name(void) | 29 | extern __attribute__((weak, alias("UIRQ"))) void name(void) |
@@ -153,7 +154,7 @@ void irq_handler(void) | |||
153 | int irq_nr = (HW_ICOLL_VECTOR - HW_ICOLL_VBASE) / 4; | 154 | int irq_nr = (HW_ICOLL_VECTOR - HW_ICOLL_VBASE) / 4; |
154 | if(irq_count[irq_nr]++ > IRQ_STORM_THRESHOLD) | 155 | if(irq_count[irq_nr]++ > IRQ_STORM_THRESHOLD) |
155 | panicf("IRQ %d: storm detected", irq_nr); | 156 | panicf("IRQ %d: storm detected", irq_nr); |
156 | if(irq_nr == INT_SRC_TIMER(TICK_TIMER_NR)) | 157 | if(irq_nr == INT_SRC_TIMER(TIMER_TICK)) |
157 | do_irq_stat(); | 158 | do_irq_stat(); |
158 | (*(isr_t *)HW_ICOLL_VECTOR)(); | 159 | (*(isr_t *)HW_ICOLL_VECTOR)(); |
159 | /* acknowledge completion of IRQ (all use the same priority 0) */ | 160 | /* 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) | |||
32 | void tick_start(unsigned int interval_in_ms) | 32 | void tick_start(unsigned int interval_in_ms) |
33 | { | 33 | { |
34 | /* use the 1-kHz XTAL clock source */ | 34 | /* use the 1-kHz XTAL clock source */ |
35 | imx233_setup_timer(TICK_TIMER_NR, true, interval_in_ms, | 35 | imx233_timrot_setup(TIMER_TICK, true, interval_in_ms, |
36 | BV_TIMROT_TIMCTRLn_SELECT__1KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, | 36 | BV_TIMROT_TIMCTRLn_SELECT__1KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, |
37 | false, &tick_timer); | 37 | false, &tick_timer); |
38 | } | 38 | } |
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 @@ | |||
23 | 23 | ||
24 | #include "kernel.h" | 24 | #include "kernel.h" |
25 | 25 | ||
26 | #define TICK_TIMER_NR 0 | ||
27 | |||
28 | /* The i.MX233 uses in several places virtual channels to multiplex the work. | 26 | /* The i.MX233 uses in several places virtual channels to multiplex the work. |
29 | * To arbiter the use of the different channels, we use a simple channel arbiter | 27 | * To arbiter the use of the different channels, we use a simple channel arbiter |
30 | * based on a semaphore to count the number of channels in use, and a bitmask | 28 | * 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 @@ | |||
22 | #include "timrot-imx233.h" | 22 | #include "timrot-imx233.h" |
23 | #include "timer.h" | 23 | #include "timer.h" |
24 | 24 | ||
25 | #define USER_TIMER_NR 1 | ||
26 | |||
27 | static long timer_cycles = 0; | 25 | static long timer_cycles = 0; |
28 | 26 | ||
29 | static void timer_fn(void) | 27 | static void timer_fn(void) |
@@ -49,14 +47,14 @@ bool timer_set(long cycles, bool start) | |||
49 | 47 | ||
50 | bool timer_start(IF_COP_VOID(int core)) | 48 | bool timer_start(IF_COP_VOID(int core)) |
51 | { | 49 | { |
52 | imx233_setup_timer(USER_TIMER_NR, true, timer_cycles, | 50 | imx233_timrot_setup(TIMER_USER, true, timer_cycles, |
53 | BV_TIMROT_TIMCTRLn_SELECT__32KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, | 51 | BV_TIMROT_TIMCTRLn_SELECT__32KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, |
54 | false, &timer_fn); | 52 | false, &timer_fn); |
55 | return true; | 53 | return true; |
56 | } | 54 | } |
57 | 55 | ||
58 | void timer_stop(void) | 56 | void timer_stop(void) |
59 | { | 57 | { |
60 | imx233_setup_timer(USER_TIMER_NR, false, 0, BV_TIMROT_TIMCTRLn_SELECT__NEVER_TICK, | 58 | imx233_timrot_setup(TIMER_USER, false, 0, BV_TIMROT_TIMCTRLn_SELECT__NEVER_TICK, |
61 | BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, false, NULL); | 59 | BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, false, NULL); |
62 | } | 60 | } |
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 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "timrot-imx233.h" | 21 | #include "timrot-imx233.h" |
22 | #include "clkctrl-imx233.h" | 22 | #include "clkctrl-imx233.h" |
23 | #include "string.h" | ||
23 | 24 | ||
24 | imx233_timer_fn_t timer_fns[4]; | 25 | static imx233_timer_fn_t timer_fns[4]; |
25 | 26 | ||
26 | #define define_timer_irq(nr) \ | 27 | #define define_timer_irq(nr) \ |
27 | void INT_TIMER##nr(void) \ | 28 | void INT_TIMER##nr(void) \ |
@@ -36,28 +37,37 @@ define_timer_irq(1) | |||
36 | define_timer_irq(2) | 37 | define_timer_irq(2) |
37 | define_timer_irq(3) | 38 | define_timer_irq(3) |
38 | 39 | ||
39 | void imx233_setup_timer(unsigned timer_nr, bool reload, unsigned count, | 40 | void imx233_timrot_setup(unsigned timer_nr, bool reload, unsigned count, |
40 | unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn) | 41 | unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn) |
41 | { | 42 | { |
42 | int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS); | 43 | int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS); |
43 | /* only enable interrupt if function is set */ | 44 | /* only enable interrupt if function is set */ |
44 | bool irq = fn != NULL; | 45 | bool irq = fn != NULL; |
45 | |||
46 | timer_fns[timer_nr] = fn; | 46 | timer_fns[timer_nr] = fn; |
47 | 47 | ||
48 | HW_TIMROT_TIMCTRLn(timer_nr) = BF_OR6(TIMROT_TIMCTRLn, SELECT(src), | ||
49 | PRESCALE(prescale), POLARITY(polarity), RELOAD(reload), IRQ(irq), | ||
50 | IRQ_EN(irq)); | ||
51 | |||
52 | /* manual says count - 1 for reload timers */ | 48 | /* manual says count - 1 for reload timers */ |
53 | HW_TIMROT_TIMCOUNTn(timer_nr) = reload ? count - 1 : reload; | 49 | HW_TIMROT_TIMCTRLn(timer_nr) = BF_OR7(TIMROT_TIMCTRLn, SELECT(src), |
50 | PRESCALE(prescale), POLARITY(polarity), RELOAD(reload), IRQ(irq), | ||
51 | IRQ_EN(irq), UPDATE(1)); | ||
54 | imx233_icoll_enable_interrupt(INT_SRC_TIMER(timer_nr), irq); | 52 | imx233_icoll_enable_interrupt(INT_SRC_TIMER(timer_nr), irq); |
55 | /* finally update */ | 53 | HW_TIMROT_TIMCOUNTn(timer_nr) = reload ? count - 1 : count; |
56 | BF_SETn(TIMROT_TIMCTRLn, timer_nr, UPDATE); | ||
57 | 54 | ||
58 | restore_interrupt(oldstatus); | 55 | restore_interrupt(oldstatus); |
59 | } | 56 | } |
60 | 57 | ||
58 | struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr) | ||
59 | { | ||
60 | struct imx233_timrot_info_t info; | ||
61 | memset(&info, 0, sizeof(info)); | ||
62 | info.src = BF_RDn(TIMROT_TIMCTRLn, timer_nr, SELECT); | ||
63 | info.prescale = BF_RDn(TIMROT_TIMCTRLn, timer_nr, PRESCALE); | ||
64 | info.reload = BF_RDn(TIMROT_TIMCTRLn, timer_nr, RELOAD); | ||
65 | info.polarity = BF_RDn(TIMROT_TIMCTRLn, timer_nr, POLARITY); | ||
66 | info.fixed_count = BF_RDn(TIMROT_TIMCOUNTn, timer_nr, FIXED_COUNT); | ||
67 | info.run_count = BF_RDn(TIMROT_TIMCOUNTn, timer_nr, RUNNING_COUNT); | ||
68 | return info; | ||
69 | } | ||
70 | |||
61 | void imx233_timrot_init(void) | 71 | void imx233_timrot_init(void) |
62 | { | 72 | { |
63 | imx233_reset_block(&HW_TIMROT_ROTCTRL); | 73 | 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 @@ | |||
26 | 26 | ||
27 | #include "regs/regs-timrot.h" | 27 | #include "regs/regs-timrot.h" |
28 | 28 | ||
29 | /* list of timers */ | ||
30 | enum | ||
31 | { | ||
32 | TIMER_TICK, /* for tick task */ | ||
33 | TIMER_USER, /* for user timer */ | ||
34 | }; | ||
35 | |||
36 | struct imx233_timrot_info_t | ||
37 | { | ||
38 | unsigned fixed_count, run_count; | ||
39 | unsigned src; | ||
40 | unsigned prescale; | ||
41 | bool reload; | ||
42 | bool polarity; | ||
43 | bool irqen; | ||
44 | }; | ||
45 | |||
29 | typedef void (*imx233_timer_fn_t)(void); | 46 | typedef void (*imx233_timer_fn_t)(void); |
30 | 47 | ||
31 | void imx233_timrot_init(void); | 48 | void imx233_timrot_init(void); |
32 | void imx233_setup_timer(unsigned timer_nr, bool reload, unsigned count, | 49 | void imx233_timrot_setup(unsigned timer_nr, bool reload, unsigned count, |
33 | unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn); | 50 | unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn); |
51 | struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr); | ||
34 | 52 | ||
35 | #endif /* TIMROT_IMX233_H */ | 53 | #endif /* TIMROT_IMX233_H */ |