Contiki-NG
micromac-radio.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, NXP and SICS Swedish ICT.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Contiki driver for NXP JN516X using MMAC interface
36  * \authors
37  * Beshr Al Nahas <beshr@sics.se>
38  * Simon Duquennot <simonduq@sics.se>
39  * Atis Elsts <atis.elsts@sics.se>
40  *
41  */
42 
43 #include <string.h>
44 #include "contiki.h"
45 #include "dev/leds.h"
46 #include "sys/rtimer.h"
47 #include "sys/energest.h"
48 #include "net/packetbuf.h"
49 #include "net/netstack.h"
51 #include "lib/crc16.h"
52 #include "lib/ringbufindex.h"
53 
54 #include "AppHardwareApi.h"
55 #include "MMAC.h"
56 #include "micromac-radio.h"
57 #include "JPT.h"
58 #include "PeripheralRegs.h"
59 
60 /* This driver configures the radio in PHY mode and does address decoding
61  * and acknowledging in software. */
62 
63 #define DEBUG DEBUG_NONE
64 #include "net/ipv6/uip-debug.h"
65 
66 #ifdef MICROMAC_CONF_RADIO_MAC
67 #define MICROMAC_RADIO_MAC MICROMAC_CONF_RADIO_MAC
68 #else
69 #define MICROMAC_RADIO_MAC 0
70 #endif
71 
72 #if MICROMAC_RADIO_MAC
73 #define MICROMAC_FRAME tsMacFrame
74 #else
75 #define MICROMAC_FRAME tsPhyFrame
76 #endif
77 
78 /* Perform CRC check for received packets in SW,
79  * since we use PHY mode which does not calculate CRC in HW */
80 #define CRC_SW 1
81 
82 #define CHECKSUM_LEN 2
83 
84 /* Max packet duration: 5 + 127 + 2 bytes, 32us per byte */
85 #define MAX_PACKET_DURATION US_TO_RTIMERTICKS((127 + 2) * 32 + RADIO_DELAY_BEFORE_TX)
86 /* Max ACK duration: 5 + 3 + 2 bytes */
87 #define MAX_ACK_DURATION US_TO_RTIMERTICKS((3 + 2) * 32 + RADIO_DELAY_BEFORE_TX)
88 
89 /* Test-mode pins output on dev-kit */
90 #define RADIO_TEST_MODE_HIGH_PWR 1
91 #define RADIO_TEST_MODE_ADVANCED 2
92 #define RADIO_TEST_MODE_DISABLED 0
93 
94 #ifndef RADIO_TEST_MODE
95 #define RADIO_TEST_MODE RADIO_TEST_MODE_DISABLED
96 #endif /* RADIO_TEST_MODE */
97 
98 /* The number of input buffers */
99 #ifndef MIRCOMAC_CONF_BUF_NUM
100 #define MIRCOMAC_CONF_BUF_NUM 2
101 #endif /* MIRCOMAC_CONF_BUF_NUM */
102 
103 /* Default energy level threshold for clear channel detection */
104 #ifndef MICROMAC_CONF_CCA_THR
105 #define MICROMAC_CONF_CCA_THR 39 /* approximately -85 dBm */
106 #endif /* MICROMAC_CONF_CCA_THR */
107 
108 #if (JENNIC_CHIP == JN5169)
109 #define OUTPUT_POWER_MAX 10
110 #define OUTPUT_POWER_MIN (-32)
111 #define ABS_OUTPUT_POWER_MIN (32)
112 #else
113 #define OUTPUT_POWER_MAX 0
114 #define OUTPUT_POWER_MIN (-32)
115 #endif
116 
117 /* Default Tx power [dBm] (between OUTPUT_POWER_MIN and OUTPUT_POWER_MAX) */
118 #ifndef MICROMAC_CONF_TX_POWER
119 #define MICROMAC_CONF_TX_POWER 0
120 #endif
121 
122 /* Autoack */
123 #ifndef MICROMAC_CONF_AUTOACK
124 #define MICROMAC_CONF_AUTOACK 1
125 #endif /* MICROMAC_CONF_AUTOACK */
126 
127 /* Set radio always on for now because this is what Contiki MAC layers
128  * expect. */
129 #ifndef MICROMAC_CONF_ALWAYS_ON
130 #define MICROMAC_CONF_ALWAYS_ON 1
131 #endif /* MICROMAC_CONF_ALWAYS_ON */
132 
133 #define BUSYWAIT_UNTIL(cond, max_time) \
134  do { \
135  rtimer_clock_t t0; \
136  t0 = RTIMER_NOW(); \
137  while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) ; \
138  } while(0)
139 
140 /* Local variables */
141 static volatile signed char radio_last_rssi;
142 static volatile uint8_t radio_last_correlation; /* LQI */
143 
144 /* Did we miss a request to turn the radio on due to overflow? */
145 static volatile uint8_t missed_radio_on_request = 0;
146 
147 /* Poll mode disabled by default */
148 static uint8_t poll_mode = 0;
149 /* (Software) frame filtering enabled by default */
150 static uint8_t frame_filtering = 1;
151 /* (Software) autoack */
152 static uint8_t autoack_enabled = MICROMAC_CONF_AUTOACK;
153 /* CCA before sending? Disabled by default. */
154 static uint8_t send_on_cca = 0;
155 
156 /* Current radio channel */
157 static int current_channel = IEEE802154_DEFAULT_CHANNEL;
158 
159 /* Current set point tx power
160  Actual tx power may be different. Use get_txpower() for actual power */
161 static int current_tx_power = MICROMAC_CONF_TX_POWER;
162 
163 /* an integer between 0 and 255, used only with cca() */
164 static uint8_t cca_thershold = MICROMAC_CONF_CCA_THR;
165 
166 /* Tx in progress? */
167 static volatile uint8_t tx_in_progress = 0;
168 /* Are we currently listening? */
169 static volatile uint8_t listen_on = 0;
170 
171 /* Is the driver currently transmitting a software ACK? */
172 static uint8_t in_ack_transmission = 0;
173 
174 /* TX frame buffer */
175 static MICROMAC_FRAME tx_frame_buffer;
176 
177 /* RX frame buffer */
178 static MICROMAC_FRAME *rx_frame_buffer;
179 
180 /* Frame buffer pointer to read from */
181 static MICROMAC_FRAME *input_frame_buffer = NULL;
182 
183 /* Ringbuffer for received packets in interrupt enabled mode */
184 static struct ringbufindex input_ringbuf;
185 static MICROMAC_FRAME input_array[MIRCOMAC_CONF_BUF_NUM];
186 
187 /* SFD timestamp in RTIMER ticks */
188 static volatile uint32_t last_packet_timestamp = 0;
189 
190 /* Local functions prototypes */
191 static int on(void);
192 static int off(void);
193 #if !MICROMAC_RADIO_MAC
194 static int is_packet_for_us(uint8_t *buf, int len, int do_send_ack);
195 #endif
196 static void set_frame_filtering(uint8_t enable);
197 static rtimer_clock_t get_packet_timestamp(void);
198 static void set_txpower(int8_t power);
199 void set_channel(int c);
200 static void radio_interrupt_handler(uint32 mac_event);
201 static int get_detected_energy(void);
202 static int get_rssi(void);
203 static void read_last_rssi(void);
204 
205 /*---------------------------------------------------------------------------*/
206 PROCESS(micromac_radio_process, "micromac_radio_driver");
207 /*---------------------------------------------------------------------------*/
208 
209 /* Custom Radio parameters */
210 #ifndef RADIO_RX_MODE_POLL_MODE
211 #define RADIO_PARAM_LAST_RSSI 0x80
212 #define RADIO_PARAM_LAST_PACKET_TIMESTAMP 0x81
213 #define RADIO_RX_MODE_POLL_MODE (1 << 2)
214 #endif /* RADIO_RX_MODE_POLL_MODE */
215 
216 /*---------------------------------------------------------------------------*/
217 static rtimer_clock_t
218 get_packet_timestamp(void)
219 {
220  /* Wait for an edge */
221  uint32_t t = u32MMAC_GetTime();
222  while(u32MMAC_GetTime() == t);
223  /* Save SFD timestamp, converted from radio timer to RTIMER */
224  last_packet_timestamp = RTIMER_NOW() -
225  RADIO_TO_RTIMER((uint32_t)(u32MMAC_GetTime() - (u32MMAC_GetRxTime() - 1)));
226  /* The remaining measured error is typically in range 0..16 usec.
227  * Center it around zero, in the -8..+8 usec range. */
228  last_packet_timestamp -= US_TO_RTIMERTICKS(8);
229  return last_packet_timestamp;
230 }
231 /*---------------------------------------------------------------------------*/
232 static int
233 init_software(void)
234 {
235  int put_index;
236  /* Initialize ring buffer and first input packet pointer */
237  ringbufindex_init(&input_ringbuf, MIRCOMAC_CONF_BUF_NUM);
238  /* get pointer to next input slot */
239  put_index = ringbufindex_peek_put(&input_ringbuf);
240  if(put_index == -1) {
241  rx_frame_buffer = NULL;
242  printf("micromac_radio init:! no buffer available. Abort init.\n");
243  off();
244  return 0;
245  } else {
246  rx_frame_buffer = &input_array[put_index];
247  }
248  input_frame_buffer = rx_frame_buffer;
249 
250  process_start(&micromac_radio_process, NULL);
251 
252  return 1;
253 }
254 /*---------------------------------------------------------------------------*/
255 static int
256 init(void)
257 {
258  int ret = 1;
259  tsExtAddr node_long_address;
260  uint16_t node_short_address;
261  static uint8_t is_initialized;
262 
263  tx_in_progress = 0;
264 
265  u32JPT_Init();
266  vMMAC_Enable();
267 
268  /* Enable/disable interrupts */
269  if(poll_mode) {
270  vMMAC_EnableInterrupts(NULL);
271  vMMAC_ConfigureInterruptSources(0);
272  } else {
273  vMMAC_EnableInterrupts(&radio_interrupt_handler);
274  }
275  vMMAC_ConfigureRadio();
276  set_txpower(current_tx_power); /* it sets also the current_channel */
277 
278  vMMAC_GetMacAddress(&node_long_address);
279  /* Short addresses are disabled by default */
280  node_short_address = (uint16_t)node_long_address.u32L;
281  vMMAC_SetRxAddress(frame802154_get_pan_id(), node_short_address, &node_long_address);
282 
283  /* Disable hardware backoff */
284  vMMAC_SetTxParameters(1, 0, 0, 0);
285  vMMAC_SetCutOffTimer(0, FALSE);
286 
287 #if RADIO_TEST_MODE == RADIO_TEST_MODE_HIGH_PWR
288  /* Enable high power mode.
289  * In this mode DIO2 goes high during RX
290  * and DIO3 goes high during TX
291  **/
292  vREG_SysWrite(REG_SYS_PWR_CTRL,
293  u32REG_SysRead(REG_SYS_PWR_CTRL)
294  | REG_SYSCTRL_PWRCTRL_RFRXEN_MASK
295  | REG_SYSCTRL_PWRCTRL_RFTXEN_MASK);
296 #elif RADIO_TEST_MODE == RADIO_TEST_MODE_ADVANCED
297  /* output internal radio status on IO pins.
298  * See Chris@NXP email */
299  vREG_SysWrite(REG_SYS_PWR_CTRL,
300  u32REG_SysRead(REG_SYS_PWR_CTRL) | (1UL << 26UL));
301 #endif /* TEST_MODE */
302 
303  if(!is_initialized) {
304  is_initialized = 1;
305  ret = init_software();
306  }
307 
308  return ret;
309 }
310 /*---------------------------------------------------------------------------*/
311 static int
312 on(void)
313 {
314  /* No address matching or frame decoding */
315  if(rx_frame_buffer != NULL) {
316 #if MICROMAC_RADIO_MAC
317  vMMAC_StartMacReceive(rx_frame_buffer,
318  (uint16_t)(E_MMAC_RX_START_NOW
319  | E_MMAC_RX_USE_AUTO_ACK
320  | E_MMAC_RX_NO_MALFORMED
321  | E_MMAC_RX_NO_FCS_ERROR
322  | E_MMAC_RX_ADDRESS_MATCH
323  | E_MMAC_RX_ALIGN_NORMAL)
324  );
325 #else
326  vMMAC_StartPhyReceive(rx_frame_buffer,
327  (uint16_t)(E_MMAC_RX_START_NOW
328  | E_MMAC_RX_NO_FCS_ERROR) /* means: reject FCS errors */
329  );
330 #endif
331  } else {
332  missed_radio_on_request = 1;
333  }
334  ENERGEST_ON(ENERGEST_TYPE_LISTEN);
335  listen_on = 1;
336  return 1;
337 }
338 /*---------------------------------------------------------------------------*/
339 static int
340 off(void)
341 {
342  listen_on = 0;
343  tx_in_progress = 0;
344 
345  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
346 
347  /* The following would be needed with delayed Tx/Rx functions
348  * vMMAC_SetCutOffTimer(0, FALSE);*/
349  vMMAC_RadioOff();
350 
351  return 1;
352 }
353 /*---------------------------------------------------------------------------*/
354 static int
355 transmit(unsigned short payload_len)
356 {
357  if(tx_in_progress) {
358  return RADIO_TX_COLLISION;
359  }
360  tx_in_progress = 1;
361 
362  /* Energest */
363  if(listen_on) {
364  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
365  }
366  ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
367 
368  /* Transmit and wait */
369 #if MICROMAC_RADIO_MAC
370  vMMAC_StartMacTransmit(&tx_frame_buffer,
371  E_MMAC_TX_START_NOW |
372  E_MMAC_TX_USE_AUTO_ACK |
373  (send_on_cca ? E_MMAC_TX_USE_CCA : E_MMAC_TX_NO_CCA));
374 #else
375  vMMAC_StartPhyTransmit(&tx_frame_buffer,
376  E_MMAC_TX_START_NOW |
377  (send_on_cca ? E_MMAC_TX_USE_CCA : E_MMAC_TX_NO_CCA));
378 #endif
379  if(poll_mode) {
380  BUSYWAIT_UNTIL(u32MMAC_PollInterruptSource(E_MMAC_INT_TX_COMPLETE), MAX_PACKET_DURATION);
381  } else {
382  if(in_ack_transmission) {
383  /* as nested interupts are not possible, the tx flag will never be cleared */
384  BUSYWAIT_UNTIL(FALSE, MAX_ACK_DURATION);
385  } else {
386  /* wait until the tx flag is cleared */
387  BUSYWAIT_UNTIL(!tx_in_progress, MAX_PACKET_DURATION);
388  }
389  }
390 
391  /* Energest */
392  ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
393  if(listen_on) {
394  ENERGEST_ON(ENERGEST_TYPE_LISTEN);
395  }
396  tx_in_progress = 0;
397 
398  /* Check error code */
399  int ret;
400  uint32_t tx_error = u32MMAC_GetTxErrors();
401  if(tx_error == 0) {
402  ret = RADIO_TX_OK;
403  } else if(tx_error & E_MMAC_TXSTAT_ABORTED) {
404  ret = RADIO_TX_ERR;
405  } else if(tx_error & E_MMAC_TXSTAT_CCA_BUSY) {
406  ret = RADIO_TX_COLLISION;
407  } else if(tx_error & E_MMAC_TXSTAT_NO_ACK) {
408  ret = RADIO_TX_NOACK;
409  } else {
410  ret = RADIO_TX_ERR;
411  }
412  return ret;
413 }
414 /*---------------------------------------------------------------------------*/
415 static int
416 prepare(const void *payload, unsigned short payload_len)
417 {
418 #if !MICROMAC_RADIO_MAC
419  uint8_t i;
420  uint16_t checksum;
421 #endif
422 
423  if(tx_in_progress) {
424  return 1;
425  }
426  if(payload_len > 127 || payload == NULL) {
427  return 1;
428  }
429 #if MICROMAC_RADIO_MAC
430  frame802154_t info154;
431  int hdr_len = frame802154_parse((unsigned char *)payload, payload_len, &info154);
432  //TODO: hdr_len contains security header, which are not managed by micromac
433  tx_frame_buffer.u8PayloadLength = payload_len - hdr_len;
434  tx_frame_buffer.u8SequenceNum = info154.seq;
435  tx_frame_buffer.u16FCF = ((uint8_t*)payload)[0] | (((uint8_t*)payload)[1] << 8);
436  tx_frame_buffer.u16DestPAN = info154.dest_pid;
437  tx_frame_buffer.u16SrcPAN = info154.src_pid;
438  if(info154.fcf.dest_addr_mode == FRAME802154_SHORTADDRMODE) {
439  tx_frame_buffer.uDestAddr.u16Short = info154.dest_addr[0] | (info154.dest_addr[0] << 8);
440  } else if(info154.fcf.dest_addr_mode == FRAME802154_LONGADDRMODE) {
441  tx_frame_buffer.uDestAddr.sExt.u32L = *(uint32_t*)(&info154.dest_addr[4]);
442  tx_frame_buffer.uDestAddr.sExt.u32H = *(uint32_t*)(&info154.dest_addr[0]);
443  }
444  if(info154.fcf.src_addr_mode == FRAME802154_SHORTADDRMODE) {
445  tx_frame_buffer.uSrcAddr.u16Short = info154.src_addr[0] | (info154.src_addr[0] << 8);
446  } else if(info154.fcf.src_addr_mode == FRAME802154_LONGADDRMODE) {
447  tx_frame_buffer.uSrcAddr.sExt.u32L = *(uint32_t*)(&info154.src_addr[4]);
448  tx_frame_buffer.uSrcAddr.sExt.u32H = *(uint32_t*)(&info154.src_addr[0]);
449  }
450  tx_frame_buffer.u16FCS = crc16_data(payload, payload_len, 0);
451  memcpy(tx_frame_buffer.uPayload.au8Byte, info154.payload, info154.payload_len);
452 #else
453  /* Copy payload to (soft) Ttx buffer */
454  memcpy(tx_frame_buffer.uPayload.au8Byte, payload, payload_len);
455  i = payload_len;
456 #if CRC_SW
457  /* Compute CRC */
458  checksum = crc16_data(payload, payload_len, 0);
459  tx_frame_buffer.uPayload.au8Byte[i++] = checksum;
460  tx_frame_buffer.uPayload.au8Byte[i++] = (checksum >> 8) & 0xff;
461  tx_frame_buffer.u8PayloadLength = payload_len + CHECKSUM_LEN;
462 #else
463  tx_frame_buffer.u8PayloadLength = payload_len;
464 #endif
465 #endif
466 
467  return 0;
468 }
469 /*---------------------------------------------------------------------------*/
470 static int
471 send(const void *payload, unsigned short payload_len)
472 {
473  if(prepare(payload, payload_len) == 0) {
474  return transmit(payload_len);
475  } else {
476  return RADIO_TX_ERR;
477  }
478 }
479 /*---------------------------------------------------------------------------*/
480 int
481 get_channel(void)
482 {
483  return current_channel;
484 }
485 /*---------------------------------------------------------------------------*/
486 void
487 set_channel(int c)
488 {
489  current_channel = c;
490  vMMAC_SetChannelAndPower(current_channel, current_tx_power);
491 }
492 /*---------------------------------------------------------------------------*/
493 #if !MICROMAC_RADIO_MAC
494 static int
495 is_broadcast_addr(uint8_t mode, uint8_t *addr)
496 {
497  int i = ((mode == FRAME802154_SHORTADDRMODE) ? 2 : 8);
498  while(i-- > 0) {
499  if(addr[i] != 0xff) {
500  return 0;
501  }
502  }
503  return 1;
504 }
505 /*---------------------------------------------------------------------------*/
506 /* Send an ACK */
507 static void
508 send_ack(const frame802154_t *frame)
509 {
510  uint8_t buffer[3];
511  /* FCF: 2 octets */
512  buffer[0] = FRAME802154_ACKFRAME;
513  buffer[1] = 0;
514  /* Seqnum: 1 octets */
515  buffer[2] = frame->seq;
516  in_ack_transmission = 1;
517  send(&buffer, sizeof(buffer));
518  in_ack_transmission = 0;
519 }
520 /*---------------------------------------------------------------------------*/
521 /* Check if a packet is for us */
522 static int
523 is_packet_for_us(uint8_t *buf, int len, int do_send_ack)
524 {
525  frame802154_t frame;
526  int result;
527  uint8_t parsed = frame802154_parse(buf, len, &frame);
528  if(parsed) {
529  if(frame.fcf.dest_addr_mode) {
530  int has_dest_panid;
531  frame802154_has_panid(&frame.fcf, NULL, &has_dest_panid);
532  if(has_dest_panid
533  && frame802154_get_pan_id() != FRAME802154_BROADCASTPANDID
534  && frame.dest_pid != frame802154_get_pan_id()
535  && frame.dest_pid != FRAME802154_BROADCASTPANDID) {
536  /* Packet to another PAN */
537  return 0;
538  }
539  if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
540  result = linkaddr_cmp((linkaddr_t *)frame.dest_addr, &linkaddr_node_addr);
541  if(autoack_enabled && result && do_send_ack) {
542  /* this is a unicast frame and sending ACKs is enabled */
543  send_ack(&frame);
544  }
545  return result;
546  }
547  }
548  return 1;
549  } else {
550  return 0;
551  }
552 }
553 #endif
554 /*---------------------------------------------------------------------------*/
555 static int
556 read(void *buf, unsigned short bufsize)
557 {
558  int len = 0;
559 #if MICROMAC_RADIO_MAC
560  frame802154_fcf_t fcf;
561  uint8_t *p = (uint8_t*)buf;
562  int has_src_panid;
563  int has_dest_panid;
564  int c;
565 
566  p[len++] = input_frame_buffer->u16FCF & 0xff;
567  p[len++] = (input_frame_buffer->u16FCF >> 8) & 0xff;
568  frame802154_parse_fcf(p, &fcf);
569  p[len++] = input_frame_buffer->u8SequenceNum;
570  frame802154_has_panid(&fcf, &has_src_panid, &has_dest_panid);
571  if(has_dest_panid) {
572  p[len++] = input_frame_buffer->u16DestPAN & 0xff;
573  p[len++] = (input_frame_buffer->u16DestPAN >> 8) & 0xff;
574  }
575  if(fcf.dest_addr_mode == FRAME802154_SHORTADDRMODE) {
576  p[len++] = input_frame_buffer->uDestAddr.u16Short & 0xff;
577  p[len++] = (input_frame_buffer->uDestAddr.u16Short >> 8) & 0xff;
578  } else if(fcf.dest_addr_mode == FRAME802154_LONGADDRMODE) {
579  for(c = 0; c < 4; c++) {
580  p[len + c] = ((uint8_t*)(&input_frame_buffer->uDestAddr.sExt.u32L))[3 - c];
581  }
582  for(c = 0; c < 4; c++) {
583  p[len + c + 4] = ((uint8_t*)(&input_frame_buffer->uDestAddr.sExt.u32H))[3 - c];
584  }
585  len += 8;
586  }
587  if(has_src_panid) {
588  p[len++] = input_frame_buffer->u16SrcPAN & 0xff;
589  p[len++] = (input_frame_buffer->u16SrcPAN >> 8) & 0xff;
590  }
591  if(fcf.src_addr_mode == FRAME802154_SHORTADDRMODE) {
592  p[len++] = input_frame_buffer->uSrcAddr.u16Short & 0xff;
593  p[len++] = (input_frame_buffer->uSrcAddr.u16Short >> 8) & 0xff;
594  } else if(fcf.src_addr_mode == FRAME802154_LONGADDRMODE) {
595  for(c = 0; c < 4; c++) {
596  p[len + c] = ((uint8_t*)(&input_frame_buffer->uSrcAddr.sExt.u32L))[3 - c];
597  }
598  for(c = 0; c < 4; c++) {
599  p[len + c + 4] = ((uint8_t*)(&input_frame_buffer->uSrcAddr.sExt.u32H))[3 - c];
600  }
601  len += 8;
602  }
603  memcpy(&p[len], input_frame_buffer->uPayload.au8Byte, input_frame_buffer->u8PayloadLength);
604  len += input_frame_buffer->u8PayloadLength;
605 #else
606  uint16_t radio_last_rx_crc;
607  uint8_t radio_last_rx_crc_ok = 1;
608 
609  len = input_frame_buffer->u8PayloadLength;
610 
611  if(len <= CHECKSUM_LEN) {
612  input_frame_buffer->u8PayloadLength = 0;
613  return 0;
614  } else {
615  len -= CHECKSUM_LEN;
616  /* Check CRC */
617 #if CRC_SW
618  uint16_t checksum = crc16_data(input_frame_buffer->uPayload.au8Byte, len, 0);
619  radio_last_rx_crc =
620  (uint16_t)(input_frame_buffer->uPayload.au8Byte[len + 1] << (uint16_t)8)
621  | input_frame_buffer->uPayload.au8Byte[len];
622  radio_last_rx_crc_ok = (checksum == radio_last_rx_crc);
623  if(!radio_last_rx_crc_ok) {
624  }
625 #endif /* CRC_SW */
626  if(radio_last_rx_crc_ok) {
627  /* If we are in poll mode we need to check the frame here */
628  if(poll_mode) {
629  if(frame_filtering &&
630  !is_packet_for_us(input_frame_buffer->uPayload.au8Byte, len, 0)) {
631  len = 0;
632  } else {
633  read_last_rssi();
634  }
635  }
636  if(len != 0) {
637  bufsize = MIN(len, bufsize);
638  memcpy(buf, input_frame_buffer->uPayload.au8Byte, bufsize);
639  if(!poll_mode) {
640  /* Not in poll mode: packetbuf should not be accessed in interrupt context */
641  packetbuf_set_attr(PACKETBUF_ATTR_RSSI, radio_last_rssi);
642  packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, radio_last_correlation);
643  }
644  }
645  } else {
646  len = 0;
647  }
648  /* Disable further read attempts */
649  input_frame_buffer->u8PayloadLength = 0;
650  }
651 #endif
652  return len;
653 }
654 /*---------------------------------------------------------------------------*/
655 static void
656 set_txpower(int8_t power)
657 {
658  if(power > OUTPUT_POWER_MAX) {
659  current_tx_power = OUTPUT_POWER_MAX;
660  } else {
661  if(power < OUTPUT_POWER_MIN) {
662  current_tx_power = OUTPUT_POWER_MIN;
663  } else {
664  current_tx_power = power;
665  }
666  }
667  vMMAC_SetChannelAndPower(current_channel, current_tx_power);
668 }
669 /*--------------------------------------------------------------------------*/
670 static int
671 get_txpower(void)
672 {
673  int actual_tx_power;
674 #if (JENNIC_CHIP == JN5169)
675  /* Actual tx power value rounded to nearest integer number */
676  const static int8 power_table [] = {
677  -32, -30, -29, -29, /* -32 .. -29 */
678  -28, -28, -28, -28, /* -28 .. -25 */
679  -21, -21, -21, -2, /* -24 .. -21 */
680  -20, -19, -18, -17, /* -20 .. -17 */
681  -17, -17, -17, -10, /* -16 .. -13 */
682  -10, -10, -10, -9, /* -12 .. -09 */
683  -8, -7, -6, -6, /* -08 .. -05 */
684  -6, -6, 1, 1, /* -04 .. -01 */
685  1, 1, 2, 3, /* 00 .. 03 */
686  4, 5, 6, 7, /* 04 .. 07 */
687  9, 9, 10 }; /* 08 .. 10 */
688  if(current_tx_power > OUTPUT_POWER_MAX) {
689  actual_tx_power = OUTPUT_POWER_MAX;
690  } else if(current_tx_power < OUTPUT_POWER_MIN) {
691  actual_tx_power = OUTPUT_POWER_MIN;
692  } else {
693  actual_tx_power = power_table[current_tx_power + ABS_OUTPUT_POWER_MIN];
694  }
695 #else
696  /* Other JN516x chips */
697  if(current_tx_power < (-24)) {
698  actual_tx_power = OUTPUT_POWER_MIN;
699  } else if(current_tx_power < (-12)) {
700  actual_tx_power = (-20);
701  } else if(current_tx_power < 0) {
702  actual_tx_power = (-9);
703  } else {
704  actual_tx_power = OUTPUT_POWER_MAX;
705  }
706 #endif
707  return (int)actual_tx_power;
708 }
709 /*---------------------------------------------------------------------------*/
710 static int
711 get_detected_energy(void)
712 {
713  const uint32 u32Samples = 8;
714  return u8JPT_EnergyDetect(current_channel, u32Samples);
715 }
716 /*---------------------------------------------------------------------------*/
717 static int
718 get_rssi(void)
719 {
720  /* this approximate formula for RSSI is taken from NXP internal docs */
721  return (7 * get_detected_energy() - 1970) / 20;
722 }
723 /*---------------------------------------------------------------------------*/
724 static void
725 read_last_rssi(void)
726 {
727  uint8_t radio_last_rx_energy;
728  radio_last_rx_energy = u8MMAC_GetRxLqi((uint8_t *)&radio_last_correlation);
729  radio_last_rssi = i16JPT_ConvertEnergyTodBm(radio_last_rx_energy);
730 }
731 /*---------------------------------------------------------------------------*/
732 int
733 receiving_packet(void)
734 {
735  return bMMAC_RxDetected();
736 }
737 /*---------------------------------------------------------------------------*/
738 static int
739 pending_packet(void)
740 {
741  if(!poll_mode) {
742  return ringbufindex_peek_get(&input_ringbuf) != -1;
743  } else {
744  return u32MMAC_PollInterruptSource(
745  E_MMAC_INT_RX_COMPLETE | E_MMAC_INT_RX_HEADER);
746  }
747 }
748 /*---------------------------------------------------------------------------*/
749 static int
750 cca(void)
751 {
752  bool_t is_channel_busy = bJPT_CCA(current_channel,
753  E_JPT_CCA_MODE_CARRIER_OR_ENERGY,
754  cca_thershold);
755  return is_channel_busy == FALSE;
756 }
757 /*---------------------------------------------------------------------------*/
758 static void
759 radio_interrupt_handler(uint32 mac_event)
760 {
761  uint32_t rx_status;
762  uint8_t overflow = 0;
763  int get_index;
764  int put_index;
765 #if !MICROMAC_RADIO_MAC
766  int packet_for_me = 0;
767 #endif
768 
769  if(mac_event & E_MMAC_INT_TX_COMPLETE) {
770  /* Transmission attempt has finished */
771  tx_in_progress = 0;
772  } else if(mac_event & E_MMAC_INT_RX_COMPLETE) {
773  rx_status = u32MMAC_GetRxErrors();
774  /* If rx is successful */
775  if(rx_status == 0) {
776  /* Save SFD timestamp */
777  last_packet_timestamp = get_packet_timestamp();
778 
779  if(!poll_mode && (mac_event & E_MMAC_INT_RX_COMPLETE)) {
780 #if MICROMAC_RADIO_MAC
781  /* read and cache RSSI and LQI values */
782  read_last_rssi();
783  /* Put received frame in queue */
784  ringbufindex_put(&input_ringbuf);
785 
786  if((get_index = ringbufindex_peek_get(&input_ringbuf)) != -1) {
787  input_frame_buffer = &input_array[get_index];
788  }
789  process_poll(&micromac_radio_process);
790 
791  /* get pointer to next input slot */
792  put_index = ringbufindex_peek_put(&input_ringbuf);
793  /* is there space? */
794  if(put_index != -1) {
795  /* move rx_frame_buffer to next empty slot */
796  rx_frame_buffer = &input_array[put_index];
797  } else {
798  overflow = 1;
799  rx_frame_buffer = NULL;
800  }
801 #else
802  if(rx_frame_buffer->u8PayloadLength > CHECKSUM_LEN) {
803  if(frame_filtering) {
804  /* Check RX address */
805  packet_for_me = is_packet_for_us(rx_frame_buffer->uPayload.au8Byte, rx_frame_buffer->u8PayloadLength - CHECKSUM_LEN, 1);
806  } else if(!frame_filtering) {
807  packet_for_me = 1;
808  }
809  }
810  if(!packet_for_me) {
811  /* Prevent reading */
812  rx_frame_buffer->u8PayloadLength = 0;
813  } else {
814  /* read and cache RSSI and LQI values */
815  read_last_rssi();
816  /* Put received frame in queue */
817  ringbufindex_put(&input_ringbuf);
818 
819  if((get_index = ringbufindex_peek_get(&input_ringbuf)) != -1) {
820  input_frame_buffer = &input_array[get_index];
821  }
822  process_poll(&micromac_radio_process);
823 
824  /* get pointer to next input slot */
825  put_index = ringbufindex_peek_put(&input_ringbuf);
826  /* is there space? */
827  if(put_index != -1) {
828  /* move rx_frame_buffer to next empty slot */
829  rx_frame_buffer = &input_array[put_index];
830  } else {
831  overflow = 1;
832  rx_frame_buffer = NULL;
833  }
834  }
835 #endif
836  }
837  }
838  }
839  if(overflow) {
840  off();
841  } else if(MICROMAC_CONF_ALWAYS_ON
842  && (mac_event & (E_MMAC_INT_TX_COMPLETE | E_MMAC_INT_RX_COMPLETE))) {
843  on();
844  }
845 }
846 /*---------------------------------------------------------------------------*/
847 PROCESS_THREAD(micromac_radio_process, ev, data)
848 {
849  PROCESS_BEGIN();
850 
851  while(1) {
852  PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
853 
854  /* Pass received packets to upper layer */
855  int16_t read_index;
856  /* Loop on accessing (without removing) a pending input packet */
857  while((read_index = ringbufindex_peek_get(&input_ringbuf)) != -1) {
858  input_frame_buffer = &input_array[read_index];
859  /* Put packet into packetbuf for input callback */
860  packetbuf_clear();
861  int len = read(packetbuf_dataptr(), PACKETBUF_SIZE);
862  /* is packet valid? */
863  if(len > 0) {
865  NETSTACK_MAC.input();
866  }
867  /* Remove packet from ringbuf */
868  ringbufindex_get(&input_ringbuf);
869  /* Disable further read attempts */
870  input_frame_buffer->u8PayloadLength = 0;
871  }
872 
873  /* Are we recovering from overflow? */
874  if(rx_frame_buffer == NULL) {
875  /* get pointer to next input slot */
876  int put_index = ringbufindex_peek_put(&input_ringbuf);
877  /* is there space? */
878  if(put_index != -1) {
879  /* move rx_frame_buffer to next empty slot */
880  rx_frame_buffer = &input_array[put_index];
881  /* do we need to turn radio on? */
882  if(MICROMAC_CONF_ALWAYS_ON || missed_radio_on_request) {
883  missed_radio_on_request = 0;
884  on();
885  }
886  } else {
887  rx_frame_buffer = NULL;
888  }
889  }
890  }
891  PROCESS_END();
892 }
893 /*---------------------------------------------------------------------------*/
894 static void
895 set_frame_filtering(uint8_t enable)
896 {
897  frame_filtering = enable;
898 }
899 /*---------------------------------------------------------------------------*/
900 static void
901 set_autoack(uint8_t enable)
902 {
903  autoack_enabled = enable;
904 }
905 /*---------------------------------------------------------------------------*/
906 static void
907 set_poll_mode(uint8_t enable)
908 {
909  poll_mode = enable;
910  if(poll_mode) {
911  /* Disable interrupts */
912  vMMAC_EnableInterrupts(NULL);
913  vMMAC_ConfigureInterruptSources(0);
914  } else {
915  /* Initialize and enable interrupts */
916  /* TODO: enable E_MMAC_INT_RX_HEADER & filter out frames after header rx */
917  vMMAC_ConfigureInterruptSources(
918  E_MMAC_INT_RX_COMPLETE | E_MMAC_INT_TX_COMPLETE);
919  vMMAC_EnableInterrupts(&radio_interrupt_handler);
920  }
921 }
922 /* Enable or disable CCA before sending */
923 static void
924 set_send_on_cca(uint8_t enable)
925 {
926  send_on_cca = enable;
927 }
928 /*---------------------------------------------------------------------------*/
929 static radio_result_t
930 get_value(radio_param_t param, radio_value_t *value)
931 {
932  if(!value) {
933  return RADIO_RESULT_INVALID_VALUE;
934  }
935  switch(param) {
936  case RADIO_PARAM_POWER_MODE:
937  *value = listen_on || tx_in_progress ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF;
938  return RADIO_RESULT_OK;
939  case RADIO_PARAM_CHANNEL:
940  *value = get_channel();
941  return RADIO_RESULT_OK;
942  case RADIO_PARAM_RX_MODE:
943  *value = 0;
944  if(frame_filtering) {
946  }
947  if(autoack_enabled) {
948  *value |= RADIO_RX_MODE_AUTOACK;
949  }
950  if(poll_mode) {
951  *value |= RADIO_RX_MODE_POLL_MODE;
952  }
953  return RADIO_RESULT_OK;
954  case RADIO_PARAM_TX_MODE:
955  *value = 0;
956  if(send_on_cca) {
957  *value |= RADIO_TX_MODE_SEND_ON_CCA;
958  }
959  return RADIO_RESULT_OK;
960  case RADIO_PARAM_TXPOWER:
961  *value = get_txpower();
962  return RADIO_RESULT_OK;
963  case RADIO_PARAM_RSSI:
964  *value = get_rssi();
965  return RADIO_RESULT_OK;
966  case RADIO_PARAM_LAST_RSSI:
967  *value = radio_last_rssi;
968  return RADIO_RESULT_OK;
969  case RADIO_PARAM_CCA_THRESHOLD:
970  *value = cca_thershold;
971  return RADIO_RESULT_OK;
972  case RADIO_CONST_CHANNEL_MIN:
973  *value = 11;
974  return RADIO_RESULT_OK;
975  case RADIO_CONST_CHANNEL_MAX:
976  *value = 26;
977  return RADIO_RESULT_OK;
978  case RADIO_CONST_TXPOWER_MIN:
979  *value = OUTPUT_POWER_MIN;
980  return RADIO_RESULT_OK;
981  case RADIO_CONST_TXPOWER_MAX:
982  *value = OUTPUT_POWER_MAX;
983  return RADIO_RESULT_OK;
984  default:
985  return RADIO_RESULT_NOT_SUPPORTED;
986  }
987 }
988 /*---------------------------------------------------------------------------*/
989 static radio_result_t
990 set_value(radio_param_t param, radio_value_t value)
991 {
992  switch(param) {
993  case RADIO_PARAM_POWER_MODE:
994  if(value == RADIO_POWER_MODE_ON) {
995  on();
996  return RADIO_RESULT_OK;
997  }
998  if(value == RADIO_POWER_MODE_OFF) {
999  off();
1000  return RADIO_RESULT_OK;
1001  }
1002  return RADIO_RESULT_INVALID_VALUE;
1003  case RADIO_PARAM_CHANNEL:
1004  if(value < 11 || value > 26) {
1005  return RADIO_RESULT_INVALID_VALUE;
1006  }
1007  set_channel(value);
1008  return RADIO_RESULT_OK;
1009  case RADIO_PARAM_RX_MODE:
1010  if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
1011  RADIO_RX_MODE_AUTOACK | RADIO_RX_MODE_POLL_MODE)) {
1012  return RADIO_RESULT_INVALID_VALUE;
1013  }
1014  set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
1015  set_autoack((value & RADIO_RX_MODE_AUTOACK) != 0);
1016  set_poll_mode((value & RADIO_RX_MODE_POLL_MODE) != 0);
1017  return RADIO_RESULT_OK;
1018  case RADIO_PARAM_TX_MODE:
1019  if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) {
1020  return RADIO_RESULT_INVALID_VALUE;
1021  }
1022  set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0);
1023  return RADIO_RESULT_OK;
1024  case RADIO_PARAM_TXPOWER:
1025  if(value < OUTPUT_POWER_MIN || value > OUTPUT_POWER_MAX) {
1026  return RADIO_RESULT_INVALID_VALUE;
1027  /* Find the closest higher PA_LEVEL for the desired output power */
1028  }
1029  set_txpower(value);
1030  return RADIO_RESULT_OK;
1031  case RADIO_PARAM_CCA_THRESHOLD:
1032  cca_thershold = value;
1033  return RADIO_RESULT_OK;
1034  default:
1035  return RADIO_RESULT_NOT_SUPPORTED;
1036  }
1037 }
1038 /*---------------------------------------------------------------------------*/
1039 static radio_result_t
1040 get_object(radio_param_t param, void *dest, size_t size)
1041 {
1042  if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) {
1043  if(size != sizeof(rtimer_clock_t) || !dest) {
1044  return RADIO_RESULT_INVALID_VALUE;
1045  }
1046  *(rtimer_clock_t *)dest = get_packet_timestamp();
1047 
1048  return RADIO_RESULT_OK;
1049  }
1050  return RADIO_RESULT_NOT_SUPPORTED;
1051 }
1052 /*---------------------------------------------------------------------------*/
1053 static radio_result_t
1054 set_object(radio_param_t param, const void *src, size_t size)
1055 {
1056  return RADIO_RESULT_NOT_SUPPORTED;
1057 }
1058 /*---------------------------------------------------------------------------*/
1059 const struct radio_driver micromac_radio_driver = {
1060  init,
1061  prepare,
1062  transmit,
1063  send,
1064  read,
1065  cca,
1068  on,
1069  off,
1070  get_value,
1071  set_value,
1072  get_object,
1073  set_object
1074 };
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
Definition: radio.h:280
uint16_t src_pid
Source PAN ID.
Definition: frame802154.h:207
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
Definition: packetbuf.c:143
uint8_t dest_addr_mode
2 bit.
Definition: frame802154.h:161
int(* prepare)(const void *payload, unsigned short payload_len)
Prepare the radio with a packet to be sent.
Definition: radio.h:242
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
void ringbufindex_init(struct ringbufindex *r, uint8_t size)
Initialize a ring buffer.
Definition: ringbufindex.c:50
Header file for the ringbufindex library
frame802154_fcf_t fcf
Frame control field.
Definition: frame802154.h:204
void packetbuf_clear(void)
Clear and reset the packetbuf.
Definition: packetbuf.c:75
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:115
Header file for the energy estimation mechanism
int ringbufindex_peek_get(const struct ringbufindex *r)
Return the index of the first element which will be removed if calling ringbufindex_get.
Definition: ringbufindex.c:115
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
Definition: process.h:178
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
Definition: frame802154.c:500
int(* receiving_packet)(void)
Check if the radio driver is currently receiving a packet.
Definition: radio.h:258
Header file for the CRC16 calculcation
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
Definition: radio.h:273
int(* pending_packet)(void)
Check if the radio driver has just received a packet.
Definition: radio.h:261
The structure of a device driver for a radio in Contiki.
Definition: radio.h:237
int payload_len
Length of payload field.
Definition: frame802154.h:210
A set of debugging macros for the IP stack
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
uint8_t src_addr[8]
Source address.
Definition: frame802154.h:203
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition: linkaddr.c:48
#define IEEE802154_DEFAULT_CHANNEL
The default channel for IEEE 802.15.4 networks.
Definition: mac.h:52
#define RTIMER_NOW()
Get the current clock time.
Definition: rtimer.h:158
void(* input)(void)
Callback for getting notified of incoming packet.
Definition: mac.h:72
int(* send)(const void *payload, unsigned short payload_len)
Prepare & transmit a packet.
Definition: radio.h:248
int(* transmit)(unsigned short transmit_len)
Send the packet that has previously been prepared.
Definition: radio.h:245
void process_poll(struct process *p)
Request a process to be polled.
Definition: process.c:371
int(* off)(void)
Turn the radio off.
Definition: radio.h:267
The IEEE 802.15.4 frame has a number of constant/fixed fields that can be counted to make frame const...
Definition: frame802154.h:152
Header file for the real-time timer module.
unsigned short crc16_data(const unsigned char *data, int len, unsigned short acc)
Calculate the CRC16 over a data area.
Definition: crc16.c:66
uint8_t src_addr_mode
2 bit.
Definition: frame802154.h:163
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
Definition: packetbuf.h:66
MICROMAC_RADIO driver header file
802.15.4 frame creation and parsing functions
#define RADIO_RX_MODE_ADDRESS_FILTER
The radio reception mode controls address filtering and automatic transmission of acknowledgements in...
Definition: radio.h:204
uint16_t dest_pid
Destination PAN ID.
Definition: frame802154.h:206
Parameters used by the frame802154_create() function.
Definition: frame802154.h:198
#define RADIO_TX_MODE_SEND_ON_CCA
The radio transmission mode controls whether transmissions should be done using clear channel assessm...
Definition: radio.h:216
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
Definition: linkaddr.c:69
static int8_t set_channel(uint8_t channel)
Set the current operating channel.
Definition: cc2538-rf.c:172
uint8_t seq
Sequence number.
Definition: frame802154.h:205
int ringbufindex_get(struct ringbufindex *r)
Remove the first element and return its index.
Definition: ringbufindex.c:90
int(* read)(void *buf, unsigned short buf_len)
Read a received packet into a buffer.
Definition: radio.h:251
int ringbufindex_peek_put(const struct ringbufindex *r)
Check if there is space to put an element.
Definition: ringbufindex.c:78
Header file for the Packet buffer (packetbuf) management
Include file for the Contiki low-layer network stack (NETSTACK)
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.
Definition: radio.h:270
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Definition: cc2538-rf.c:1008
uint8_t * payload
Pointer to 802.15.4 payload.
Definition: frame802154.h:209
uint8_t dest_addr[8]
Destination address.
Definition: frame802154.h:202
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
Definition: radio.h:286
Header file for the LED HAL.
int ringbufindex_put(struct ringbufindex *r)
Put one element to the ring buffer.
Definition: ringbufindex.c:58
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
Definition: packetbuf.c:136
int(* on)(void)
Turn the radio on.
Definition: radio.h:264
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
static uint8_t get_channel()
Get the current operating channel.
Definition: cc2538-rf.c:157