Commit 1c1c7506de1051df6d81c51a06a57be6406b534c

Authored by Daniel Hellstrom
1 parent 0986546582

leon: use CONFIG_SYS_HZ to config timer prescaler

Before it was hardcoded to 1000 ticks per second.

Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>

Showing 2 changed files with 18 additions and 16 deletions Side-by-side Diff

arch/sparc/cpu/leon2/cpu_init.c
... ... @@ -13,6 +13,9 @@
13 13  
14 14 #include <config.h>
15 15  
  16 +#define TIMER_BASE_CLK 1000000
  17 +#define US_PER_TICK (1000000 / CONFIG_SYS_HZ)
  18 +
16 19 DECLARE_GLOBAL_DATA_PTR;
17 20  
18 21 /* reset CPU (jump to 0, without reset) */
... ... @@ -90,7 +93,7 @@
90 93 while (get_timer(start) < ticks) ;
91 94 }
92 95  
93   -/* initiate and setup timer0 interrupt to 1MHz
  96 +/* initiate and setup timer0 interrupt to configured HZ. Base clock is 1MHz.
94 97 * Return irq number for timer int or a negative number for
95 98 * dealing with self
96 99 */
97 100  
... ... @@ -98,9 +101,9 @@
98 101 {
99 102 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
100 103  
101   - /* 1ms ticks */
  104 + /* SYS_HZ ticks per second */
102 105 leon2->Timer_Counter_1 = 0;
103   - leon2->Timer_Reload_1 = 999; /* (((1000000 / 100) - 1)) */
  106 + leon2->Timer_Reload_1 = (TIMER_BASE_CLK / CONFIG_SYS_HZ) - 1;
104 107 leon2->Timer_Control_1 =
105 108 (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD);
106 109  
107 110  
108 111  
... ... @@ -112,15 +115,13 @@
112 115 */
113 116 unsigned long cpu_usec2ticks(unsigned long usec)
114 117 {
115   - /* timer set to 1kHz ==> 1 clk tick = 1 msec */
116   - if (usec < 1000)
  118 + if (usec < US_PER_TICK)
117 119 return 1;
118   - return (usec / 1000);
  120 + return usec / US_PER_TICK;
119 121 }
120 122  
121 123 unsigned long cpu_ticks2usec(unsigned long ticks)
122 124 {
123   - /* 1tick = 1usec */
124   - return ticks * 1000;
  125 + return ticks * US_PER_TICK;
125 126 }
arch/sparc/cpu/leon3/cpu_init.c
... ... @@ -14,6 +14,9 @@
14 14  
15 15 #include <config.h>
16 16  
  17 +#define TIMER_BASE_CLK 1000000
  18 +#define US_PER_TICK (1000000 / CONFIG_SYS_HZ)
  19 +
17 20 DECLARE_GLOBAL_DATA_PTR;
18 21  
19 22 /* reset CPU (jump to 0, without reset) */
20 23  
21 24  
... ... @@ -203,15 +206,15 @@
203 206 while (get_timer(start) < ticks) ;
204 207 }
205 208  
206   -/* initiate and setup timer0 interrupt to 1MHz
  209 +/* initiate and setup timer0 interrupt to configured HZ. Base clock is 1MHz.
207 210 * Return irq number for timer int or a negative number for
208 211 * dealing with self
209 212 */
210 213 int timer_interrupt_init_cpu(void)
211 214 {
212   - /* 1ms ticks */
  215 + /* SYS_HZ ticks per second */
213 216 gptimer->e[0].val = 0;
214   - gptimer->e[0].rld = 999; /* (((1000000 / 100) - 1)) */
  217 + gptimer->e[0].rld = (TIMER_BASE_CLK / CONFIG_SYS_HZ) - 1;
215 218 gptimer->e[0].ctrl =
216 219 (LEON3_GPTIMER_EN |
217 220 LEON3_GPTIMER_RL | LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
218 221  
219 222  
... ... @@ -224,15 +227,13 @@
224 227 */
225 228 unsigned long cpu_usec2ticks(unsigned long usec)
226 229 {
227   - /* timer set to 1kHz ==> 1 clk tick = 1 msec */
228   - if (usec < 1000)
  230 + if (usec < US_PER_TICK)
229 231 return 1;
230   - return (usec / 1000);
  232 + return usec / US_PER_TICK;
231 233 }
232 234  
233 235 unsigned long cpu_ticks2usec(unsigned long ticks)
234 236 {
235   - /* 1tick = 1usec */
236   - return ticks * 1000;
  237 + return ticks * US_PER_TICK;
237 238 }