Contiki 3.x
cc2430_rf.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  * (port to the netstack API, hexdump output, RX FIFO overflow fixes
8  * code cleanup, ...)
9  *
10  * bankable code for cc2430 rf driver. this code can be placed in any 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 #include "sys/clock.h"
21 #include "sys/rtimer.h"
22 
23 #include "net/packetbuf.h"
24 #include "net/rime/rimestats.h"
25 #include "net/netstack.h"
26 
27 #define CC2430_RF_TX_POWER_RECOMMENDED 0x5F
28 #ifdef CC2430_RF_CONF_TX_POWER
29 #define CC2430_RF_TX_POWER CC2430_RF_CONF_TX_POWER
30 #else
31 #define CC2430_RF_TX_POWER CC2430_RF_TX_POWER_RECOMMENDED
32 #endif
33 
34 #ifdef CC2430_RF_CONF_CHANNEL
35 #define CC2430_RF_CHANNEL CC2430_RF_CONF_CHANNEL
36 #else
37 #define CC2430_RF_CHANNEL 18
38 #endif /* CC2430_RF_CONF_CHANNEL */
39 #define CC2430_CHANNEL_MIN 11
40 #define CC2430_CHANNEL_MAX 26
41 
42 #ifdef CC2430_RF_CONF_AUTOACK
43 #define CC2430_RF_AUTOACK CC2430_RF_CONF_AUTOACK
44 #else
45 #define CC2430_RF_AUTOACK 1
46 #endif
47 
48 #ifndef CC2430_CONF_CHECKSUM
49 #define CC2430_CONF_CHECKSUM 0
50 #endif /* CC2420_CONF_CHECKSUM */
51 
52 #if CC2430_CONF_CHECKSUM
53 #include "lib/crc16.h"
54 #define CHECKSUM_LEN 2
55 #else
56 #define CHECKSUM_LEN 2
57 #endif /* CC2430_CONF_CHECKSUM */
58 #if DEBUG_LEDS
59 /* moved leds code to BANK1 to make space for cc2430_rf_process in HOME */
60 /* can't call code in BANK1 from alternate banks unless it is marked with __banked */
61 #include "dev/leds.h"
62 #define RF_RX_LED_ON() leds_on(LEDS_RED);
63 #define RF_RX_LED_OFF() leds_off(LEDS_RED);
64 #define RF_TX_LED_ON() leds_on(LEDS_GREEN);
65 #define RF_TX_LED_OFF() leds_off(LEDS_GREEN);
66 #else
67 #define RF_RX_LED_ON()
68 #define RF_RX_LED_OFF()
69 #define RF_TX_LED_ON()
70 #define RF_TX_LED_OFF()
71 #endif
72 #define DEBUG 0
73 #if DEBUG
74 #define PRINTF(...) printf(__VA_ARGS__)
75 #else
76 #define PRINTF(...) do {} while (0)
77 #endif
78 
79 /* rf_flags bits */
80 #define RX_ACTIVE 0x80
81 #define TX_ACK 0x40
82 #define TX_ON_AIR 0x20
83 #define WAS_OFF 0x10
84 #define INITIALISED 0x01
85 
86 #define RX_NO_DMA
87 /* Bits of the last byte in the RX FIFO */
88 #define CRC_BIT_MASK 0x80
89 #define LQI_BIT_MASK 0x7F
90 
91 /* 192 ms, radio off -> on interval */
92 #define ONOFF_TIME ((RTIMER_ARCH_SECOND / 3125) + 4)
93 
94 #if CC2430_RF_CONF_HEXDUMP
95 #include "uart1.h"
96 static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /* Snif */
97 #endif
98 
99 #ifdef HAVE_RF_ERROR
100 uint8_t rf_error = 0;
101 #endif
102 
103 /*---------------------------------------------------------------------------*/
104 #if !NETSTACK_CONF_SHORTCUTS
105 PROCESS(cc2430_rf_process, "CC2430 RF driver");
106 #endif
107 /*---------------------------------------------------------------------------*/
108 static uint8_t CC_AT_DATA rf_flags;
109 static uint8_t rf_channel;
110 
111 static int on(void); /* prepare() needs our prototype */
112 static int off(void); /* transmit() needs our prototype */
113 static int channel_clear(void); /* transmit() needs our prototype */
114 /*---------------------------------------------------------------------------*/
115 /**
116  * Execute a single CSP command.
117  *
118  * \param command command to execute
119  *
120  */
121 void
122 cc2430_rf_command(uint8_t command)
123 {
124  if(command >= 0xE0) { /*immediate strobe*/
125  uint8_t fifo_count;
126  switch (command) { /*hardware bug workaround*/
127  case ISRFOFF:
128  case ISRXON:
129  case ISTXON:
130  fifo_count = RXFIFOCNT;
131  RFST = command;
132  clock_delay_usec(2);
133  if(fifo_count != RXFIFOCNT) {
134  RFST = ISFLUSHRX;
135  RFST = ISFLUSHRX;
136  }
137  break;
138 
139  default:
140  RFST = command;
141  }
142  } else if(command == SSTART) {
143  RFIF &= ~IRQ_CSP_STOP; /*clear IRQ flag*/
144  RFST = SSTOP; /*make sure there is a stop in the end*/
145  RFST = ISSTART; /*start execution*/
146  while((RFIF & IRQ_CSP_STOP) == 0);
147  } else {
148  RFST = command; /*write command*/
149  }
150 }
151 /*---------------------------------------------------------------------------*/
152 static void
153 flush_rx()
154 {
155  cc2430_rf_command(ISFLUSHRX);
156  cc2430_rf_command(ISFLUSHRX);
157 
158 #if !NETSTACK_CONF_SHORTCUTS
159  IEN2 |= RFIE;
160 #endif
161 #if CC2430_RFERR_INTERRUPT
162  IEN0 |= RFERRIE;
163 #endif
164 
165  RFIF &= ~IRQ_FIFOP;
166 }
167 /*---------------------------------------------------------------------------*/
168 /**
169  * Select RF channel.
170  *
171  * \param channel channel number to select
172  *
173  * \return channel value or negative (invalid channel number)
174  */
175 
176  /* channel freqdiv = (2048 + FSCTRL(9:0)) / 4
177  freq = (2048 + FSCTRL(9:0)) MHz */
178 
179 int8_t
180 cc2430_rf_channel_set(uint8_t channel)
181 {
182  uint16_t freq;
183 
184  if((channel < 11) || (channel > 26)) {
185  return -1;
186  }
187 
188  cc2430_rf_command(ISSTOP); /*make sure CSP is not running*/
189  cc2430_rf_command(ISRFOFF);
190  /* Channel values: 11-26 */
191  freq = (uint16_t) channel - 11;
192  freq *= 5; /*channel spacing*/
193  freq += 357; /*correct channel range*/
194  freq |= 0x4000; /*LOCK_THR = 1*/
195  FSCTRLH = (freq >> 8);
196  FSCTRLL = (uint8_t)freq;
197 
198  cc2430_rf_command(ISRXON);
199 
200  rf_channel = channel;
201 
202  return (int8_t) channel;
203 }
204 /*---------------------------------------------------------------------------*/
205 uint8_t
206 cc2430_rf_channel_get()
207 {
208  return rf_channel;
209 }
210 /*---------------------------------------------------------------------------*/
211 /**
212  * Select RF transmit power.
213  *
214  * \param new_power new power level
215  *
216  * \return new level
217  */
218 uint8_t
219 cc2430_rf_power_set(uint8_t new_power)
220 {
221  /* Set transmitter power */
222  TXCTRLL = new_power;
223 
224  return TXCTRLL;
225 }
226 /*---------------------------------------------------------------------------*/
227 #if 0 /* unused */
228 /**
229  * Enable RF transmitter.
230  *
231  *
232  * \return pdTRUE
233  * \return pdFALSE bus not free
234  */
235 int
236 cc2430_rf_tx_enable(void)
237 {
238  DMAARM = 0x80 + (1 << 0); /*ABORT + channel bit*/
239 
240  return 1;
241 }
242 #endif
243 /*---------------------------------------------------------------------------*/
244 /**
245  * Set MAC addresses
246  *
247  * \param pan The PAN address to set
248  * \param addr The short address to set
249  * \param ieee_addr The 64-bit IEEE address to set
250  */
251 void
252 cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr)
253 {
254  uint8_t f;
255  __xdata unsigned char *ptr;
256 
257  PANIDH = pan >> 8;
258  PANIDL = pan & 0xff;
259 
260  SHORTADDRH = addr >> 8;
261  SHORTADDRL = addr & 0xff;
262 
263  if(ieee_addr != NULL) {
264  ptr = &IEEE_ADDR7;
265  /* LSB first, MSB last for 802.15.4 addresses in CC2420 */
266  for(f = 0; f < 8; f++) {
267  *ptr-- = ieee_addr[f];
268  }
269  }
270 }
271 #if 0 /* currently unused */
272 /*---------------------------------------------------------------------------*/
273 /**
274  * Channel energy detect.
275  *
276  * Coordinator use this function detect best channel for PAN-network.
277  * \return RSSI-energy level dBm.
278  * \return 0 operation failed.
279  */
280 
281 int8_t
282 cc2430_rf_analyze_rssi(void)
283 {
284  int8_t retval = -128;
285  /*pause_us(128);*/
286 
287  retval = (int8_t)RSSIL;
288  retval -= 45;
289  return retval;
290 }
291 #endif /* currently unused */
292 /*---------------------------------------------------------------------------*/
293 /**
294  * Send ACK.
295  *
296  *\param pending set up pending flag if pending > 0.
297  */
298 void
299 cc2430_rf_send_ack(uint8_t pending)
300 {
301  if(pending) {
302  cc2430_rf_command(ISACKPEND);
303  } else {
304  cc2430_rf_command(ISACK);
305  }
306 }
307 /*---------------------------------------------------------------------------*/
308 /* Netstack API radio driver functions */
309 /*---------------------------------------------------------------------------*/
310 static int
311 init(void)
312 {
313  if(rf_flags & INITIALISED) {
314  return 0;
315  }
316 
317  PRINTF("cc2430_rf_init called\n");
318 
319  RFPWR &= ~RREG_RADIO_PD; /*make sure it's powered*/
320  while((RFPWR & ADI_RADIO_PD) == 1);
321  while((RFIF & IRQ_RREG_ON) == 0); /*wait for power up*/
322  SLEEP &= ~OSC_PD; /*Osc on*/
323  while((SLEEP & XOSC_STB) == 0); /*wait for power up*/
324 
325  rf_flags = 0;
326 
327  FSMTC1 = 1; /*don't abort reception, if enable called, accept ack, auto rx after tx*/
328 
329  MDMCTRL0H = 0x0A; /* Generic client, standard hysteresis, decoder on 0x0a */
330  MDMCTRL0L = 0xE2; /* automatic CRC, standard CCA and preamble 0xE2 */
331 #if CC2430_RF_AUTOACK
332  MDMCTRL0L |= 0x10;
333 #endif
334 
335  MDMCTRL1H = 0x30; /* Defaults */
336  MDMCTRL1L = 0x0;
337 
338  RXCTRL0H = 0x32; /* RX tuning optimized */
339  RXCTRL0L = 0xf5;
340 
341  cc2430_rf_channel_set(CC2430_RF_CHANNEL);
342  cc2430_rf_command(ISFLUSHTX);
343  cc2430_rf_command(ISFLUSHRX);
344 
345  /* Temporary values, main() will sort this out later on */
346  cc2430_rf_set_addr(0xffff, 0x0000, NULL);
347 
348  RFIM = IRQ_FIFOP;
349  RFIF &= ~(IRQ_FIFOP);
350 
351  S1CON &= ~(RFIF_0 | RFIF_1);
352 #if !NETSTACK_CONF_SHORTCUTS
353  IEN2 |= RFIE;
354 #endif
355 
356  /* If contiki-conf.h turns on the RFERR interrupt, enable it here */
357 #if CC2430_RFERR_INTERRUPT
358  IEN0 |= RFERRIE;
359 #endif
360 
361  RF_TX_LED_OFF();
362  RF_RX_LED_OFF();
363 
364  rf_flags |= INITIALISED;
365 
366 #if !NETSTACK_CONF_SHORTCUTS
367  process_start(&cc2430_rf_process, NULL);
368 #endif
369 
370  cc2430_rf_power_set(CC2430_RF_TX_POWER);
371 
372  return 1;
373 }
374 /*---------------------------------------------------------------------------*/
375 static int
376 prepare(const void *payload, unsigned short payload_len)
377 {
378  uint8_t i;
379  /*
380  * When we transmit in very quick bursts, make sure previous transmission
381  * is not still in progress before re-writing in the TX FIFO
382  */
383  while(RFSTATUS & TX_ACTIVE);
384 
385  if(rf_flags & TX_ACK) {
386  return -1;
387  }
388 
389  if((rf_flags & RX_ACTIVE) == 0) {
390  on();
391  }
392 
393  PRINTF("cc2430_rf: sending %u byte payload\n", payload_len);
394 
395  cc2430_rf_command(ISFLUSHTX);
396  PRINTF("cc2430_rf: data = ");
397  /* Send the phy length byte first */
398  RFD = payload_len + CHECKSUM_LEN; /* Payload plus FCS */
399  PRINTF("(%d)", payload_len + CHECKSUM_LEN);
400  for(i = 0; i < payload_len; i++) {
401  RFD = ((unsigned char *)(payload))[i];
402  PRINTF("%02X", ((unsigned char *)(payload))[i]);
403  }
404  PRINTF("\n");
405 
406  /* Leave space for the FCS */
407  RFD = 0;
408  RFD = 0;
409 
410  return 0;
411 }
412 /*---------------------------------------------------------------------------*/
413 static int
414 transmit(unsigned short transmit_len)
415 {
416  uint8_t counter;
417  int ret = RADIO_TX_ERR;
418 
419  if(!(rf_flags & RX_ACTIVE)) {
420  on();
421  rf_flags |= WAS_OFF;
422  }
423 
424  if(channel_clear() == CC2430_CCA_BUSY) {
425  RIMESTATS_ADD(contentiondrop);
426  return RADIO_TX_COLLISION;
427  }
428 
429  /*
430  * prepare() double checked that TX_ACTIVE is low. If SFD is high we are
431  * receiving. Abort transmission and bail out with RADIO_TX_COLLISION
432  */
433  if(RFSTATUS & SFD) {
434  RIMESTATS_ADD(contentiondrop);
435  return RADIO_TX_COLLISION;
436  }
437 
438  /* Start the transmission */
439  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
440  ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
441 
442  cc2430_rf_command(ISTXON);
443  counter = 0;
444  while(!(RFSTATUS & TX_ACTIVE) && (counter++ < 3)) {
445  clock_delay_usec(6);
446  }
447 
448  if(!(RFSTATUS & TX_ACTIVE)) {
449  PRINTF("cc2430_rf: TX never active.\n");
450  cc2430_rf_command(ISFLUSHTX);
451  ret = RADIO_TX_ERR;
452  } else {
453  /* Wait for the transmission to finish */
454  while(RFSTATUS & TX_ACTIVE);
455  RF_RX_LED_OFF();
456  RF_TX_LED_ON();
457  ret = RADIO_TX_OK;
458  // rf_flags |= TX_ON_AIR;
459  }
460  ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
461  ENERGEST_ON(ENERGEST_TYPE_LISTEN);
462 
463  if(rf_flags & WAS_OFF) {
464  off();
465  }
466 
467  RIMESTATS_ADD(lltx);
468  /* OK, sent. We are now ready to send more */
469  return ret;
470 }
471 /*---------------------------------------------------------------------------*/
472 static int
473 send(void *payload, unsigned short payload_len)
474 {
475  prepare(payload, payload_len);
476  return transmit(payload_len);
477 }
478 /*---------------------------------------------------------------------------*/
479 static int
480 read(void *buf, unsigned short bufsize)
481 {
482  uint8_t i;
483  uint8_t len;
484  uint8_t crc_corr;
485  int8_t rssi;
486 #if CC2420_CONF_CHECKSUM
487  uint16_t checksum;
488 #endif /* CC2420_CONF_CHECKSUM */
489 
490  /* Don't interrupt us while emptying the FIFO */
491 #if !NETSTACK_CONF_SHORTCUTS
492  IEN2 &= ~RFIE;
493 #endif
494 #if CC2430_RFERR_INTERRUPT
495  IEN0 &= ~RFERRIE;
496 #endif
497 
498  /* RX interrupt polled the cc2430_rf_process, now read the RX FIFO */
499  /* Check the length */
500  len = RFD;
501 
502  /* Check for validity */
503  if(len > CC2430_MAX_PACKET_LEN) {
504  /* Oops, we must be out of sync. */
505  PRINTF("error: bad sync\n");
506 
507  RIMESTATS_ADD(badsynch);
508  flush_rx();
509  return 0;
510  }
511 
512  if(len <= CC2430_MIN_PACKET_LEN) {
513  PRINTF("error: too short\n");
514 
515  RIMESTATS_ADD(tooshort);
516  flush_rx();
517  return 0;
518  }
519 
520  if(len - CHECKSUM_LEN > bufsize) {
521  PRINTF("error: too long\n");
522 
523  RIMESTATS_ADD(toolong);
524  flush_rx();
525  return 0;
526  }
527 
528 #if CC2430_RF_CONF_HEXDUMP
529  /* If we reach here, chances are the FIFO is holding a valid frame */
530  uart1_writeb(magic[0]);
531  uart1_writeb(magic[1]);
532  uart1_writeb(magic[2]);
533  uart1_writeb(magic[3]);
534  uart1_writeb(len);
535 #endif
536 
537  PRINTF("cc2430_rf: read = ");
538  PRINTF("(%d)", len);
539  len -= CHECKSUM_LEN;
540  for(i = 0; i < len; ++i) {
541  ((unsigned char *)(buf))[i] = RFD;
542 #if CC2430_RF_CONF_HEXDUMP
543  uart1_writeb(((unsigned char *)(buf))[i]);
544 #endif
545  PRINTF("%02X", ((unsigned char *)(buf))[i]);
546  }
547  PRINTF("\n");
548 
549 #if CC2430_CONF_CHECKSUM
550  /* Deal with the checksum */
551  checksum = RFD * 256;
552  checksum += RFD;
553 #endif /* CC2430_CONF_CHECKSUM */
554 
555  /* Read the RSSI and CRC/Corr bytes */
556  rssi = ((int8_t) RFD) - 45;
557  crc_corr = RFD;
558 
559 #if CC2430_RF_CONF_HEXDUMP
560  uart1_writeb(rssi);
561  uart1_writeb(crc_corr);
562 #endif
563 
564  /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */
565  if(crc_corr & CRC_BIT_MASK) {
566  packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi);
567  packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK);
568  RIMESTATS_ADD(llrx);
569  } else {
570  RIMESTATS_ADD(badcrc);
571  flush_rx();
572  return 0;
573  }
574 
575  /* If FIFOP==1 and FIFO==0 then we had a FIFO overflow at some point. */
576  if((RFSTATUS & (FIFO | FIFOP)) == FIFOP) {
577  /*
578  * If we reach here means that there might be more intact packets in the
579  * FIFO despite the overflow. This can happen with bursts of small packets.
580  *
581  * Only flush if the FIFO is actually empty. If not, then next pass we will
582  * pick up one more packet or flush due to an error.
583  */
584  if(!RXFIFOCNT) {
585  flush_rx();
586  }
587  }
588 
589  RF_RX_LED_OFF();
590 
591 #if !NETSTACK_CONF_SHORTCUTS
592  IEN2 |= RFIE;
593 #endif
594 #if CC2430_RFERR_INTERRUPT
595  IEN0 |= RFERRIE;
596 #endif
597 
598  RFIF &= ~IRQ_FIFOP;
599 
600  return (len);
601 }
602 /*---------------------------------------------------------------------------*/
603 static int
604 channel_clear(void)
605 {
606  if(!(RFSTATUS & CCA)) {
607  return CC2430_CCA_BUSY;
608  }
609  return CC2430_CCA_CLEAR;
610 }
611 /*---------------------------------------------------------------------------*/
612 static int
613 receiving_packet(void)
614 {
615  /*
616  * SFD high while transmitting and receiving.
617  * TX_ACTIVE high only when transmitting
618  *
619  * RFSTATUS & (TX_ACTIVE | SFD) == SFD <=> receiving
620  */
621  return (RFSTATUS & (TX_ACTIVE | SFD) == SFD);
622 }
623 /*---------------------------------------------------------------------------*/
624 static int
625 pending_packet(void)
626 {
627  return (RFSTATUS & FIFOP);
628 }
629 /*---------------------------------------------------------------------------*/
630 /**
631  * Enable RF receiver.
632  *
633  *
634  * \return pdTRUE
635  * \return pdFALSE bus not free
636  */
637 static int
638 on(void)
639 {
640  rtimer_clock_t t0;
641  PRINTF("cc2430_rf_rx_enable called\n");
642  if(!(rf_flags & RX_ACTIVE)) {
643  t0 = RTIMER_NOW();
644  rf_flags |= RX_ACTIVE;
645  IOCFG0 = 0x7f; /* Set the FIFOP threshold 127 */
646  RSSIH = 0xd2; /* -84dbm = 0xd2 default, 0xe0 -70 dbm */
647 
648  RFPWR &= ~RREG_RADIO_PD; /* make sure it's powered */
649  while((RFIF & IRQ_RREG_ON) == 0); /* wait for power up */
650 
651  /* Make sure the RREG On Interrupt Flag is 0 next time we get called */
652  RFIF &= ~IRQ_RREG_ON;
653 
654  cc2430_rf_command(ISRXON);
655  cc2430_rf_command(ISFLUSHRX);
656  while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ONOFF_TIME));
657 
658  }
659  PRINTF("cc2430_rf_rx_enable done\n");
660  ENERGEST_ON(ENERGEST_TYPE_LISTEN);
661  return 1;
662 }
663 /*---------------------------------------------------------------------------*/
664 /**
665  * Disable RF receiver.
666  *
667  *
668  * \return pdTRUE
669  * \return pdFALSE bus not free
670  */
671 
672 static int
673 off(void)
674 {
675  cc2430_rf_command(ISSTOP); /* make sure CSP is not running */
676  cc2430_rf_command(ISRFOFF);
677 
678  RFPWR |= RREG_RADIO_PD; /* RF powerdown */
679 
680  /* Clear the RREG On Interrupt Flag */
681  RFIF &= ~IRQ_RREG_ON;
682 
683  rf_flags &= ~RX_ACTIVE;
684  rf_flags &= ~WAS_OFF;
685  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
686  return 1;
687 }
688 /*---------------------------------------------------------------------------*/
689 static radio_result_t
690 get_value(radio_param_t param, radio_value_t *value)
691 {
692  return RADIO_RESULT_NOT_SUPPORTED;
693 }
694 /*---------------------------------------------------------------------------*/
695 static radio_result_t
696 set_value(radio_param_t param, radio_value_t value)
697 {
698  return RADIO_RESULT_NOT_SUPPORTED;
699 }
700 /*---------------------------------------------------------------------------*/
701 static radio_result_t
702 get_object(radio_param_t param, void *dest, size_t size)
703 {
704  return RADIO_RESULT_NOT_SUPPORTED;
705 }
706 /*---------------------------------------------------------------------------*/
707 static radio_result_t
708 set_object(radio_param_t param, const void *src, size_t size)
709 {
710  return RADIO_RESULT_NOT_SUPPORTED;
711 }
712 /*---------------------------------------------------------------------------*/
713 const struct radio_driver cc2430_rf_driver = {
714  init,
715  prepare,
716  transmit,
717  send,
718  read,
722  on,
723  off,
724  get_value,
725  set_value,
726  get_object,
727  set_object
728 };
729 /*---------------------------------------------------------------------------*/
730 #if !NETSTACK_CONF_SHORTCUTS
731 /*---------------------------------------------------------------------------*/
732 PROCESS_THREAD(cc2430_rf_process, ev, data)
733 {
734  int len;
735  PROCESS_BEGIN();
736  while(1) {
737  PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
738 
739  packetbuf_clear();
741  if(len > 0) {
743  NETSTACK_RDC.input();
744  }
745  }
746 
747  PROCESS_END();
748 }
749 #endif
750 /*---------------------------------------------------------------------------*/
CC2430 registers header file for CC2430.
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
Definition: clock.c:94
Header file for the radio API
int8_t cc2430_rf_channel_set(uint8_t channel)
Select RF channel.
Definition: cc2430_rf.c:180
Header file for the Rime buffer (packetbuf) management
CC2430 RF driver header file
#define NULL
The null pointer.
The structure of a device driver for a radio in Contiki.
Definition: radio.h:225
int(* pending_packet)(void)
Check if the radio driver has just received a packet.
Definition: radio.h:249
uint8_t cc2430_rf_power_set(uint8_t new_power)
Select RF transmit power.
Definition: cc2430_rf.c:219
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
Definition: radio.h:88
int(* prepare)(const void *payload, unsigned short payload_len)
Prepare the radio with a packet to be sent.
Definition: radio.h:230
void cc2430_rf_command(uint8_t command)
Execute a single CSP command.
Definition: cc2430_rf.c:122
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
Definition: packetbuf.c:200
int(* send)(const void *payload, unsigned short payload_len)
Prepare &amp; transmit a packet.
Definition: radio.h:236
int(* receiving_packet)(void)
Check if the radio driver is currently receiving a packet.
Definition: radio.h:246
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
int(* channel_clear)(void)
Perform a Clear-Channel Assessment (CCA) to find out if there is a packet in the air or not...
Definition: radio.h:243
Header file for the real-time timer module.
void cc2430_rf_send_ack(uint8_t pending)
Send ACK.
Definition: cc2430_rf.c:299
int(* on)(void)
Turn the radio on.
Definition: radio.h:252
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.
Definition: radio.h:258
void cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr)
Set MAC addresses.
Definition: cc2430_rf.c:252
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
Definition: radio.h:268
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define SLEEP
Constant SLEEP for sub-register SR_TRX_STATUS.
int(* transmit)(unsigned short transmit_len)
Send the packet that has previously been prepared.
Definition: radio.h:233
void packetbuf_clear(void)
Clear and reset the packetbuf.
Definition: packetbuf.c:77
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
#define RTIMER_NOW()
Get the current clock time.
Definition: rtimer.h:133
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
Definition: packetbuf.h:65
Header file for Rime statistics
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
Definition: packetbuf.c:207
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
Definition: radio.h:274
Header file for the CRC16 calculcation
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
Definition: process.h:178
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
Definition: radio.h:261
int(* read)(void *buf, unsigned short buf_len)
Read a received packet into a buffer.
Definition: radio.h:239
int(* off)(void)
Turn the radio off.
Definition: radio.h:255
Include file for the Contiki low-layer network stack (NETSTACK)