2014-02-02 16:48:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 INRIA
|
|
|
|
*
|
|
|
|
* The source code is licensed under the LGPLv2 license,
|
|
|
|
* See the file LICENSE for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cc430
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief cc430 hardware timer driver
|
|
|
|
*
|
|
|
|
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
2014-02-03 00:47:38 +01:00
|
|
|
* @author Aleksandr Mikoff <sir.enmity@gmail.com>
|
2014-02-02 16:48:18 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-03-20 23:12:38 +01:00
|
|
|
#include "cpu.h"
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "hwtimer.h"
|
|
|
|
#include "hwtimer_arch.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);
|
2014-03-20 23:12:38 +01:00
|
|
|
extern uint16_t overflow_interrupt[HWTIMER:_MAXTIMERS+1];
|
|
|
|
extern uint16_t timer_round;
|
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
|
|
|
{
|
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;
|
2014-03-20 23:12:38 +01:00
|
|
|
ticks = 0; /* Set tick counter value to 0 */
|
|
|
|
timer_round = 0; /* Set to round 0 */
|
|
|
|
TA0CTL = TASSEL_1 + TACLR; /* Clear the timer counter, set ACLK */
|
|
|
|
TA0CTL &= ~TAIFG; /* Clear the IFG */
|
|
|
|
TA0CTL |= TAIE; /* Enable TAIE (overflow IRQ) */
|
2010-12-08 12:16:49 +01:00
|
|
|
|
2014-03-21 17:31:55 +01:00
|
|
|
for (int i = 0; i < HWTIMER_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();
|
2014-03-20 23:12:38 +01:00
|
|
|
if (overflow_interrupt[0] == timer_round) {
|
|
|
|
timer_unset(0);
|
|
|
|
int_handler(0);
|
|
|
|
}
|
2010-12-08 12:16:49 +01:00
|
|
|
__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;
|
2014-03-20 23:12:38 +01:00
|
|
|
short timer = taiv / 2;
|
|
|
|
/* TAIV = 0x0E means overflow */
|
|
|
|
if (taiv == 0x0E) {
|
2010-12-09 13:24:24 +01:00
|
|
|
DEBUG("Overflow\n");
|
2014-03-20 23:12:38 +01:00
|
|
|
timer_round += 1;
|
2010-12-09 13:24:24 +01:00
|
|
|
}
|
2014-03-20 23:12:38 +01:00
|
|
|
/* check which CCR has been hit and if the overflow counter for this timer
|
|
|
|
* has been reached */
|
|
|
|
else if (overflow_interrupt[timer] == timer_round) {
|
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();
|
|
|
|
}
|