Contiki 3.x
cc2430_rf_intr.c
Go to the documentation of this file.
1 /**
2  * \file
3  * CC2430 RF driver
4  * \author
5  * Zach Shelby <zach@sensinode.com> (Original)
6  * George Oikonomou - <oikonomou@users.sourceforge.net>
7  * (recent updates for the contiki cc2430 port)
8  *
9  * Non-bankable code for cc2430 rf driver.
10  * Interrupt routines must be placed into the HOME bank.
11  *
12  */
13 
14 #include <stdio.h>
15 
16 #include "contiki.h"
17 #include "dev/radio.h"
18 #include "dev/cc2430_rf.h"
19 #include "cc2430_sfr.h"
20 #ifdef RF_LED_ENABLE
21 #include "dev/leds.h"
22 #endif
23 #include "sys/clock.h"
24 
25 #include "net/packetbuf.h"
26 #include "net/rime/rimestats.h"
27 #include "net/netstack.h"
28 #define DEBUG 0
29 #if DEBUG
30 #define PRINTF(...) printf(__VA_ARGS__)
31 #else
32 #define PRINTF(...) do {} while (0)
33 #endif
34 
35 #ifdef RF_LED_ENABLE
36 #define RF_RX_LED_ON() leds_on(LEDS_RED);
37 #define RF_RX_LED_OFF() leds_off(LEDS_RED);
38 #define RF_TX_LED_ON() leds_on(LEDS_GREEN);
39 #define RF_TX_LED_OFF() leds_off(LEDS_GREEN);
40 #else
41 #define RF_RX_LED_ON()
42 #define RF_RX_LED_OFF()
43 #define RF_TX_LED_ON()
44 #define RF_TX_LED_OFF()
45 #endif
46 
47 #ifdef HAVE_RF_ERROR
48 uint8_t rf_error = 0;
49 #endif
50 
51 PROCESS_NAME(cc2430_rf_process);
52 
53 #if !NETSTACK_CONF_SHORTCUTS
54 /*---------------------------------------------------------------------------*/
55 /**
56  * RF interrupt service routine.
57  *
58  */
59 #pragma save
60 #if CC_CONF_OPTIMIZE_STACK_SIZE
61 #pragma exclude bits
62 #endif
63 void
64 cc2430_rf_ISR(void) __interrupt(RF_VECTOR)
65 {
66  EA = 0;
67  ENERGEST_ON(ENERGEST_TYPE_IRQ);
68  /*
69  * We only vector here if RFSTATUS.FIFOP goes high.
70  * Just double check the flag.
71  */
72  if(RFIF & IRQ_FIFOP) {
73  RF_RX_LED_ON();
74  /* Poll the RF process which calls cc2430_rf_read() */
75  process_poll(&cc2430_rf_process);
76  }
77  S1CON &= ~(RFIF_0 | RFIF_1);
78 
79  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
80  EA = 1;
81 }
82 #pragma restore
83 #endif
84 /*---------------------------------------------------------------------------*/
85 #if CC2430_RFERR_INTERRUPT
86 /**
87  * RF error interrupt service routine.
88  * Turned off by default, can be turned on in contiki-conf.h
89  */
90 #pragma save
91 #if CC_CONF_OPTIMIZE_STACK_SIZE
92 #pragma exclude bits
93 #endif
94 void
95 cc2430_rf_error_ISR(void) __interrupt(RFERR_VECTOR)
96 {
97  EA = 0;
98  TCON_RFERRIF = 0;
99 #ifdef HAVE_RF_ERROR
100  rf_error = 254;
101 #endif
102  cc2430_rf_command(ISRFOFF);
103  cc2430_rf_command(ISFLUSHRX);
104  cc2430_rf_command(ISFLUSHRX);
105  cc2430_rf_command(ISRXON);
106  RF_RX_LED_OFF();
107  RF_TX_LED_OFF();
108  EA = 1;
109 }
110 #pragma restore
111 #endif
112 /*---------------------------------------------------------------------------*/
CC2430 registers header file for CC2430.
void process_poll(struct process *p)
Request a process to be polled.
Definition: process.c:371
Header file for the radio API
#define PROCESS_NAME(name)
Declare the name of a process.
Definition: process.h:286
Header file for the Rime buffer (packetbuf) management
CC2430 RF driver header file
void cc2430_rf_ISR(void) __interrupt(RF_VECTOR)
RF interrupt service routine.
void cc2430_rf_command(uint8_t command)
Execute a single CSP command.
Definition: cc2430_rf.c:122
Header file for Rime statistics
Include file for the Contiki low-layer network stack (NETSTACK)