lpc176x: Divide system clock within timer; not on system bus

Scaling the timer on the system bus has a notable impact on
performance.  So, scale the timer within the timer hardware itself.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-10-18 09:37:47 -04:00
parent 0079311b0b
commit 8fca908445
1 changed files with 3 additions and 0 deletions

View File

@ -37,6 +37,9 @@ timer_init(void)
{ {
// Disable timer // Disable timer
LPC_TIM0->TCR = 0x02; LPC_TIM0->TCR = 0x02;
// Setup clock and prescaler (divide sys clock by 4)
LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & ~(0x3<<2)) | (0x1<<2);
LPC_TIM0->PR = 3;
// Enable interrupts // Enable interrupts
NVIC_SetPriority(TIMER0_IRQn, 2); NVIC_SetPriority(TIMER0_IRQn, 2);
NVIC_EnableIRQ(TIMER0_IRQn); NVIC_EnableIRQ(TIMER0_IRQn);