cc2430_rf_intr.c

Go to the documentation of this file.
00001 /**
00002  * \file
00003  *         CC2430 RF driver
00004  * \author
00005  *         Zach Shelby <zach@sensinode.com>
00006  *
00007  *  Non-bankable code for cc2430 rf driver.  
00008  *  Interrupt routine and code called through function pointers
00009  *  must be placed into the HOME bank.
00010  *
00011  */
00012 
00013 #include <stdio.h>
00014 
00015 #include "contiki.h"
00016 #include "dev/radio.h"
00017 #include "dev/cc2430_rf.h"
00018 #include "cc2430_sfr.h"
00019 #ifdef RF_LED_ENABLE
00020 #include "dev/leds.h"
00021 #endif
00022 #include "sys/clock.h"
00023 
00024 #include "net/packetbuf.h"
00025 #include "net/rime/rimestats.h"
00026 #define DEBUG 0
00027 #if DEBUG
00028 #define PRINTF(...) printf(__VA_ARGS__)
00029 #else
00030 #define PRINTF(...) do {} while (0)
00031 #endif
00032 
00033 #ifdef RF_LED_ENABLE
00034 #define RF_RX_LED_ON()          leds_on(LEDS_RED);
00035 #define RF_RX_LED_OFF()         leds_off(LEDS_RED);
00036 #define RF_TX_LED_ON()          leds_on(LEDS_GREEN);
00037 #define RF_TX_LED_OFF()         leds_off(LEDS_GREEN);
00038 #else
00039 #define RF_RX_LED_ON()
00040 #define RF_RX_LED_OFF()
00041 #define RF_TX_LED_ON()
00042 #define RF_TX_LED_OFF()
00043 #endif
00044 
00045 #ifdef HAVE_RF_ERROR
00046 uint8_t rf_error = 0;
00047 #endif
00048 
00049 
00050 /*---------------------------------------------------------------------------*/
00051 PROCESS(cc2430_rf_process, "CC2430 RF driver");
00052 
00053 /*---------------------------------------------------------------------------*/
00054 /**
00055  * RF interrupt service routine.
00056  *
00057  */
00058 void
00059 cc2430_rf_ISR( void ) __interrupt (RF_VECTOR)
00060 {
00061   EA = 0;
00062   if(RFIF & IRQ_TXDONE) {
00063     RF_TX_LED_OFF();
00064     RFIF &= ~IRQ_TXDONE;
00065     cc2430_rf_command(ISFLUSHTX);
00066   }
00067   if(RFIF & IRQ_FIFOP) {
00068     if(RFSTATUS & FIFO) {
00069       RF_RX_LED_ON();
00070       /* Poll the RF process which calls cc2430_rf_read() */
00071       process_poll(&cc2430_rf_process);
00072     } else {
00073       cc2430_rf_command(ISFLUSHRX);
00074       cc2430_rf_command(ISFLUSHRX);
00075       RFIF &= ~IRQ_FIFOP;
00076     }
00077   }
00078   S1CON &= ~(RFIF_0 | RFIF_1);
00079   EA = 1;
00080 }
00081 /*---------------------------------------------------------------------------*/
00082 /**
00083  * RF error interrupt service routine.
00084  *
00085  */
00086 void
00087 cc2430_rf_error_ISR( void ) __interrupt (RFERR_VECTOR)
00088 {
00089   EA = 0;
00090   TCON_RFERRIF = 0;
00091 #ifdef HAVE_RF_ERROR
00092   rf_error = 254;
00093 #endif
00094   cc2430_rf_command(ISRFOFF);
00095   cc2430_rf_command(ISFLUSHRX);
00096   cc2430_rf_command(ISFLUSHRX);
00097   cc2430_rf_command(ISRXON);
00098   RF_RX_LED_OFF();
00099   RF_TX_LED_OFF();
00100   EA = 1;
00101 }
00102 
00103 void (* receiver_callback)(const struct radio_driver *);
00104 
00105 void
00106 cc2430_rf_set_receiver(void (* recv)(const struct radio_driver *))
00107 {
00108   receiver_callback = recv;
00109 }
00110 /*---------------------------------------------------------------------------*/
00111 /* 
00112  * non-banked functions called through function pointers then call banked code
00113  */
00114 int
00115 cc2430_rf_off(void)
00116 {
00117   return cc2430_rf_rx_disable();
00118 }
00119 /*---------------------------------------------------------------------------*/
00120 int
00121 cc2430_rf_on(void)
00122 {
00123   return cc2430_rf_rx_enable();
00124 }
00125 /*---------------------------------------------------------------------------*/
00126 int
00127 cc2430_rf_send(void *payload, unsigned short payload_len)
00128 {
00129   return cc2430_rf_send_b(payload, payload_len);
00130 }
00131 /*---------------------------------------------------------------------------*/
00132 int
00133 cc2430_rf_read(void *buf, unsigned short bufsize) 
00134 {
00135   return cc2430_rf_read_banked(buf, bufsize);
00136 }
00137 /*---------------------------------------------------------------------------*/
00138 /*---------------------------------------------------------------------------*/
00139 PROCESS_THREAD(cc2430_rf_process, ev, data)
00140 {
00141   PROCESS_BEGIN();
00142   while(1) {
00143     PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
00144 
00145     if(receiver_callback != NULL) {
00146       PRINTF("cc2430_rf_process: calling receiver callback\n");
00147       receiver_callback(&cc2430_rf_driver);
00148     } else {
00149       PRINTF("cc2430_rf_process: no receiver callback\n");
00150       cc2430_rf_command(ISFLUSHRX);
00151     }
00152   }
00153 
00154   PROCESS_END();
00155 }

Generated on Mon Apr 11 14:23:38 2011 for Contiki 2.5 by  doxygen 1.6.1