Contiki 2.6
|
00001 /** 00002 * \file 00003 * CC2430 RF driver 00004 * \author 00005 * Zach Shelby <zach@sensinode.com> (Original) 00006 * George Oikonomou - <oikonomou@users.sourceforge.net> 00007 * (recent updates for the contiki cc2430 port) 00008 * 00009 * Non-bankable code for cc2430 rf driver. 00010 * Interrupt routines must be placed into the HOME bank. 00011 * 00012 */ 00013 00014 #include <stdio.h> 00015 00016 #include "contiki.h" 00017 #include "dev/radio.h" 00018 #include "dev/cc2430_rf.h" 00019 #include "cc2430_sfr.h" 00020 #ifdef RF_LED_ENABLE 00021 #include "dev/leds.h" 00022 #endif 00023 #include "sys/clock.h" 00024 00025 #include "net/packetbuf.h" 00026 #include "net/rime/rimestats.h" 00027 #include "net/netstack.h" 00028 #define DEBUG 0 00029 #if DEBUG 00030 #define PRINTF(...) printf(__VA_ARGS__) 00031 #else 00032 #define PRINTF(...) do {} while (0) 00033 #endif 00034 00035 #ifdef RF_LED_ENABLE 00036 #define RF_RX_LED_ON() leds_on(LEDS_RED); 00037 #define RF_RX_LED_OFF() leds_off(LEDS_RED); 00038 #define RF_TX_LED_ON() leds_on(LEDS_GREEN); 00039 #define RF_TX_LED_OFF() leds_off(LEDS_GREEN); 00040 #else 00041 #define RF_RX_LED_ON() 00042 #define RF_RX_LED_OFF() 00043 #define RF_TX_LED_ON() 00044 #define RF_TX_LED_OFF() 00045 #endif 00046 00047 #ifdef HAVE_RF_ERROR 00048 uint8_t rf_error = 0; 00049 #endif 00050 00051 PROCESS_NAME(cc2430_rf_process); 00052 00053 #if !NETSTACK_CONF_SHORTCUTS 00054 /*---------------------------------------------------------------------------*/ 00055 /** 00056 * RF interrupt service routine. 00057 * 00058 */ 00059 void 00060 cc2430_rf_ISR( void ) __interrupt (RF_VECTOR) 00061 { 00062 EA = 0; 00063 ENERGEST_ON(ENERGEST_TYPE_IRQ); 00064 /* 00065 * We only vector here if RFSTATUS.FIFOP goes high. 00066 * Just double check the flag. 00067 */ 00068 if(RFIF & IRQ_FIFOP) { 00069 RF_RX_LED_ON(); 00070 /* Poll the RF process which calls cc2430_rf_read() */ 00071 process_poll(&cc2430_rf_process); 00072 } 00073 S1CON &= ~(RFIF_0 | RFIF_1); 00074 00075 ENERGEST_OFF(ENERGEST_TYPE_IRQ); 00076 EA = 1; 00077 } 00078 #endif 00079 /*---------------------------------------------------------------------------*/ 00080 #if CC2430_RFERR_INTERRUPT 00081 /** 00082 * RF error interrupt service routine. 00083 * Turned off by default, can be turned on in contiki-conf.h 00084 */ 00085 void 00086 cc2430_rf_error_ISR( void ) __interrupt (RFERR_VECTOR) 00087 { 00088 EA = 0; 00089 TCON_RFERRIF = 0; 00090 #ifdef HAVE_RF_ERROR 00091 rf_error = 254; 00092 #endif 00093 cc2430_rf_command(ISRFOFF); 00094 cc2430_rf_command(ISFLUSHRX); 00095 cc2430_rf_command(ISFLUSHRX); 00096 cc2430_rf_command(ISRXON); 00097 RF_RX_LED_OFF(); 00098 RF_TX_LED_OFF(); 00099 EA = 1; 00100 } 00101 #endif 00102 /*---------------------------------------------------------------------------*/