added initial set-up code SFD capture interrupts usable for exact packet timestamping

This commit is contained in:
joxe 2009-04-02 22:23:06 +00:00
parent 4507891ed5
commit 7d2a08b29c

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)$Id: cc2420-arch.c,v 1.2 2008/07/02 09:05:40 adamdunkels Exp $ * @(#)$Id: cc2420-arch.c,v 1.3 2009/04/02 22:23:06 joxe Exp $
*/ */
#include <io.h> #include <io.h>
@ -38,6 +38,11 @@
#include "dev/spi.h" #include "dev/spi.h"
#include "dev/cc2420.h" #include "dev/cc2420.h"
#ifdef CONF_SFD_TIMESTAMPS
uint16_t sfd_start_time;
uint16_t sfd_end_time;
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
interrupt(PORT1_VECTOR) interrupt(PORT1_VECTOR)
cc24240_port1_interrupt(void) cc24240_port1_interrupt(void)
@ -48,14 +53,49 @@ cc24240_port1_interrupt(void)
} }
ENERGEST_OFF(ENERGEST_TYPE_IRQ); ENERGEST_OFF(ENERGEST_TYPE_IRQ);
} }
#ifdef CONF_SFD_TIMESTAMPS
/*---------------------------------------------------------------------------*/
/* SFD interrupt for timestamping radio packets */
interrupt(TIMERB1_VECTOR)
cc24240_timerb1_interrupt(void)
{
int tbiv;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
/* always read TBIV to clear IFG */
tbiv = TBIV;
if(SFD_IS_1) {
start_time = TBCCR1;
} else {
end_time = TBCCR1;
}
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
cc2420_arch_init(void) cc2420_arch_init(void)
{ {
spi_init(); spi_init();
/* all input by default, set these as output */
P4DIR |= BV(CSN) | BV(VREG_EN) | BV(RESET_N); P4DIR |= BV(CSN) | BV(VREG_EN) | BV(RESET_N);
#ifdef CONF_SFD_TIMESTAMPS
/* Need to select the special function! */
P4SEL = BV(SFD);
/* start timer B - 32768 ticks per second */
TBCTL = TBSSEL_1 | TBCLR;
/* CM_3 = capture mode - capture on both edges */
TBCCTL1 = CM_3 | CAP | SCS;
TBCCTL1 |= CCIE;
/* Start Timer_B in continuous mode. */
TBCTL |= MC1;
#endif
SPI_DISABLE(); /* Unselect radio. */ SPI_DISABLE(); /* Unselect radio. */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/