37 lines
1.1 KiB
C
37 lines
1.1 KiB
C
#include "timer_a1.h"
|
|
|
|
#include "inc/msp432p401r.h"
|
|
|
|
void (*timer_a1_task)(void); // user function
|
|
|
|
// Activate Timer A1 interrupts to run user task periodically
|
|
// 16 bits period in units (24/SMCLK, with SMCLK 12 MHz -> 2us)
|
|
void TimerA1Init(void (*task)(void), uint16_t period) {
|
|
timer_a1_task = task;
|
|
|
|
// bits9-8=10, clock source to SMCLK
|
|
// bits7-6=10, input clock divider
|
|
// bits5-4=00, stop mode
|
|
// bit2=0, set this bit to clear
|
|
// bit1=0, no interrupt on
|
|
TIMER_A1->CTL = 0x0280;
|
|
|
|
// bits15-14=00, no capture mode
|
|
// bit8=0, compare mode
|
|
// bit4=1, enable capture/compare interrupt on CCIFG
|
|
// bit2=0, output this value in output mode 0
|
|
TIMER_A1->CCTL[0] &= ~0x0001;
|
|
|
|
TIMER_A1->CCR[0] = (period - 1);
|
|
TIMER_A1->EX0 = 0x0005;
|
|
NVIC->IP[3] = (NVIC->IP[3]&0xFFFFFF00)|0x00000040; // priority 2
|
|
NVIC->ISER[0] = 0x00001000; // enable interrupt 12 in NVIC
|
|
TIMER_A1->CTL |= 0x0014; // reset and start Timer A in up mode
|
|
TIMER_A1->CTL |= 0x0020; // Enable Timer A1 interrupts (TAIE)
|
|
}
|
|
|
|
void TA1_0_IRQHandler(void) {
|
|
TIMER_A1->CCTL[0] &= ~0x0001;
|
|
timer_a1_task();
|
|
}
|