17 #include "sys/clock.h"
22 extern void (* receiver_callback)(
const struct radio_driver *);
23 #ifndef RF_DEFAULT_POWER
24 #define RF_DEFAULT_POWER 100
27 #ifndef RF_DEFAULT_CHANNEL
28 #define RF_DEFAULT_CHANNEL 18
31 #ifndef CC2430_CONF_CHECKSUM
32 #define CC2430_CONF_CHECKSUM 0
35 #if CC2430_CONF_CHECKSUM
37 #define CHECKSUM_LEN 2
39 #define CHECKSUM_LEN 2
45 #define RF_RX_LED_ON() leds_on(LEDS_RED);
46 #define RF_RX_LED_OFF() leds_off(LEDS_RED);
47 #define RF_TX_LED_ON() leds_on(LEDS_GREEN);
48 #define RF_TX_LED_OFF() leds_off(LEDS_GREEN);
50 #define RF_RX_LED_ON()
51 #define RF_RX_LED_OFF()
52 #define RF_TX_LED_ON()
53 #define RF_TX_LED_OFF()
57 #define PRINTF(...) printf(__VA_ARGS__)
59 #define PRINTF(...) do {} while (0)
62 #define RX_ACTIVE 0x80
64 #define TX_ON_AIR 0x20
71 uint8_t rf_initialized = 0;
74 uint8_t rf_channel = 0;
75 rf_address_mode_t rf_addr_mode;
88 cc2430_rf_set_receiver,
95 cc2430_rf_init(
void) __banked
101 PRINTF(
"cc2430_rf_init called\n");
103 RFPWR &= ~RREG_RADIO_PD;
104 while((RFPWR & ADI_RADIO_PD) == 1);
105 while((RFIF & IRQ_RREG_ON) == 0);
107 while((
SLEEP & XOSC_STB) == 0);
135 RFIF &= ~(IRQ_FIFOP);
137 S1CON &= ~(RFIF_0 | RFIF_1);
147 cc2430_rf_send_b(
void *payload,
unsigned short payload_len) __banked
151 if(rf_flags & TX_ACK) {
154 if((rf_flags & RX_ACTIVE) == 0) {
161 PRINTF(
"cc2430_rf: sending %ud byte payload\n", payload_len);
166 PRINTF(
"cc2430_rf: sent = ");
168 RFD = payload_len+CHECKSUM_LEN;
169 PRINTF(
"(%d)", payload_len+CHECKSUM_LEN);
170 for(i = 0 ; i < payload_len; i++) {
171 RFD = ((
unsigned char*)(payload))[i];
172 PRINTF(
"%02X", ((
unsigned char*)(payload))[i]);
189 while(!(RFSTATUS & TX_ACTIVE) && (counter++ < 3)) {
193 if(!(RFSTATUS & TX_ACTIVE)) {
194 PRINTF(
"cc2430_rf: TX never active.\n");
206 cc2430_rf_read_banked(
void *buf,
unsigned short bufsize) __banked
209 #if CC2420_CONF_CHECKSUM
219 if(len > CC2430_MAX_PACKET_LEN) {
221 PRINTF(
"error: bad sync\n");
223 RIMESTATS_ADD(badsynch);
227 if(len <= CC2430_MIN_PACKET_LEN) {
228 PRINTF(
"error: too short\n");
230 RIMESTATS_ADD(tooshort);
234 if(len - CHECKSUM_LEN > bufsize) {
235 PRINTF(
"error: too long\n");
237 RIMESTATS_ADD(toolong);
242 PRINTF(
"cc2430_rf: read = ");
244 for(i = 0; i < (len - CHECKSUM_LEN); i++) {
245 ((
unsigned char*)(buf))[i] = RFD;
246 PRINTF(
"%02X", ((
unsigned char*)(buf))[i]);
250 #if CC2430_CONF_CHECKSUM
252 checksum = RFD * 256;
255 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, ((int8_t) RFD) - 45);
256 packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, RFD);
266 return (len - CHECKSUM_LEN);
276 if(command >= 0xE0) {
282 fifo_count = RXFIFOCNT;
285 if(fifo_count != RXFIFOCNT) {
294 }
else if(command == SSTART) {
295 RFIF &= ~IRQ_CSP_STOP;
298 while((RFIF & IRQ_CSP_STOP) == 0);
322 if((channel < 11) || (channel > 26)) {
329 freq = (uint16_t) channel - 11;
333 FSCTRLH = (freq >> 8);
334 FSCTRLL = (uint8_t)freq;
338 rf_channel = channel;
340 return (int8_t) channel;
366 if(new_power > 100) {
370 power = 31 * new_power;
375 TXCTRLH = (power >> 8);
376 TXCTRLL = (uint8_t)power;
378 rf_tx_power = (int8_t) new_power;
392 PRINTF(
"cc2430_rf_rx_enable called\n");
393 if(!(rf_flags & RX_ACTIVE)) {
396 rf_flags |= RX_ACTIVE;
398 RFPWR &= ~RREG_RADIO_PD;
399 while((RFIF & IRQ_RREG_ON) == 0);
401 while((
SLEEP & XOSC_STB) == 0);
406 PRINTF(
"cc2430_rf_rx_enable done\n");
422 RFPWR |= RREG_RADIO_PD;
438 DMAARM = 0x80 + (1 << 0);
454 __xdata
unsigned char *ptr;
460 SHORTADDRH = addr >> 8;
461 SHORTADDRL = addr & 0xff;
463 if(ieee_addr !=
NULL) {
466 for (f = 0; f < 8; f++) {
467 *ptr++ = ieee_addr[f];
487 case RF_SOFTACK_MONITOR:
494 case RF_DECODER_COORDINATOR:
526 int8_t retval = -128;
529 retval = (int8_t)RSSIL;
543 uint8_t counter, cca = 1;
560 if(!(RFSTATUS & CCA)) {
572 if(!(RFSTATUS & CCA)) {