summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-05-02 21:37:38 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2016-05-28 17:18:32 +0200
commit643c0a1e0e80ee6010353201792ba6e2be7e1ced (patch)
tree0b039050be720483935978575f77351db143463f
parent423c64770c04a62e34775c37a7e09a60f6ccbc4c (diff)
downloadrockbox-643c0a1e0e80ee6010353201792ba6e2be7e1ced.tar.gz
rockbox-643c0a1e0e80ee6010353201792ba6e2be7e1ced.zip
imx233: simplify timrot API
The old timrot setup API was very low-level and unfriendly. The new one makes in easier to select the frequency source. Use to simplify timer and kernel timer code. Change-Id: Iffcdf11c00e925be9ec8d9a4efc74b197b6bd2aa
-rw-r--r--firmware/target/arm/imx233/kernel-imx233.c4
-rw-r--r--firmware/target/arm/imx233/system-imx233.c5
-rw-r--r--firmware/target/arm/imx233/timer-imx233.c7
-rw-r--r--firmware/target/arm/imx233/timrot-imx233.c43
-rw-r--r--firmware/target/arm/imx233/timrot-imx233.h26
5 files changed, 74 insertions, 11 deletions
diff --git a/firmware/target/arm/imx233/kernel-imx233.c b/firmware/target/arm/imx233/kernel-imx233.c
index 199015f564..0652d6e640 100644
--- a/firmware/target/arm/imx233/kernel-imx233.c
+++ b/firmware/target/arm/imx233/kernel-imx233.c
@@ -34,9 +34,7 @@ static void tick_timer(void)
34void tick_start(unsigned int interval_in_ms) 34void tick_start(unsigned int interval_in_ms)
35{ 35{
36 /* use the 1-kHz XTAL clock source */ 36 /* use the 1-kHz XTAL clock source */
37 imx233_timrot_setup(TIMER_TICK, true, interval_in_ms, 37 imx233_timrot_setup_simple(TIMER_TICK, true, interval_in_ms, TIMER_SRC_1KHZ, &tick_timer);
38 BV_TIMROT_TIMCTRLn_SELECT__1KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1,
39 false, &tick_timer);
40} 38}
41 39
42void arbiter_init(struct channel_arbiter_t *a, unsigned count) 40void arbiter_init(struct channel_arbiter_t *a, unsigned count)
diff --git a/firmware/target/arm/imx233/system-imx233.c b/firmware/target/arm/imx233/system-imx233.c
index 666b9fedf4..b2ece3be61 100644
--- a/firmware/target/arm/imx233/system-imx233.c
+++ b/firmware/target/arm/imx233/system-imx233.c
@@ -67,9 +67,8 @@ static void good_dog(void)
67{ 67{
68 imx233_rtc_reset_watchdog(WATCHDOG_HW_DELAY * 1000 / HZ); /* ms */ 68 imx233_rtc_reset_watchdog(WATCHDOG_HW_DELAY * 1000 / HZ); /* ms */
69 imx233_rtc_enable_watchdog(true); 69 imx233_rtc_enable_watchdog(true);
70 imx233_timrot_setup(TIMER_WATCHDOG, false, WATCHDOG_SW_DELAY * 1000 / HZ, 70 imx233_timrot_setup_simple(TIMER_WATCHDOG, false, WATCHDOG_SW_DELAY * 1000 / HZ,
71 BV_TIMROT_TIMCTRLn_SELECT__1KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, 71 TIMER_SRC_1KHZ, &woof_woof);
72 false, &woof_woof);
73 imx233_timrot_set_priority(TIMER_WATCHDOG, ICOLL_PRIO_WATCHDOG); 72 imx233_timrot_set_priority(TIMER_WATCHDOG, ICOLL_PRIO_WATCHDOG);
74} 73}
75 74
diff --git a/firmware/target/arm/imx233/timer-imx233.c b/firmware/target/arm/imx233/timer-imx233.c
index bcadc82f2c..57d38c01a6 100644
--- a/firmware/target/arm/imx233/timer-imx233.c
+++ b/firmware/target/arm/imx233/timer-imx233.c
@@ -49,14 +49,11 @@ bool timer_set(long cycles, bool start)
49 49
50bool timer_start(IF_COP_VOID(int core)) 50bool timer_start(IF_COP_VOID(int core))
51{ 51{
52 imx233_timrot_setup(TIMER_USER, true, timer_cycles, 52 imx233_timrot_setup_simple(TIMER_USER, true, timer_cycles, TIMER_SRC_32KHZ, &timer_fn);
53 BV_TIMROT_TIMCTRLn_SELECT__32KHZ_XTAL, BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1,
54 false, &timer_fn);
55 return true; 53 return true;
56} 54}
57 55
58void timer_stop(void) 56void timer_stop(void)
59{ 57{
60 imx233_timrot_setup(TIMER_USER, false, 0, BV_TIMROT_TIMCTRLn_SELECT__NEVER_TICK, 58 imx233_timrot_setup_simple(TIMER_USER, false, 0, TIMER_SRC_STOP, NULL);
61 BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1, false, NULL);
62} 59}
diff --git a/firmware/target/arm/imx233/timrot-imx233.c b/firmware/target/arm/imx233/timrot-imx233.c
index 7c5e60c30e..91f24924d6 100644
--- a/firmware/target/arm/imx233/timrot-imx233.c
+++ b/firmware/target/arm/imx233/timrot-imx233.c
@@ -65,6 +65,49 @@ void imx233_timrot_set_priority(unsigned timer_nr, unsigned prio)
65 imx233_icoll_set_priority(INT_SRC_TIMER(timer_nr), prio); 65 imx233_icoll_set_priority(INT_SRC_TIMER(timer_nr), prio);
66} 66}
67 67
68static unsigned map_src(enum imx233_timrot_src_t src, unsigned *prescale)
69{
70 *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1;
71 switch(src)
72 {
73 case TIMER_SRC_24MHZ:
74 return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
75 case TIMER_SRC_12MHZ:
76 *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_2;
77 return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
78 case TIMER_SRC_6MHZ:
79 *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_4;
80 return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
81 case TIMER_SRC_3MHZ:
82 *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_8;
83 return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
84 case TIMER_SRC_32KHZ:
85 return BV_TIMROT_TIMCTRLn_SELECT__32KHZ_XTAL;
86 case TIMER_SRC_8KHZ:
87 return BV_TIMROT_TIMCTRLn_SELECT__8KHZ_XTAL;
88 case TIMER_SRC_4KHZ:
89 return BV_TIMROT_TIMCTRLn_SELECT__4KHZ_XTAL;
90 case TIMER_SRC_1KHZ:
91 return BV_TIMROT_TIMCTRLn_SELECT__1KHZ_XTAL;
92 case TIMER_SRC_STOP:
93 default:
94 return BV_TIMROT_TIMCTRLn_SELECT__NEVER_TICK;
95 }
96}
97
98void imx233_timrot_setup_simple(unsigned timer_nr, bool periodic, unsigned count,
99 enum imx233_timrot_src_t src, imx233_timer_fn_t fn)
100{
101 unsigned prescale;
102 unsigned hw_src = map_src(src, &prescale);
103 imx233_timrot_setup(timer_nr, periodic, count, hw_src, prescale, false, fn);
104}
105
106unsigned imx233_timrot_get_count(unsigned timer_nr)
107{
108 return BF_RD(TIMROT_TIMCOUNTn(timer_nr), RUNNING_COUNT);
109}
110
68struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr) 111struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr)
69{ 112{
70 struct imx233_timrot_info_t info; 113 struct imx233_timrot_info_t info;
diff --git a/firmware/target/arm/imx233/timrot-imx233.h b/firmware/target/arm/imx233/timrot-imx233.h
index 778cd1add9..0add64e9ce 100644
--- a/firmware/target/arm/imx233/timrot-imx233.h
+++ b/firmware/target/arm/imx233/timrot-imx233.h
@@ -25,6 +25,7 @@
25#include "cpu.h" 25#include "cpu.h"
26#include "icoll-imx233.h" 26#include "icoll-imx233.h"
27 27
28/* WARNING timrot code assumes APBX is running at 24MHz */
28/* list of timers */ 29/* list of timers */
29enum 30enum
30{ 31{
@@ -33,6 +34,20 @@ enum
33 TIMER_WATCHDOG, /* for watchdog */ 34 TIMER_WATCHDOG, /* for watchdog */
34}; 35};
35 36
37/* timer sources */
38enum imx233_timrot_src_t
39{
40 TIMER_SRC_24MHZ,
41 TIMER_SRC_12MHZ,
42 TIMER_SRC_6MHZ,
43 TIMER_SRC_3MHZ,
44 TIMER_SRC_32KHZ,
45 TIMER_SRC_8KHZ,
46 TIMER_SRC_4KHZ,
47 TIMER_SRC_1KHZ,
48 TIMER_SRC_STOP
49};
50
36struct imx233_timrot_info_t 51struct imx233_timrot_info_t
37{ 52{
38 unsigned fixed_count, run_count; 53 unsigned fixed_count, run_count;
@@ -45,10 +60,21 @@ struct imx233_timrot_info_t
45 60
46typedef void (*imx233_timer_fn_t)(void); 61typedef void (*imx233_timer_fn_t)(void);
47 62
63/* maximum count for non-periodic timers, add one for periodic timers */
64#define IMX233_TIMROT_MAX_COUNT 0xffff
65
48void imx233_timrot_init(void); 66void imx233_timrot_init(void);
67/* low-level function all-in-one function */
49void imx233_timrot_setup(unsigned timer_nr, bool reload, unsigned count, 68void imx233_timrot_setup(unsigned timer_nr, bool reload, unsigned count,
50 unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn); 69 unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn);
70/* change interrupt priority */
51void imx233_timrot_set_priority(unsigned timer_nr, unsigned prio); 71void imx233_timrot_set_priority(unsigned timer_nr, unsigned prio);
72/* simple setup function */
73void imx233_timrot_setup_simple(unsigned timer_nr, bool periodic, unsigned count,
74 enum imx233_timrot_src_t src, imx233_timer_fn_t fn);
75/* get timer count */
76unsigned imx233_timrot_get_count(unsigned timer_nr);
77/* update timer running count */
52struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr); 78struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr);
53 79
54#endif /* TIMROT_IMX233_H */ 80#endif /* TIMROT_IMX233_H */