2010-01-25 23:12:09 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* CC2430 RF driver
|
|
|
|
* \author
|
2012-03-05 16:28:06 +00:00
|
|
|
* Zach Shelby <zach@sensinode.com> (Original)
|
|
|
|
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
|
|
|
* (recent updates for the contiki cc2430 port)
|
2010-01-25 23:12:09 +00:00
|
|
|
*
|
|
|
|
* Non-bankable code for cc2430 rf driver.
|
2012-03-05 16:28:06 +00:00
|
|
|
* Interrupt routines must be placed into the HOME bank.
|
2010-01-25 23:12:09 +00: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 19:19:16 +00:00
|
|
|
#include "net/packetbuf.h"
|
2010-01-25 23:12:09 +00:00
|
|
|
#include "net/rime/rimestats.h"
|
2012-03-05 16:28:06 +00:00
|
|
|
#include "net/netstack.h"
|
2010-04-10 19:59:37 +00:00
|
|
|
#define DEBUG 0
|
2010-01-29 19:15:44 +00:00
|
|
|
#if DEBUG
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...) do {} while (0)
|
|
|
|
#endif
|
2010-01-25 23:12:09 +00: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 16:28:06 +00:00
|
|
|
PROCESS_NAME(cc2430_rf_process);
|
2010-01-25 23:12:09 +00:00
|
|
|
|
2012-04-01 20:43:22 +00:00
|
|
|
#if !NETSTACK_CONF_SHORTCUTS
|
2010-01-25 23:12:09 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* RF interrupt service routine.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cc2430_rf_ISR( void ) __interrupt (RF_VECTOR)
|
|
|
|
{
|
|
|
|
EA = 0;
|
2012-03-05 16:28:06 +00:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
|
|
|
/*
|
|
|
|
* We only vector here if RFSTATUS.FIFOP goes high.
|
|
|
|
* Just double check the flag.
|
|
|
|
*/
|
2010-01-25 23:12:09 +00: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 16:28:06 +00:00
|
|
|
|
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
2010-01-25 23:12:09 +00:00
|
|
|
EA = 1;
|
|
|
|
}
|
2012-03-05 16:28:06 +00:00
|
|
|
#endif
|
2010-01-25 23:12:09 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-03-05 16:28:06 +00:00
|
|
|
#if CC2430_RFERR_INTERRUPT
|
2010-01-25 23:12:09 +00:00
|
|
|
/**
|
|
|
|
* RF error interrupt service routine.
|
2012-03-05 16:28:06 +00:00
|
|
|
* Turned off by default, can be turned on in contiki-conf.h
|
2010-01-25 23:12:09 +00: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-03-05 16:28:06 +00:00
|
|
|
#endif
|
2010-01-29 19:15:44 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|