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 /* Local variables */
134 static volatile signed char radio_last_rssi;
135 static volatile uint8_t radio_last_correlation; /* LQI */
136 
137 /* Did we miss a request to turn the radio on due to overflow? */
138 static volatile uint8_t missed_radio_on_request = 0;
139 
140 /* Poll mode disabled by default */
141 static uint8_t poll_mode = 0;
142 /* (Software) frame filtering enabled by default */
143 static uint8_t frame_filtering = 1;
144 /* (Software) autoack */
145 static uint8_t autoack_enabled = MICROMAC_CONF_AUTOACK;
146 /* CCA before sending? Disabled by default. */
147 static uint8_t send_on_cca = 0;
148 
149 /* Current radio channel */
150 static int current_channel = IEEE802154_DEFAULT_CHANNEL;
151 
152 /* Current set point tx power
153  Actual tx power may be different. Use get_txpower() for actual power */
154 static int current_tx_power = MICROMAC_CONF_TX_POWER;
155 
156 /* an integer between 0 and 255, used only with cca() */
157 static uint8_t cca_thershold = MICROMAC_CONF_CCA_THR;
158 
159 /* Tx in progress? */
160 static volatile uint8_t tx_in_progress = 0;
161 /* Are we currently listening? */
162 static volatile uint8_t listen_on = 0;
163 
164 /* Is the driver currently transmitting a software ACK? */
165 static uint8_t in_ack_transmission = 0;
166 
167 /* TX frame buffer */
168 static MICROMAC_FRAME tx_frame_buffer;
169 
170 /* RX frame buffer */
171 static MICROMAC_FRAME *rx_frame_buffer;
172 
173 /* Frame buffer pointer to read from */
174 static MICROMAC_FRAME *input_frame_buffer = NULL;
175 
176 /* Ringbuffer for received packets in interrupt enabled mode */
177 static struct ringbufindex input_ringbuf;
178 static MICROMAC_FRAME input_array[MIRCOMAC_CONF_BUF_NUM];
179 
180 /* SFD timestamp in RTIMER ticks */
181 static volatile uint32_t last_packet_timestamp = 0;
182 
183 /* Local functions prototypes */
184 static int on(void);
185 static int off(void);
186 #if !MICROMAC_RADIO_MAC
187 static int is_packet_for_us(uint8_t *buf, int len, int do_send_ack);
188 #endif
189 static void set_frame_filtering(uint8_t enable);
190 static rtimer_clock_t get_packet_timestamp(void);
191 static void set_txpower(int8_t power);
192 void set_channel(int c);
193 static void radio_interrupt_handler(uint32 mac_event);
194 static int get_detected_energy(void);
195 static int get_rssi(void);
196 static void read_last_rssi(void);
197 
198 /*---------------------------------------------------------------------------*/
199 PROCESS(micromac_radio_process, "micromac_radio_driver");
200 /*---------------------------------------------------------------------------*/
201 
202 /* Custom Radio parameters */
203 #ifndef RADIO_RX_MODE_POLL_MODE
204 #define RADIO_PARAM_LAST_RSSI 0x80
205 #define RADIO_PARAM_LAST_PACKET_TIMESTAMP 0x81
206 #define RADIO_RX_MODE_POLL_MODE (1 << 2)
207 #endif /* RADIO_RX_MODE_POLL_MODE */
208 
209 /*---------------------------------------------------------------------------*/
210 static rtimer_clock_t
211 get_packet_timestamp(void)
212 {
213  /* Wait for an edge */
214  uint32_t t = u32MMAC_GetTime();
215  while(u32MMAC_GetTime() == t);
216  /* Save SFD timestamp, converted from radio timer to RTIMER */
217  last_packet_timestamp = RTIMER_NOW() -
218  RADIO_TO_RTIMER((uint32_t)(u32MMAC_GetTime() - (u32MMAC_GetRxTime() - 1)));
219  /* The remaining measured error is typically in range 0..16 usec.
220  * Center it around zero, in the -8..+8 usec range. */
221  last_packet_timestamp -= US_TO_RTIMERTICKS(8);
222  return last_packet_timestamp;
223 }
224 /*---------------------------------------------------------------------------*/
225 static int
226 init_software(void)
227 {
228  int put_index;
229  /* Initialize ring buffer and first input packet pointer */
230  ringbufindex_init(&input_ringbuf, MIRCOMAC_CONF_BUF_NUM);
231  /* get pointer to next input slot */
232  put_index = ringbufindex_peek_put(&input_ringbuf);
233  if(put_index == -1) {
234  rx_frame_buffer = NULL;
235  printf("micromac_radio init:! no buffer available. Abort init.\n");
236  off();
237  return 0;
238  } else {
239  rx_frame_buffer = &input_array[put_index];
240  }
241  input_frame_buffer = rx_frame_buffer;
242 
243  process_start(&micromac_radio_process, NULL);
244 
245  return 1;
246 }
247 /*---------------------------------------------------------------------------*/
248 static int
249 init(void)
250 {
251  int ret = 1;
252  tsExtAddr node_long_address;
253  uint16_t node_short_address;
254  static uint8_t is_initialized;
255 
256  tx_in_progress = 0;
257 
258  u32JPT_Init();
259  vMMAC_Enable();
260 
261  /* Enable/disable interrupts */
262  if(poll_mode) {
263  vMMAC_EnableInterrupts(NULL);
264  vMMAC_ConfigureInterruptSources(0);
265  } else {
266  vMMAC_EnableInterrupts(&radio_interrupt_handler);
267  }
268  vMMAC_ConfigureRadio();
269  set_txpower(current_tx_power); /* it sets also the current_channel */
270 
271  vMMAC_GetMacAddress(&node_long_address);
272  /* Short addresses are disabled by default */
273  node_short_address = (uint16_t)node_long_address.u32L;
274  vMMAC_SetRxAddress(frame802154_get_pan_id(), node_short_address, &node_long_address);
275 
276  /* Disable hardware backoff */
277  vMMAC_SetTxParameters(1, 0, 0, 0);
278  vMMAC_SetCutOffTimer(0, FALSE);
279 
280 #if RADIO_TEST_MODE == RADIO_TEST_MODE_HIGH_PWR
281  /* Enable high power mode.
282  * In this mode DIO2 goes high during RX
283  * and DIO3 goes high during TX
284  **/
285  vREG_SysWrite(REG_SYS_PWR_CTRL,
286  u32REG_SysRead(REG_SYS_PWR_CTRL)
287  | REG_SYSCTRL_PWRCTRL_RFRXEN_MASK
288  | REG_SYSCTRL_PWRCTRL_RFTXEN_MASK);
289 #elif RADIO_TEST_MODE == RADIO_TEST_MODE_ADVANCED
290  /* output internal radio status on IO pins.
291  * See Chris@NXP email */
292  vREG_SysWrite(REG_SYS_PWR_CTRL,
293  u32REG_SysRead(REG_SYS_PWR_CTRL) | (1UL << 26UL));
294 #endif /* TEST_MODE */
295 
296  if(!is_initialized) {
297  is_initialized = 1;
298  ret = init_software();
299  }
300 
301  return ret;
302 }
303 /*---------------------------------------------------------------------------*/
304 static int
305 on(void)
306 {
307  /* No address matching or frame decoding */
308  if(rx_frame_buffer != NULL) {
309 #if MICROMAC_RADIO_MAC
310  vMMAC_StartMacReceive(rx_frame_buffer,
311  (uint16_t)(E_MMAC_RX_START_NOW
312  | E_MMAC_RX_USE_AUTO_ACK
313  | E_MMAC_RX_NO_MALFORMED
314  | E_MMAC_RX_NO_FCS_ERROR
315  | E_MMAC_RX_ADDRESS_MATCH
316  | E_MMAC_RX_ALIGN_NORMAL)
317  );
318 #else
319  vMMAC_StartPhyReceive(rx_frame_buffer,
320  (uint16_t)(E_MMAC_RX_START_NOW
321  | E_MMAC_RX_NO_FCS_ERROR) /* means: reject FCS errors */
322  );
323 #endif
324  } else {
325  missed_radio_on_request = 1;
326  }
327  ENERGEST_ON(ENERGEST_TYPE_LISTEN);
328  listen_on = 1;
329  return 1;
330 }
331 /*---------------------------------------------------------------------------*/
332 static int
333 off(void)
334 {
335  listen_on = 0;
336  tx_in_progress = 0;
337 
338  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
339 
340  /* The following would be needed with delayed Tx/Rx functions
341  * vMMAC_SetCutOffTimer(0, FALSE);*/
342  vMMAC_RadioOff();
343 
344  return 1;
345 }
346 /*---------------------------------------------------------------------------*/
347 static int
348 transmit(unsigned short payload_len)
349 {
350  if(tx_in_progress) {
351  return RADIO_TX_COLLISION;
352  }
353  tx_in_progress = 1;
354 
355  /* Energest */
356  if(listen_on) {
357  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
358  }
359  ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
360 
361  /* Transmit and wait */
362 #if MICROMAC_RADIO_MAC
363  vMMAC_StartMacTransmit(&tx_frame_buffer,
364  E_MMAC_TX_START_NOW |
365  E_MMAC_TX_USE_AUTO_ACK |
366  (send_on_cca ? E_MMAC_TX_USE_CCA : E_MMAC_TX_NO_CCA));
367 #else
368  vMMAC_StartPhyTransmit(&tx_frame_buffer,
369  E_MMAC_TX_START_NOW |
370  (send_on_cca ? E_MMAC_TX_USE_CCA : E_MMAC_TX_NO_CCA));
371 #endif
372  if(poll_mode) {
373  RTIMER_BUSYWAIT_UNTIL(u32MMAC_PollInterruptSource(E_MMAC_INT_TX_COMPLETE), MAX_PACKET_DURATION);
374  } else {
375  if(in_ack_transmission) {
376  /* as nested interupts are not possible, the tx flag will never be cleared */
377  RTIMER_BUSYWAIT_UNTIL(FALSE, MAX_ACK_DURATION);
378  } else {
379  /* wait until the tx flag is cleared */
380  RTIMER_BUSYWAIT_UNTIL(!tx_in_progress, MAX_PACKET_DURATION);
381  }
382  }
383 
384  /* Energest */
385  ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
386  if(listen_on) {
387  ENERGEST_ON(ENERGEST_TYPE_LISTEN);
388  }
389  tx_in_progress = 0;
390 
391  /* Check error code */
392  int ret;
393  uint32_t tx_error = u32MMAC_GetTxErrors();
394  if(tx_error == 0) {
395  ret = RADIO_TX_OK;
396  } else if(tx_error & E_MMAC_TXSTAT_ABORTED) {
397  ret = RADIO_TX_ERR;
398  } else if(tx_error & E_MMAC_TXSTAT_CCA_BUSY) {
399  ret = RADIO_TX_COLLISION;
400  } else if(tx_error & E_MMAC_TXSTAT_NO_ACK) {
401  ret = RADIO_TX_NOACK;
402  } else {
403  ret = RADIO_TX_ERR;
404  }
405  return ret;
406 }
407 /*---------------------------------------------------------------------------*/
408 static int
409 prepare(const void *payload, unsigned short payload_len)
410 {
411 #if !MICROMAC_RADIO_MAC
412  uint8_t i;
413  uint16_t checksum;
414 #endif
415 
416  if(tx_in_progress) {
417  return 1;
418  }
419  if(payload_len > 127 || payload == NULL) {
420  return 1;
421  }
422 #if MICROMAC_RADIO_MAC
423  frame802154_t info154;
424  int hdr_len = frame802154_parse((unsigned char *)payload, payload_len, &info154);
425  //TODO: hdr_len contains security header, which are not managed by micromac
426  tx_frame_buffer.u8PayloadLength = payload_len - hdr_len;
427  tx_frame_buffer.u8SequenceNum = info154.seq;
428  tx_frame_buffer.u16FCF = ((uint8_t*)payload)[0] | (((uint8_t*)payload)[1] << 8);
429  tx_frame_buffer.u16DestPAN = info154.dest_pid;
430  tx_frame_buffer.u16SrcPAN = info154.src_pid;
431  if(info154.fcf.dest_addr_mode == FRAME802154_SHORTADDRMODE) {
432  tx_frame_buffer.uDestAddr.u16Short = info154.dest_addr[0] | (info154.dest_addr[0] << 8);
433  } else if(info154.fcf.dest_addr_mode == FRAME802154_LONGADDRMODE) {
434  tx_frame_buffer.uDestAddr.sExt.u32L = *(uint32_t*)(&info154.dest_addr[4]);
435  tx_frame_buffer.uDestAddr.sExt.u32H = *(uint32_t*)(&info154.dest_addr[0]);
436  }
437  if(info154.fcf.src_addr_mode == FRAME802154_SHORTADDRMODE) {
438  tx_frame_buffer.uSrcAddr.u16Short = info154.src_addr[0] | (info154.src_addr[0] << 8);
439  } else if(info154.fcf.src_addr_mode == FRAME802154_LONGADDRMODE) {
440  tx_frame_buffer.uSrcAddr.sExt.u32L = *(uint32_t*)(&info154.src_addr[4]);
441  tx_frame_buffer.uSrcAddr.sExt.u32H = *(uint32_t*)(&info154.src_addr[0]);
442  }
443  tx_frame_buffer.u16FCS = crc16_data(payload, payload_len, 0);
444  memcpy(tx_frame_buffer.uPayload.au8Byte, info154.payload, info154.payload_len);
445 #else
446  /* Copy payload to (soft) Ttx buffer */
447  memcpy(tx_frame_buffer.uPayload.au8Byte, payload, payload_len);
448  i = payload_len;
449 #if CRC_SW
450  /* Compute CRC */
451  checksum = crc16_data(payload, payload_len, 0);
452  tx_frame_buffer.uPayload.au8Byte[i++] = checksum;
453  tx_frame_buffer.uPayload.au8Byte[i++] = (checksum >> 8) & 0xff;
454  tx_frame_buffer.u8PayloadLength = payload_len + CHECKSUM_LEN;
455 #else
456  tx_frame_buffer.u8PayloadLength = payload_len;
457 #endif
458 #endif
459 
460  return 0;
461 }
462 /*---------------------------------------------------------------------------*/
463 static int
464 send(const void *payload, unsigned short payload_len)
465 {
466  if(prepare(payload, payload_len) == 0) {
467  return transmit(payload_len);
468  } else {
469  return RADIO_TX_ERR;
470  }
471 }
472 /*---------------------------------------------------------------------------*/
473 int
474 get_channel(void)
475 {
476  return current_channel;
477 }
478 /*---------------------------------------------------------------------------*/
479 void
480 set_channel(int c)
481 {
482  current_channel = c;
483  vMMAC_SetChannelAndPower(current_channel, current_tx_power);
484 }
485 /*---------------------------------------------------------------------------*/
486 #if !MICROMAC_RADIO_MAC
487 static int
488 is_broadcast_addr(uint8_t mode, uint8_t *addr)
489 {
490  int i = ((mode == FRAME802154_SHORTADDRMODE) ? 2 : 8);
491  while(i-- > 0) {
492  if(addr[i] != 0xff) {
493  return 0;
494  }
495  }
496  return 1;
497 }
498 /*---------------------------------------------------------------------------*/
499 /* Send an ACK */
500 static void
501 send_ack(const frame802154_t *frame)
502 {
503  uint8_t buffer[3];
504  /* FCF: 2 octets */
505  buffer[0] = FRAME802154_ACKFRAME;
506  buffer[1] = 0;
507  /* Seqnum: 1 octets */
508  buffer[2] = frame->seq;
509  in_ack_transmission = 1;
510  send(&buffer, sizeof(buffer));
511  in_ack_transmission = 0;
512 }
513 /*---------------------------------------------------------------------------*/
514 /* Check if a packet is for us */
515 static int
516 is_packet_for_us(uint8_t *buf, int len, int do_send_ack)
517 {
518  frame802154_t frame;
519  int result;
520  uint8_t parsed = frame802154_parse(buf, len, &frame);
521  if(parsed) {
522  if(frame.fcf.dest_addr_mode) {
523  int has_dest_panid;
524  frame802154_has_panid(&frame.fcf, NULL, &has_dest_panid);
525  if(has_dest_panid
526  && frame802154_get_pan_id() != FRAME802154_BROADCASTPANDID
527  && frame.dest_pid != frame802154_get_pan_id()
528  && frame.dest_pid != FRAME802154_BROADCASTPANDID) {
529  /* Packet to another PAN */
530  return 0;
531  }
532  if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
533  result = linkaddr_cmp((linkaddr_t *)frame.dest_addr, &linkaddr_node_addr);
534  if(autoack_enabled && result && do_send_ack) {
535  /* this is a unicast frame and sending ACKs is enabled */
536  send_ack(&frame);
537  }
538  return result;
539  }
540  }
541  return 1;
542  } else {
543  return 0;
544  }
545 }
546 #endif
547 /*---------------------------------------------------------------------------*/
548 static int
549 read(void *buf, unsigned short bufsize)
550 {
551  int len = 0;
552 #if MICROMAC_RADIO_MAC
553  frame802154_fcf_t fcf;
554  uint8_t *p = (uint8_t*)buf;
555  int has_src_panid;
556  int has_dest_panid;
557  int c;
558 
559  p[len++] = input_frame_buffer->u16FCF & 0xff;
560  p[len++] = (input_frame_buffer->u16FCF >> 8) & 0xff;
561  frame802154_parse_fcf(p, &fcf);
562  p[len++] = input_frame_buffer->u8SequenceNum;
563  frame802154_has_panid(&fcf, &has_src_panid, &has_dest_panid);
564  if(has_dest_panid) {
565  p[len++] = input_frame_buffer->u16DestPAN & 0xff;
566  p[len++] = (input_frame_buffer->u16DestPAN >> 8) & 0xff;
567  }
568  if(fcf.dest_addr_mode == FRAME802154_SHORTADDRMODE) {
569  p[len++] = input_frame_buffer->uDestAddr.u16Short & 0xff;
570  p[len++] = (input_frame_buffer->uDestAddr.u16Short >> 8) & 0xff;
571  } else if(fcf.dest_addr_mode == FRAME802154_LONGADDRMODE) {
572  for(c = 0; c < 4; c++) {
573  p[len + c] = ((uint8_t*)(&input_frame_buffer->uDestAddr.sExt.u32L))[3 - c];
574  }
575  for(c = 0; c < 4; c++) {
576  p[len + c + 4] = ((uint8_t*)(&input_frame_buffer->uDestAddr.sExt.u32H))[3 - c];
577  }
578  len += 8;
579  }
580  if(has_src_panid) {
581  p[len++] = input_frame_buffer->u16SrcPAN & 0xff;
582  p[len++] = (input_frame_buffer->u16SrcPAN >> 8) & 0xff;
583  }
584  if(fcf.src_addr_mode == FRAME802154_SHORTADDRMODE) {
585  p[len++] = input_frame_buffer->uSrcAddr.u16Short & 0xff;
586  p[len++] = (input_frame_buffer->uSrcAddr.u16Short >> 8) & 0xff;
587  } else if(fcf.src_addr_mode == FRAME802154_LONGADDRMODE) {
588  for(c = 0; c < 4; c++) {
589  p[len + c] = ((uint8_t*)(&input_frame_buffer->uSrcAddr.sExt.u32L))[3 - c];
590  }
591  for(c = 0; c < 4; c++) {
592  p[len + c + 4] = ((uint8_t*)(&input_frame_buffer->uSrcAddr.sExt.u32H))[3 - c];
593  }
594  len += 8;
595  }
596  memcpy(&p[len], input_frame_buffer->uPayload.au8Byte, input_frame_buffer->u8PayloadLength);
597  len += input_frame_buffer->u8PayloadLength;
598 #else
599  uint16_t radio_last_rx_crc;
600  uint8_t radio_last_rx_crc_ok = 1;
601 
602  len = input_frame_buffer->u8PayloadLength;
603 
604  if(len <= CHECKSUM_LEN) {
605  input_frame_buffer->u8PayloadLength = 0;
606  return 0;
607  } else {
608  len -= CHECKSUM_LEN;
609  /* Check CRC */
610 #if CRC_SW
611  uint16_t checksum = crc16_data(input_frame_buffer->uPayload.au8Byte, len, 0);
612  radio_last_rx_crc =
613  (uint16_t)(input_frame_buffer->uPayload.au8Byte[len + 1] << (uint16_t)8)
614  | input_frame_buffer->uPayload.au8Byte[len];
615  radio_last_rx_crc_ok = (checksum == radio_last_rx_crc);
616  if(!radio_last_rx_crc_ok) {
617  }
618 #endif /* CRC_SW */
619  if(radio_last_rx_crc_ok) {
620  /* If we are in poll mode we need to check the frame here */
621  if(poll_mode) {
622  if(frame_filtering &&
623  !is_packet_for_us(input_frame_buffer->uPayload.au8Byte, len, 0)) {
624  len = 0;
625  } else {
626  read_last_rssi();
627  }
628  }
629  if(len != 0) {
630  bufsize = MIN(len, bufsize);
631  memcpy(buf, input_frame_buffer->uPayload.au8Byte, bufsize);
632  if(!poll_mode) {
633  /* Not in poll mode: packetbuf should not be accessed in interrupt context */
634  packetbuf_set_attr(PACKETBUF_ATTR_RSSI, radio_last_rssi);
635  packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, radio_last_correlation);
636  }
637  }
638  } else {
639  len = 0;
640  }
641  /* Disable further read attempts */
642  input_frame_buffer->u8PayloadLength = 0;
643  }
644 #endif
645  return len;
646 }
647 /*---------------------------------------------------------------------------*/
648 static void
649 set_txpower(int8_t power)
650 {
651  if(power > OUTPUT_POWER_MAX) {
652  current_tx_power = OUTPUT_POWER_MAX;
653  } else {
654  if(power < OUTPUT_POWER_MIN) {
655  current_tx_power = OUTPUT_POWER_MIN;
656  } else {
657  current_tx_power = power;
658  }
659  }
660  vMMAC_SetChannelAndPower(current_channel, current_tx_power);
661 }
662 /*--------------------------------------------------------------------------*/
663 static int
664 get_txpower(void)
665 {
666  int actual_tx_power;
667 #if (JENNIC_CHIP == JN5169)
668  /* Actual tx power value rounded to nearest integer number */
669  const static int8 power_table [] = {
670  -32, -30, -29, -29, /* -32 .. -29 */
671  -28, -28, -28, -28, /* -28 .. -25 */
672  -21, -21, -21, -2, /* -24 .. -21 */
673  -20, -19, -18, -17, /* -20 .. -17 */
674  -17, -17, -17, -10, /* -16 .. -13 */
675  -10, -10, -10, -9, /* -12 .. -09 */
676  -8, -7, -6, -6, /* -08 .. -05 */
677  -6, -6, 1, 1, /* -04 .. -01 */
678  1, 1, 2, 3, /* 00 .. 03 */
679  4, 5, 6, 7, /* 04 .. 07 */
680  9, 9, 10 }; /* 08 .. 10 */
681  if(current_tx_power > OUTPUT_POWER_MAX) {
682  actual_tx_power = OUTPUT_POWER_MAX;
683  } else if(current_tx_power < OUTPUT_POWER_MIN) {
684  actual_tx_power = OUTPUT_POWER_MIN;
685  } else {
686  actual_tx_power = power_table[current_tx_power + ABS_OUTPUT_POWER_MIN];
687  }
688 #else
689  /* Other JN516x chips */
690  if(current_tx_power < (-24)) {
691  actual_tx_power = OUTPUT_POWER_MIN;
692  } else if(current_tx_power < (-12)) {
693  actual_tx_power = (-20);
694  } else if(current_tx_power < 0) {
695  actual_tx_power = (-9);
696  } else {
697  actual_tx_power = OUTPUT_POWER_MAX;
698  }
699 #endif
700  return (int)actual_tx_power;
701 }
702 /*---------------------------------------------------------------------------*/
703 static int
704 get_detected_energy(void)
705 {
706  const uint32 u32Samples = 8;
707  return u8JPT_EnergyDetect(current_channel, u32Samples);
708 }
709 /*---------------------------------------------------------------------------*/
710 static int
711 get_rssi(void)
712 {
713  /* this approximate formula for RSSI is taken from NXP internal docs */
714  return (7 * get_detected_energy() - 1970) / 20;
715 }
716 /*---------------------------------------------------------------------------*/
717 static void
718 read_last_rssi(void)
719 {
720  uint8_t radio_last_rx_energy;
721  radio_last_rx_energy = u8MMAC_GetRxLqi((uint8_t *)&radio_last_correlation);
722  radio_last_rssi = i16JPT_ConvertEnergyTodBm(radio_last_rx_energy);
723 }
724 /*---------------------------------------------------------------------------*/
725 int
726 receiving_packet(void)
727 {
728  return bMMAC_RxDetected();
729 }
730 /*---------------------------------------------------------------------------*/
731 static int
732 pending_packet(void)
733 {
734  if(!poll_mode) {
735  return ringbufindex_peek_get(&input_ringbuf) != -1;
736  } else {
737  return u32MMAC_PollInterruptSource(
738  E_MMAC_INT_RX_COMPLETE | E_MMAC_INT_RX_HEADER);
739  }
740 }
741 /*---------------------------------------------------------------------------*/
742 static int
743 cca(void)
744 {
745  bool_t is_channel_busy = bJPT_CCA(current_channel,
746  E_JPT_CCA_MODE_CARRIER_OR_ENERGY,
747  cca_thershold);
748  return is_channel_busy == FALSE;
749 }
750 /*---------------------------------------------------------------------------*/
751 static void
752 radio_interrupt_handler(uint32 mac_event)
753 {
754  uint32_t rx_status;
755  uint8_t overflow = 0;
756  int get_index;
757  int put_index;
758 #if !MICROMAC_RADIO_MAC
759  int packet_for_me = 0;
760 #endif
761 
762  if(mac_event & E_MMAC_INT_TX_COMPLETE) {
763  /* Transmission attempt has finished */
764  tx_in_progress = 0;
765  } else if(mac_event & E_MMAC_INT_RX_COMPLETE) {
766  rx_status = u32MMAC_GetRxErrors();
767  /* If rx is successful */
768  if(rx_status == 0) {
769  /* Save SFD timestamp */
770  last_packet_timestamp = get_packet_timestamp();
771 
772  if(!poll_mode && (mac_event & E_MMAC_INT_RX_COMPLETE)) {
773 #if MICROMAC_RADIO_MAC
774  /* read and cache RSSI and LQI values */
775  read_last_rssi();
776  /* Put received frame in queue */
777  ringbufindex_put(&input_ringbuf);
778 
779  if((get_index = ringbufindex_peek_get(&input_ringbuf)) != -1) {
780  input_frame_buffer = &input_array[get_index];
781  }
782  process_poll(&micromac_radio_process);
783 
784  /* get pointer to next input slot */
785  put_index = ringbufindex_peek_put(&input_ringbuf);
786  /* is there space? */
787  if(put_index != -1) {
788  /* move rx_frame_buffer to next empty slot */
789  rx_frame_buffer = &input_array[put_index];
790  } else {
791  overflow = 1;
792  rx_frame_buffer = NULL;
793  }
794 #else
795  if(rx_frame_buffer->u8PayloadLength > CHECKSUM_LEN) {
796  if(frame_filtering) {
797  /* Check RX address */
798  packet_for_me = is_packet_for_us(rx_frame_buffer->uPayload.au8Byte, rx_frame_buffer->u8PayloadLength - CHECKSUM_LEN, 1);
799  } else if(!frame_filtering) {
800  packet_for_me = 1;
801  }
802  }
803  if(!packet_for_me) {
804  /* Prevent reading */
805  rx_frame_buffer->u8PayloadLength = 0;
806  } else {
807  /* read and cache RSSI and LQI values */
808  read_last_rssi();
809  /* Put received frame in queue */
810  ringbufindex_put(&input_ringbuf);
811 
812  if((get_index = ringbufindex_peek_get(&input_ringbuf)) != -1) {
813  input_frame_buffer = &input_array[get_index];
814  }
815  process_poll(&micromac_radio_process);
816 
817  /* get pointer to next input slot */
818  put_index = ringbufindex_peek_put(&input_ringbuf);
819  /* is there space? */
820  if(put_index != -1) {
821  /* move rx_frame_buffer to next empty slot */
822  rx_frame_buffer = &input_array[put_index];
823  } else {
824  overflow = 1;
825  rx_frame_buffer = NULL;
826  }
827  }
828 #endif
829  }
830  }
831  }
832  if(overflow) {
833  off();
834  } else if(MICROMAC_CONF_ALWAYS_ON
835  && (mac_event & (E_MMAC_INT_TX_COMPLETE | E_MMAC_INT_RX_COMPLETE))) {
836  on();
837  }
838 }
839 /*---------------------------------------------------------------------------*/
840 PROCESS_THREAD(micromac_radio_process, ev, data)
841 {
842  PROCESS_BEGIN();
843 
844  while(1) {
845  PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
846 
847  /* Pass received packets to upper layer */
848  int16_t read_index;
849  /* Loop on accessing (without removing) a pending input packet */
850  while((read_index = ringbufindex_peek_get(&input_ringbuf)) != -1) {
851  input_frame_buffer = &input_array[read_index];
852  /* Put packet into packetbuf for input callback */
853  packetbuf_clear();
854  int len = read(packetbuf_dataptr(), PACKETBUF_SIZE);
855  /* is packet valid? */
856  if(len > 0) {
858  NETSTACK_MAC.input();
859  }
860  /* Remove packet from ringbuf */
861  ringbufindex_get(&input_ringbuf);
862  /* Disable further read attempts */
863  input_frame_buffer->u8PayloadLength = 0;
864  }
865 
866  /* Are we recovering from overflow? */
867  if(rx_frame_buffer == NULL) {
868  /* get pointer to next input slot */
869  int put_index = ringbufindex_peek_put(&input_ringbuf);
870  /* is there space? */
871  if(put_index != -1) {
872  /* move rx_frame_buffer to next empty slot */
873  rx_frame_buffer = &input_array[put_index];
874  /* do we need to turn radio on? */
875  if(MICROMAC_CONF_ALWAYS_ON || missed_radio_on_request) {
876  missed_radio_on_request = 0;
877  on();
878  }
879  } else {
880  rx_frame_buffer = NULL;
881  }
882  }
883  }
884  PROCESS_END();
885 }
886 /*---------------------------------------------------------------------------*/
887 static void
888 set_frame_filtering(uint8_t enable)
889 {
890  frame_filtering = enable;
891 }
892 /*---------------------------------------------------------------------------*/
893 static void
894 set_autoack(uint8_t enable)
895 {
896  autoack_enabled = enable;
897 }
898 /*---------------------------------------------------------------------------*/
899 static void
900 set_poll_mode(uint8_t enable)
901 {
902  poll_mode = enable;
903  if(poll_mode) {
904  /* Disable interrupts */
905  vMMAC_EnableInterrupts(NULL);
906  vMMAC_ConfigureInterruptSources(0);
907  } else {
908  /* Initialize and enable interrupts */
909  /* TODO: enable E_MMAC_INT_RX_HEADER & filter out frames after header rx */
910  vMMAC_ConfigureInterruptSources(
911  E_MMAC_INT_RX_COMPLETE | E_MMAC_INT_TX_COMPLETE);
912  vMMAC_EnableInterrupts(&radio_interrupt_handler);
913  }
914 }
915 /* Enable or disable CCA before sending */
916 static void
917 set_send_on_cca(uint8_t enable)
918 {
919  send_on_cca = enable;
920 }
921 /*---------------------------------------------------------------------------*/
922 static radio_result_t
923 get_value(radio_param_t param, radio_value_t *value)
924 {
925  if(!value) {
926  return RADIO_RESULT_INVALID_VALUE;
927  }
928  switch(param) {
929  case RADIO_PARAM_POWER_MODE:
930  *value = listen_on || tx_in_progress ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF;
931  return RADIO_RESULT_OK;
932  case RADIO_PARAM_CHANNEL:
933  *value = get_channel();
934  return RADIO_RESULT_OK;
935  case RADIO_PARAM_RX_MODE:
936  *value = 0;
937  if(frame_filtering) {
939  }
940  if(autoack_enabled) {
941  *value |= RADIO_RX_MODE_AUTOACK;
942  }
943  if(poll_mode) {
944  *value |= RADIO_RX_MODE_POLL_MODE;
945  }
946  return RADIO_RESULT_OK;
947  case RADIO_PARAM_TX_MODE:
948  *value = 0;
949  if(send_on_cca) {
950  *value |= RADIO_TX_MODE_SEND_ON_CCA;
951  }
952  return RADIO_RESULT_OK;
953  case RADIO_PARAM_TXPOWER:
954  *value = get_txpower();
955  return RADIO_RESULT_OK;
956  case RADIO_PARAM_RSSI:
957  *value = get_rssi();
958  return RADIO_RESULT_OK;
959  case RADIO_PARAM_LAST_RSSI:
960  *value = radio_last_rssi;
961  return RADIO_RESULT_OK;
962  case RADIO_PARAM_CCA_THRESHOLD:
963  *value = cca_thershold;
964  return RADIO_RESULT_OK;
965  case RADIO_CONST_CHANNEL_MIN:
966  *value = 11;
967  return RADIO_RESULT_OK;
968  case RADIO_CONST_CHANNEL_MAX:
969  *value = 26;
970  return RADIO_RESULT_OK;
971  case RADIO_CONST_TXPOWER_MIN:
972  *value = OUTPUT_POWER_MIN;
973  return RADIO_RESULT_OK;
974  case RADIO_CONST_TXPOWER_MAX:
975  *value = OUTPUT_POWER_MAX;
976  return RADIO_RESULT_OK;
977  default:
978  return RADIO_RESULT_NOT_SUPPORTED;
979  }
980 }
981 /*---------------------------------------------------------------------------*/
982 static radio_result_t
983 set_value(radio_param_t param, radio_value_t value)
984 {
985  switch(param) {
986  case RADIO_PARAM_POWER_MODE:
987  if(value == RADIO_POWER_MODE_ON) {
988  on();
989  return RADIO_RESULT_OK;
990  }
991  if(value == RADIO_POWER_MODE_OFF) {
992  off();
993  return RADIO_RESULT_OK;
994  }
995  return RADIO_RESULT_INVALID_VALUE;
996  case RADIO_PARAM_CHANNEL:
997  if(value < 11 || value > 26) {
998  return RADIO_RESULT_INVALID_VALUE;
999  }
1000  set_channel(value);
1001  return RADIO_RESULT_OK;
1002  case RADIO_PARAM_RX_MODE:
1003  if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
1004  RADIO_RX_MODE_AUTOACK | RADIO_RX_MODE_POLL_MODE)) {
1005  return RADIO_RESULT_INVALID_VALUE;
1006  }
1007  set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
1008  set_autoack((value & RADIO_RX_MODE_AUTOACK) != 0);
1009  set_poll_mode((value & RADIO_RX_MODE_POLL_MODE) != 0);
1010  return RADIO_RESULT_OK;
1011  case RADIO_PARAM_TX_MODE:
1012  if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) {
1013  return RADIO_RESULT_INVALID_VALUE;
1014  }
1015  set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0);
1016  return RADIO_RESULT_OK;
1017  case RADIO_PARAM_TXPOWER:
1018  if(value < OUTPUT_POWER_MIN || value > OUTPUT_POWER_MAX) {
1019  return RADIO_RESULT_INVALID_VALUE;
1020  /* Find the closest higher PA_LEVEL for the desired output power */
1021  }
1022  set_txpower(value);
1023  return RADIO_RESULT_OK;
1024  case RADIO_PARAM_CCA_THRESHOLD:
1025  cca_thershold = value;
1026  return RADIO_RESULT_OK;
1027  default:
1028  return RADIO_RESULT_NOT_SUPPORTED;
1029  }
1030 }
1031 /*---------------------------------------------------------------------------*/
1032 static radio_result_t
1033 get_object(radio_param_t param, void *dest, size_t size)
1034 {
1035  if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) {
1036  if(size != sizeof(rtimer_clock_t) || !dest) {
1037  return RADIO_RESULT_INVALID_VALUE;
1038  }
1039  *(rtimer_clock_t *)dest = get_packet_timestamp();
1040 
1041  return RADIO_RESULT_OK;
1042  }
1043  return RADIO_RESULT_NOT_SUPPORTED;
1044 }
1045 /*---------------------------------------------------------------------------*/
1046 static radio_result_t
1047 set_object(radio_param_t param, const void *src, size_t size)
1048 {
1049  return RADIO_RESULT_NOT_SUPPORTED;
1050 }
1051 /*---------------------------------------------------------------------------*/
1052 const struct radio_driver micromac_radio_driver = {
1053  init,
1054  prepare,
1055  transmit,
1056  send,
1057  read,
1058  cca,
1061  on,
1062  off,
1063  get_value,
1064  set_value,
1065  get_object,
1066  set_object
1067 };
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
Definition: radio.h:290
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:252
#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:116
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:268
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:283
int(* pending_packet)(void)
Check if the radio driver has just received a packet.
Definition: radio.h:271
The structure of a device driver for a radio in Contiki.
Definition: radio.h:247
#define RTIMER_BUSYWAIT_UNTIL(cond, max_time)
Busy-wait until a condition for at most max_time.
Definition: rtimer.h:202
int payload_len
Length of payload field.
Definition: frame802154.h:210
static void set_channel(uint8_t channel)
Set the current operating channel.
Definition: cc2538-rf.c:166
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:160
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:258
int(* transmit)(unsigned short transmit_len)
Send the packet that has previously been prepared.
Definition: radio.h:255
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:277
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:214
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:226
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
Definition: linkaddr.c:69
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:261
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:280
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Definition: cc2538-rf.c:1035
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:296
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:274
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:156