2013-03-30 21:44:16 +01:00
|
|
|
#include <legacymsp430.h>
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "board.h"
|
|
|
|
#include "hwtimer.h"
|
|
|
|
#include "hwtimer_arch.h"
|
|
|
|
#include "cpu.h"
|
2010-12-08 12:16:49 +01:00
|
|
|
|
2013-07-24 00:36:06 +02:00
|
|
|
#define ENABLE_DEBUG (0)
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "debug.h"
|
2010-12-09 13:24:24 +01:00
|
|
|
|
2010-12-08 12:16:49 +01:00
|
|
|
static uint32_t ticks = 0;
|
|
|
|
|
|
|
|
extern void (*int_handler)(int);
|
2013-10-01 15:21:54 +02:00
|
|
|
extern void timer_unset(short timer);
|
2010-12-08 12:16:49 +01:00
|
|
|
|
2013-03-30 21:44:16 +01:00
|
|
|
void timerA_init(void)
|
2010-12-08 12:16:49 +01:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
ticks = 0; // Set tick counter value to 0
|
|
|
|
TA0CTL = TASSEL_1 + TACLR; // Clear the timer counter, set ACLK
|
|
|
|
TA0CTL &= ~TAIE; // Clear the IFG
|
|
|
|
|
2010-12-08 18:18:06 +01:00
|
|
|
volatile unsigned int *ccr = &TA0CCR0;
|
2010-12-08 12:16:49 +01:00
|
|
|
volatile unsigned int *ctl = &TA0CCTL0;
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
for (int i = 0; i < ARCH_MAXTIMERS; i++) {
|
2013-06-21 03:52:57 +02:00
|
|
|
*(ccr + i) = 0;
|
|
|
|
*(ctl + i) &= ~(CCIFG);
|
|
|
|
*(ctl + i) &= ~(CCIE);
|
2010-12-08 12:16:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TA0CTL |= MC_2;
|
|
|
|
}
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
interrupt(TIMER0_A0_VECTOR) __attribute__((naked)) timer0_a0_isr(void)
|
|
|
|
{
|
2010-12-08 12:16:49 +01:00
|
|
|
__enter_isr();
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-10-01 15:21:54 +02:00
|
|
|
timer_unset(0);
|
2010-12-08 12:16:49 +01:00
|
|
|
int_handler(0);
|
|
|
|
__exit_isr();
|
|
|
|
}
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
interrupt(TIMER0_A1_VECTOR) __attribute__((naked)) timer0_a1_5_isr(void)
|
|
|
|
{
|
2010-12-08 12:16:49 +01:00
|
|
|
__enter_isr();
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2010-12-08 12:16:49 +01:00
|
|
|
short taiv = TA0IV;
|
|
|
|
short timer;
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (taiv & TAIFG) {
|
2010-12-09 13:24:24 +01:00
|
|
|
DEBUG("Overflow\n");
|
|
|
|
}
|
|
|
|
else {
|
2013-06-21 03:52:57 +02:00
|
|
|
timer = (taiv / 2);
|
2013-10-01 15:21:54 +02:00
|
|
|
timer_unset(timer);
|
2010-12-09 13:24:24 +01:00
|
|
|
int_handler(timer);
|
2013-06-21 03:52:57 +02:00
|
|
|
}
|
|
|
|
|
2010-12-08 12:16:49 +01:00
|
|
|
__exit_isr();
|
|
|
|
}
|