1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/lpc2387: timer: use lpc2387_pclk_scale()

This commit is contained in:
Benjamin Valentin 2020-04-19 02:22:17 +02:00
parent 91200aa6ea
commit 370fff90a8

View File

@ -73,20 +73,20 @@ static inline lpc23xx_timer_t *get_dev(tim_t tim)
}
}
static inline void pwr_clk_and_isr(tim_t tim)
static inline void pwr_clk_and_isr(tim_t tim, uint32_t scale)
{
switch (tim) {
case 0:
PCONP |= (1 << 1);
PCLKSEL0 &= ~(0x03 << 2);
PCLKSEL0 |= (0x01 << 2);
PCLKSEL0 |= (scale << 2);
install_irq(TIMER0_INT, &tim_isr_0, 1);
break;
#if TIMER_NUMOF > 1
case 1:
PCONP |= (1 << 2);
PCLKSEL0 &= ~(0x03 << 4);
PCLKSEL0 |= (0x01 << 4);
PCLKSEL0 |= (scale << 4);
install_irq(TIMER1_INT, &tim_isr_1, 1);
break;
#endif
@ -94,7 +94,7 @@ static inline void pwr_clk_and_isr(tim_t tim)
case 2:
PCONP |= (1 << 22);
PCLKSEL1 &= ~(0x03 << 12);
PCLKSEL1 |= (0x01 << 12);
PCLKSEL1 |= (scale << 12);
install_irq(TIMER2_INT, &tim_isr_2, 1);
break;
#endif
@ -102,7 +102,7 @@ static inline void pwr_clk_and_isr(tim_t tim)
case 3:
PCONP |= (1 << 23);
PCLKSEL1 &= ~(0x03 << 14);
PCLKSEL1 |= (0x01 << 14);
PCLKSEL1 |= (scale << 14);
install_irq(TIMER3_INT, &tim_isr_3, 1);
break;
#endif
@ -119,16 +119,19 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
return -1;
}
uint32_t scale, prescale;
lpc2387_pclk_scale(CLOCK_PCLK, freq, &scale, &prescale);
/* save the callback */
isr_ctx[tim].cb = cb;
isr_ctx[tim].arg = arg;
/* enable power, config periph clock and install ISR vector */
pwr_clk_and_isr(tim);
pwr_clk_and_isr(tim, scale);
/* reset timer configuration (sets the timer to timer mode) */
dev->TCR = 0;
dev->CTCR = 0;
/* configure the prescaler */
dev->PR = (CLOCK_PCLK / freq) - 1;
dev->PR = prescale - 1;
/* enable timer */
dev->TCR = 1;
return 0;