dhenry:
The ide does not hide anything: you can always code the mcu by writing to the registers.
However, in this case, they use a set of libraries from nxp to operate the peripherals. That's not unusual: ST has a set of its own libraries.
Without those libraries working with ARM peripherals is really not practical.
If indeed one have to write all these lines of code to initialize a timer I imagine that not many people would dare to attack ARMs.
/******************************************************************************
** Function name: init_timer
**
** Descriptions: Initialize timer, set timer interval, reset timer,
** install timer interrupt handler
**
** parameters: timer number and timer interval
** Returned value: None
**
******************************************************************************/
void init_timer32(uint8_t timer_num, uint32_t TimerInterval)
{
if ( timer_num == 0 )
{
/* Some of the I/O pins need to be carefully planned if
you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
LPC_IOCON->PIO1_5 &= ~0x07; /* Timer0_32 I/O config */
LPC_IOCON->PIO1_5 |= 0x02; /* Timer0_32 CAP0 */
LPC_IOCON->PIO1_6 &= ~0x07;
LPC_IOCON->PIO1_6 |= 0x02; /* Timer0_32 MAT0 */
LPC_IOCON->PIO1_7 &= ~0x07;
LPC_IOCON->PIO1_7 |= 0x02; /* Timer0_32 MAT1 */
LPC_IOCON->PIO0_1 &= ~0x07;
LPC_IOCON->PIO0_1 |= 0x02; /* Timer0_32 MAT2 */
#ifdef __JTAG_DISABLED
LPC_IOCON->JTAG_TDI_PIO0_11 &= ~0x07;
LPC_IOCON->JTAG_TDI_PIO0_11 |= 0x03; /* Timer0_32 MAT3 */
#endif
#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
timer32_0_counter = 0;
timer32_0_capture = 0;
#endif //TIMER32_0_DEFAULT_HANDLER
LPC_TMR32B0->MR0 = TimerInterval;
#if TIMER_MATCH
LPC_TMR32B0->EMR &= ~(0xFF<<4);
LPC_TMR32B0->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10)); /* MR0/1/2/3 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
LPC_TMR32B0->CCR = (0x1<<0)|(0x1<<2);
#endif
LPC_TMR32B0->MCR = 3; /* Interrupt and Reset on MR0 */
#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
/* Enable the TIMER0 Interrupt */
NVIC_EnableIRQ(TIMER_32_0_IRQn);
#endif
}
else if ( timer_num == 1 )
{
/* Some of the I/O pins need to be clearfully planned if
you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10);
#ifdef __JTAG_DISABLED
LPC_IOCON->JTAG_TMS_PIO1_0 &= ~0x07; /* Timer1_32 I/O config */
LPC_IOCON->JTAG_TMS_PIO1_0 |= 0x03; /* Timer1_32 CAP0 */
LPC_IOCON->JTAG_TDO_PIO1_1 &= ~0x07;
LPC_IOCON->JTAG_TDO_PIO1_1 |= 0x03; /* Timer1_32 MAT0 */
LPC_IOCON->JTAG_nTRST_PIO1_2 &= ~0x07;
LPC_IOCON->JTAG_nTRST_PIO1_2 |= 0x03; /* Timer1_32 MAT1 */
LPC_IOCON->ARM_SWDIO_PIO1_3 &= ~0x07;
LPC_IOCON->ARM_SWDIO_PIO1_3 |= 0x03; /* Timer1_32 MAT2 */
#endif
LPC_IOCON->PIO1_4 &= ~0x07;
LPC_IOCON->PIO1_4 |= 0x02; /* Timer0_32 MAT3 */
#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
timer32_1_counter = 0;
timer32_1_capture = 0;
#endif //TIMER32_1_DEFAULT_HANDLER
LPC_TMR32B1->MR0 = TimerInterval;
#if TIMER_MATCH
LPC_TMR32B1->EMR &= ~(0xFF<<4);
LPC_TMR32B1->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10)); /* MR0/1/2 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
LPC_TMR32B1->CCR = (0x1<<0)|(0x1<<2);
#endif
LPC_TMR32B1->MCR = 3; /* Interrupt and Reset on MR0 */
#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
/* Enable the TIMER1 Interrupt */
NVIC_EnableIRQ(TIMER_32_1_IRQn);
#endif
}
return;
}
Maybe not all the code above is necessary for a particular application. I do not know.
There is another problem, sometimes you have to change the parameters of a timer on the run as fast as possible between two events that are 10-20 clock cycles apart.
It seems like functions as "init_timer32" need more than 20 clk. ticks. Is there workarounds?