8#include "timer_msp432.h"
10extern uint32_t SystemCoreClock;
12function<void()> timer_msp432::_intHandler1 = 0;
13function<void()> timer_msp432::_intHandler2 = 0;
26 _factor = ((float) SystemCoreClock / 1000000.0) + 0.5;
31 NVIC_EnableIRQ((timer == TIMER32_1) ? T32_INT1_IRQn : T32_INT2_IRQn);
34timer_msp432::~timer_msp432() {
38void timer_msp432::setPeriod(uint32_t us, TIMER::timer_mode mode) {
41 _timer->
LOAD = _period_load = us * _factor;
43 if (mode == TIMER::ONE_SHOT) {
46 _timer->
CONTROL &= ~TIMER32_CONTROL_ONESHOT;
50uint32_t timer_msp432::getPeriod() {
54void timer_msp432::setCallback(function<
void()> f) {
55 if (_timer == TIMER32_1) {
56 timer_msp432::_intHandler1 = f;
58 timer_msp432::_intHandler2 = f;
62void timer_msp432::start() {
63 _timer->
CONTROL |= TIMER32_CONTROL_ENABLE;
66void timer_msp432::stop() {
67 _timer->
CONTROL &= ~TIMER32_CONTROL_ENABLE;
70bool timer_msp432::isRunning() {
71 return _timer->
CONTROL & TIMER32_CONTROL_ENABLE;
74void timer_msp432::reset() {
75 _timer->
LOAD = _period_load;
78void timer_msp432::setNanoPeriod(uint32_t ns, TIMER::timer_mode mode) {
81 _timer->
LOAD = _period_load = (ns * _factor) / 1000;
83 if (mode == TIMER::ONE_SHOT) {
86 _timer->
CONTROL &= ~TIMER32_CONTROL_ONESHOT;
90uint32_t timer_msp432::getNanoPeriod() {
98void T32_INT1_IRQHandler(
void) {
100 TIMER32_1->INTCLR = 1;
103 TIMER32_1->CONTROL &= ~TIMER32_CONTROL_ENABLE;
105 if (timer_msp432::_intHandler1) {
106 timer_msp432::_intHandler1();
109void T32_INT2_IRQHandler(
void) {
111 TIMER32_2->INTCLR = 1;
114 TIMER32_2->CONTROL &= ~TIMER32_CONTROL_ENABLE;
116 if (timer_msp432::_intHandler2) {
117 timer_msp432::_intHandler2();
#define TIMER32_CONTROL_SIZE
#define TIMER32_CONTROL_ONESHOT
#define TIMER32_CONTROL_IE
#define TIMER32_CONTROL_MODE