2014-02-02 16:48:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 INRIA
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-02-02 16:48:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cpu
|
|
|
|
* @{
|
|
|
|
*
|
2014-02-03 00:47:38 +01:00
|
|
|
* @file hwtimer_msp430_.c
|
2014-12-01 17:32:29 +01:00
|
|
|
* @brief MSP430Fxyz timer functions
|
2014-02-02 16:48:18 +01:00
|
|
|
*
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
|
|
|
* @author Milan Babel <babel@inf.fu-berlin.de>
|
|
|
|
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2013-12-19 10:22:44 +01:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "hwtimer.h"
|
2014-07-09 21:08:13 +02:00
|
|
|
#include "arch/hwtimer_arch.h"
|
2010-12-08 12:16:49 +01:00
|
|
|
|
2014-04-28 14:28:34 +02:00
|
|
|
#define ENABLE_DEBUG (1)
|
2014-03-20 23:12:38 +01:00
|
|
|
#include "debug.h"
|
|
|
|
|
2010-12-08 12:16:49 +01:00
|
|
|
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
|
|
|
|
2014-04-28 14:28:34 +02:00
|
|
|
msp430_timer_t msp430_timer[HWTIMER_MAXTIMERS];
|
|
|
|
|
|
|
|
#define CCRA_NUM_TO_INDEX(ccr) (ccr)
|
|
|
|
|
2013-02-11 22:10:03 +01:00
|
|
|
void timerA_init(void)
|
2010-12-08 12:16:49 +01:00
|
|
|
{
|
2014-03-20 23:12:38 +01:00
|
|
|
TACTL = TASSEL_1 + TACLR; /* Clear the timer counter, set ACLK */
|
2014-04-28 14:28:34 +02:00
|
|
|
TACTL &= ~(TAIFG); /* Clear the IFG */
|
|
|
|
TACTL &= ~(TAIE); /* Disable TAIE (overflow IRQ) */
|
2010-12-08 12:16:49 +01:00
|
|
|
|
2014-04-28 14:28:34 +02:00
|
|
|
for (uint8_t i = 0; i < TIMER_A_MAXCOMP; i++) {
|
2014-09-30 11:35:29 +02:00
|
|
|
volatile unsigned int *ccr = &TACCR0 + (i);
|
|
|
|
volatile unsigned int *ctl = &TACCTL0 + (i);
|
2010-12-08 12:16:49 +01:00
|
|
|
*ccr = 0;
|
|
|
|
*ctl &= ~(CCIFG);
|
|
|
|
*ctl &= ~(CCIE);
|
2014-04-28 14:28:34 +02:00
|
|
|
|
|
|
|
/* intialize the corresponding msp430_timer struct */
|
|
|
|
short index = CCRA_NUM_TO_INDEX(i);
|
|
|
|
msp430_timer[index].base_timer = TIMER_A;
|
|
|
|
msp430_timer[index].ccr_num = i;
|
2010-12-08 12:16:49 +01:00
|
|
|
}
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-10-01 15:21:54 +02:00
|
|
|
TACTL |= MC_2;
|
2010-12-08 12:16:49 +01:00
|
|
|
}
|
|
|
|
|
2014-04-28 14:28:34 +02:00
|
|
|
interrupt(TIMERA0_VECTOR) __attribute__((naked)) timerA_isr_ccr0(void)
|
2013-06-21 03:52:57 +02:00
|
|
|
{
|
2010-12-08 12:16:49 +01:00
|
|
|
__enter_isr();
|
2014-04-01 11:04:31 +02:00
|
|
|
|
2014-04-28 14:28:34 +02:00
|
|
|
short timer = CCRA_NUM_TO_INDEX(0);
|
|
|
|
timer_unset(timer);
|
|
|
|
int_handler(timer);
|
2014-04-01 11:04:31 +02:00
|
|
|
|
2010-12-08 12:16:49 +01:00
|
|
|
__exit_isr();
|
|
|
|
}
|
|
|
|
|
2014-04-28 14:28:34 +02:00
|
|
|
interrupt(TIMERA1_VECTOR) __attribute__((naked)) timerA_isr(void)
|
2013-06-21 03:52:57 +02:00
|
|
|
{
|
2010-12-08 12:16:49 +01:00
|
|
|
__enter_isr();
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2014-08-27 10:25:46 +02:00
|
|
|
/* determine which CCR has been hit, and fire the appropriate callback */
|
2014-04-28 14:28:34 +02:00
|
|
|
short timer = CCRA_NUM_TO_INDEX(TAIV >> 1);
|
2014-08-27 10:25:46 +02:00
|
|
|
timer_unset(timer);
|
|
|
|
int_handler(timer);
|
2014-02-16 20:50:48 +01:00
|
|
|
|
2010-12-08 12:16:49 +01:00
|
|
|
__exit_isr();
|
|
|
|
}
|