2010-01-26 00:12:09 +01:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* CC2430 RF driver
|
|
|
|
* \author
|
2012-03-05 17:28:06 +01:00
|
|
|
* Zach Shelby <zach@sensinode.com> (Original)
|
|
|
|
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
|
|
|
* (recent updates for the contiki cc2430 port)
|
2010-01-26 00:12:09 +01:00
|
|
|
*
|
|
|
|
* Non-bankable code for cc2430 rf driver.
|
2012-03-05 17:28:06 +01:00
|
|
|
* Interrupt routines must be placed into the HOME bank.
|
2010-01-26 00:12:09 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "dev/radio.h"
|
|
|
|
#include "dev/cc2430_rf.h"
|
|
|
|
#include "cc2430_sfr.h"
|
|
|
|
#ifdef RF_LED_ENABLE
|
|
|
|
#include "dev/leds.h"
|
|
|
|
#endif
|
|
|
|
#include "sys/clock.h"
|
|
|
|
|
2010-06-14 21:19:16 +02:00
|
|
|
#include "net/packetbuf.h"
|
2010-01-26 00:12:09 +01:00
|
|
|
#include "net/rime/rimestats.h"
|
2012-03-05 17:28:06 +01:00
|
|
|
#include "net/netstack.h"
|
2010-04-10 21:59:37 +02:00
|
|
|
#define DEBUG 0
|
2010-01-29 20:15:44 +01:00
|
|
|
#if DEBUG
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...) do {} while (0)
|
|
|
|
#endif
|
2010-01-26 00:12:09 +01:00
|
|
|
|
|
|
|
#ifdef RF_LED_ENABLE
|
|
|
|
#define RF_RX_LED_ON() leds_on(LEDS_RED);
|
|
|
|
#define RF_RX_LED_OFF() leds_off(LEDS_RED);
|
|
|
|
#define RF_TX_LED_ON() leds_on(LEDS_GREEN);
|
|
|
|
#define RF_TX_LED_OFF() leds_off(LEDS_GREEN);
|
|
|
|
#else
|
|
|
|
#define RF_RX_LED_ON()
|
|
|
|
#define RF_RX_LED_OFF()
|
|
|
|
#define RF_TX_LED_ON()
|
|
|
|
#define RF_TX_LED_OFF()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_RF_ERROR
|
|
|
|
uint8_t rf_error = 0;
|
|
|
|
#endif
|
|
|
|
|
2012-03-05 17:28:06 +01:00
|
|
|
PROCESS_NAME(cc2430_rf_process);
|
2010-01-26 00:12:09 +01:00
|
|
|
|
2012-04-01 22:43:22 +02:00
|
|
|
#if !NETSTACK_CONF_SHORTCUTS
|
2010-01-26 00:12:09 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* RF interrupt service routine.
|
|
|
|
*
|
|
|
|
*/
|
2012-09-07 15:48:15 +02:00
|
|
|
#pragma save
|
|
|
|
#if CC_CONF_OPTIMIZE_STACK_SIZE
|
|
|
|
#pragma exclude bits
|
|
|
|
#endif
|
2010-01-26 00:12:09 +01:00
|
|
|
void
|
|
|
|
cc2430_rf_ISR( void ) __interrupt (RF_VECTOR)
|
|
|
|
{
|
|
|
|
EA = 0;
|
2012-03-05 17:28:06 +01:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
|
|
|
/*
|
|
|
|
* We only vector here if RFSTATUS.FIFOP goes high.
|
|
|
|
* Just double check the flag.
|
|
|
|
*/
|
2010-01-26 00:12:09 +01:00
|
|
|
if(RFIF & IRQ_FIFOP) {
|
|
|
|
RF_RX_LED_ON();
|
|
|
|
/* Poll the RF process which calls cc2430_rf_read() */
|
|
|
|
process_poll(&cc2430_rf_process);
|
|
|
|
}
|
|
|
|
S1CON &= ~(RFIF_0 | RFIF_1);
|
2012-03-05 17:28:06 +01:00
|
|
|
|
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
2010-01-26 00:12:09 +01:00
|
|
|
EA = 1;
|
|
|
|
}
|
2012-09-07 15:48:15 +02:00
|
|
|
#pragma restore
|
2012-03-05 17:28:06 +01:00
|
|
|
#endif
|
2010-01-26 00:12:09 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-03-05 17:28:06 +01:00
|
|
|
#if CC2430_RFERR_INTERRUPT
|
2010-01-26 00:12:09 +01:00
|
|
|
/**
|
|
|
|
* RF error interrupt service routine.
|
2012-03-05 17:28:06 +01:00
|
|
|
* Turned off by default, can be turned on in contiki-conf.h
|
2010-01-26 00:12:09 +01:00
|
|
|
*/
|
2012-09-07 15:48:15 +02:00
|
|
|
#pragma save
|
|
|
|
#if CC_CONF_OPTIMIZE_STACK_SIZE
|
|
|
|
#pragma exclude bits
|
|
|
|
#endif
|
2010-01-26 00:12:09 +01:00
|
|
|
void
|
|
|
|
cc2430_rf_error_ISR( void ) __interrupt (RFERR_VECTOR)
|
|
|
|
{
|
|
|
|
EA = 0;
|
|
|
|
TCON_RFERRIF = 0;
|
|
|
|
#ifdef HAVE_RF_ERROR
|
|
|
|
rf_error = 254;
|
|
|
|
#endif
|
|
|
|
cc2430_rf_command(ISRFOFF);
|
|
|
|
cc2430_rf_command(ISFLUSHRX);
|
|
|
|
cc2430_rf_command(ISFLUSHRX);
|
|
|
|
cc2430_rf_command(ISRXON);
|
|
|
|
RF_RX_LED_OFF();
|
|
|
|
RF_TX_LED_OFF();
|
|
|
|
EA = 1;
|
|
|
|
}
|
2012-09-07 15:48:15 +02:00
|
|
|
#pragma restore
|
2012-03-05 17:28:06 +01:00
|
|
|
#endif
|
2010-01-29 20:15:44 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|