Contiki-NG
Loading...
Searching...
No Matches
cc2538-rf.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
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 *
14 * 3. Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31/**
32 * \addtogroup cc2538-rf
33 * @{
34 *
35 * \file
36 * Implementation of the cc2538 RF driver
37 */
38#include "contiki.h"
39#include "dev/radio.h"
40#include "sys/clock.h"
41#include "sys/rtimer.h"
42#include "net/packetbuf.h"
43#include "net/linkaddr.h"
44#include "net/netstack.h"
45#include "net/mac/tsch/tsch.h"
46#include "sys/energest.h"
47#include "dev/cc2538-rf.h"
48#include "dev/rfcore.h"
49#include "dev/sys-ctrl.h"
50#include "dev/udma.h"
51#include "reg.h"
52#include "lib/iq-seeder.h"
53
54#include <string.h>
55/*---------------------------------------------------------------------------*/
56#define CHECKSUM_LEN 2
57
58/* uDMA channel control persistent flags */
59#define UDMA_TX_FLAGS (UDMA_CHCTL_ARBSIZE_128 | UDMA_CHCTL_XFERMODE_AUTO \
60 | UDMA_CHCTL_SRCSIZE_8 | UDMA_CHCTL_DSTSIZE_8 \
61 | UDMA_CHCTL_SRCINC_8 | UDMA_CHCTL_DSTINC_NONE)
62
63#define UDMA_RX_FLAGS (UDMA_CHCTL_ARBSIZE_128 | UDMA_CHCTL_XFERMODE_AUTO \
64 | UDMA_CHCTL_SRCSIZE_8 | UDMA_CHCTL_DSTSIZE_8 \
65 | UDMA_CHCTL_SRCINC_NONE | UDMA_CHCTL_DSTINC_8)
66
67/*
68 * uDMA transfer threshold. DMA will only be used to read an incoming frame
69 * if its size is above this threshold
70 */
71#define UDMA_RX_SIZE_THRESHOLD 3
72/*---------------------------------------------------------------------------*/
73/* Log configuration */
74#include "sys/log.h"
75#define LOG_MODULE "cc2538-rf"
76#define LOG_LEVEL LOG_LEVEL_NONE
77/*---------------------------------------------------------------------------*/
78/* Local RF Flags */
79#define RX_ACTIVE 0x80
80#define RF_MUST_RESET 0x40
81#define RF_ON 0x01
82
83/* Bit Masks for the last byte in the RX FIFO */
84#define CRC_BIT_MASK 0x80
85#define LQI_BIT_MASK 0x7F
86/* RSSI Offset */
87#define RSSI_OFFSET 73
88#define RSSI_INVALID -128
89
90/* 192 usec off -> on interval (RX Callib -> SFD Wait). We wait a bit more */
91#define ONOFF_TIME RTIMER_ARCH_SECOND / 3125
92/*---------------------------------------------------------------------------*/
93#ifdef CC2538_RF_CONF_AUTOACK
94#define CC2538_RF_AUTOACK CC2538_RF_CONF_AUTOACK
95#else
96#define CC2538_RF_AUTOACK 1
97#endif
98/*---------------------------------------------------------------------------
99 * MAC timer
100 *---------------------------------------------------------------------------*/
101/* Timer conversion */
102#define RADIO_TO_RTIMER(X) ((uint32_t)((uint64_t)(X) * RTIMER_ARCH_SECOND / SYS_CTRL_32MHZ))
103
104#define CLOCK_STABLE() do { \
105 while ( !(REG(SYS_CTRL_CLOCK_STA) & (SYS_CTRL_CLOCK_STA_XOSC_STB))); \
106 } while(0)
107/*---------------------------------------------------------------------------*/
108/* Are we currently in poll mode? Disabled by default */
109static uint8_t volatile poll_mode = 0;
110/* Do we perform a CCA before sending? Enabled by default. */
111static uint8_t send_on_cca = 1;
112static int8_t rssi;
113static uint8_t crc_corr;
114/*---------------------------------------------------------------------------*/
115static uint8_t rf_flags;
116static uint8_t rf_channel = IEEE802154_DEFAULT_CHANNEL;
117
118static int on(void);
119static int off(void);
120/*---------------------------------------------------------------------------*/
121/* TX Power dBm lookup table. Values from SmartRF Studio v1.16.0 */
122typedef struct output_config {
123 radio_value_t power;
124 uint8_t txpower_val;
125} output_config_t;
126
127static const output_config_t output_power[] = {
128 { 7, 0xFF },
129 { 5, 0xED },
130 { 3, 0xD5 },
131 { 1, 0xC5 },
132 { 0, 0xB6 },
133 { -1, 0xB0 },
134 { -3, 0xA1 },
135 { -5, 0x91 },
136 { -7, 0x88 },
137 { -9, 0x72 },
138 {-11, 0x62 },
139 {-13, 0x58 },
140 {-15, 0x42 },
141 {-24, 0x00 },
142};
143
144static radio_result_t get_value(radio_param_t param, radio_value_t *value);
145
146#define OUTPUT_CONFIG_COUNT (sizeof(output_power) / sizeof(output_config_t))
147
148/* Max and Min Output Power in dBm */
149#define OUTPUT_POWER_MIN (output_power[OUTPUT_CONFIG_COUNT - 1].power)
150#define OUTPUT_POWER_MAX (output_power[0].power)
151/*---------------------------------------------------------------------------*/
152/*
153 * The maximum number of bytes this driver can accept from the MAC layer for
154 * transmission or will deliver to the MAC layer after reception. Includes
155 * the MAC header and payload, but not the FCS.
156 */
157#define MAX_PAYLOAD_LEN (CC2538_RF_MAX_PACKET_LEN - CHECKSUM_LEN)
158/*---------------------------------------------------------------------------*/
159PROCESS(cc2538_rf_process, "cc2538 RF driver");
160/*---------------------------------------------------------------------------*/
161/**
162 * \brief Get the current operating channel
163 * \return Returns a value in [11,26] representing the current channel
164 */
165static uint8_t
167{
168 return rf_channel;
169}
170/*---------------------------------------------------------------------------*/
171/**
172 * \brief Set the current operating channel
173 * \param channel The desired channel as a value in [11,26]
174 */
175static void
176set_channel(uint8_t channel)
177{
178 uint8_t was_on = 0;
179
180 LOG_INFO("Set Channel\n");
181
182 /* Changes to FREQCTRL take effect after the next recalibration */
183
184 /* If we are off, save state, otherwise switch off and save state */
186 was_on = 1;
187 off();
188 }
189 REG(RFCORE_XREG_FREQCTRL) = CC2538_RF_CHANNEL_MIN +
190 (channel - CC2538_RF_CHANNEL_MIN) * CC2538_RF_CHANNEL_SPACING;
191
192 /* switch radio back on only if radio was on before - otherwise will turn on radio foor sleepy nodes */
193 if(was_on) {
194 on();
195 }
196
197 rf_channel = channel;
198}
199/*---------------------------------------------------------------------------*/
200static radio_value_t
201get_pan_id(void)
202{
203 return (radio_value_t)(REG(RFCORE_FFSM_PAN_ID1) << 8 | REG(RFCORE_FFSM_PAN_ID0));
204}
205/*---------------------------------------------------------------------------*/
206static void
207set_pan_id(uint16_t pan)
208{
209 REG(RFCORE_FFSM_PAN_ID0) = pan & 0xFF;
210 REG(RFCORE_FFSM_PAN_ID1) = pan >> 8;
211}
212/*---------------------------------------------------------------------------*/
213static radio_value_t
214get_short_addr(void)
215{
217}
218/*---------------------------------------------------------------------------*/
219static void
220set_short_addr(uint16_t addr)
221{
222 REG(RFCORE_FFSM_SHORT_ADDR0) = addr & 0xFF;
223 REG(RFCORE_FFSM_SHORT_ADDR1) = addr >> 8;
224}
225/*---------------------------------------------------------------------------*/
226/**
227 * \brief Reads the current signal strength (RSSI)
228 * \return The current RSSI in dBm
229 *
230 * This function reads the current RSSI on the currently configured
231 * channel.
232 */
233static radio_value_t
235{
236 int8_t rssi;
237 uint8_t was_off = 0;
238
239 /* If we are off, turn on first */
241 was_off = 1;
242 on();
243 }
244
245 /* Wait for a valid RSSI reading */
246 do {
247 rssi = REG(RFCORE_XREG_RSSI);
248 } while(rssi == RSSI_INVALID);
249 rssi -= RSSI_OFFSET;
250
251 /* If we were off, turn back off */
252 if(was_off) {
253 off();
254 }
255
256 return rssi;
257}
258/*---------------------------------------------------------------------------*/
259/**
260 * \brief Reads the current I/Q data of the received signal.
261 * \param value The least significant bit (LSB) of the I coordinate and the LSB
262 * of the Q coordinate are concatenated and stored here.
263 *
264 * If not done already, this function first enables the RX mode and waits for
265 * the RSSI_VALID bit to go high. Hence, this function should only be called
266 * at start up or by the MAC protocol to avoid conflicts.
267 */
268static void
270{
271 uint8_t was_off = 0;
272
273 /* If we are off, turn on first */
275 was_off = 1;
276 on();
277 }
278
279 /* Wait on RSSI_VALID */
281
282 /* Read I/Q LSBs */
283 *value = REG(RFCORE_XREG_RFRND)
285
286 /* If we were off, turn back off */
287 if(was_off) {
288 off();
289 }
290}
291/*---------------------------------------------------------------------------*/
292/* Returns the current CCA threshold in dBm */
293static radio_value_t
294get_cca_threshold(void)
295{
296 return (int8_t)(REG(RFCORE_XREG_CCACTRL0) & RFCORE_XREG_CCACTRL0_CCA_THR) - RSSI_OFFSET;
297}
298/*---------------------------------------------------------------------------*/
299/* Sets the CCA threshold in dBm */
300static void
301set_cca_threshold(radio_value_t value)
302{
303 REG(RFCORE_XREG_CCACTRL0) = (value & 0xFF) + RSSI_OFFSET;
304}
305/*---------------------------------------------------------------------------*/
306/* Returns the current TX power in dBm */
307static radio_value_t
308get_tx_power(void)
309{
310 int i;
311 uint8_t reg_val = REG(RFCORE_XREG_TXPOWER) & 0xFF;
312
313 /*
314 * Find the TXPOWER value in the lookup table
315 * If the value has been written with set_tx_power, we should be able to
316 * find the exact value. However, in case the register has been written in
317 * a different fashion, we return the immediately lower value of the lookup
318 */
319 for(i = 0; i < OUTPUT_CONFIG_COUNT; i++) {
320 if(reg_val >= output_power[i].txpower_val) {
321 return output_power[i].power;
322 }
323 }
324 return OUTPUT_POWER_MIN;
325}
326/*---------------------------------------------------------------------------*/
327/*
328 * Set TX power to 'at least' power dBm
329 * This works with a lookup table. If the value of 'power' does not exist in
330 * the lookup table, TXPOWER will be set to the immediately higher available
331 * value
332 */
333static void
334set_tx_power(radio_value_t power)
335{
336 int i;
337
338 for(i = OUTPUT_CONFIG_COUNT - 1; i >= 0; --i) {
339 if(power <= output_power[i].power) {
340 REG(RFCORE_XREG_TXPOWER) = output_power[i].txpower_val;
341 return;
342 }
343 }
344}
345/*---------------------------------------------------------------------------*/
346static void
347set_frame_filtering(uint8_t enable)
348{
349 if(enable) {
351 } else {
352 REG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN;
353 }
354}
355/*---------------------------------------------------------------------------*/
356static void
357set_shr_search(int enable)
358{
359 if(enable) {
360 REG(RFCORE_XREG_FRMCTRL0) &= ~RFCORE_XREG_FRMCTRL0_RX_MODE;
361 } else {
363 }
364}
365/*---------------------------------------------------------------------------*/
366static void
367mac_timer_init(void)
368{
369 CLOCK_STABLE();
373 REG(RFCORE_SFR_MTCTRL) &= ~RFCORE_SFR_MTCTRL_RUN;
378}
379/*---------------------------------------------------------------------------*/
380static void
381set_poll_mode(uint8_t enable)
382{
383 poll_mode = enable;
384
385 if(enable) {
386 mac_timer_init();
387 REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; /* mask out FIFOP interrupt source */
388 REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; /* clear pending FIFOP interrupt */
389 NVIC_DisableIRQ(RF_TX_RX_IRQn); /* disable RF interrupts */
390 } else {
391 REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; /* enable FIFOP interrupt source */
392 NVIC_EnableIRQ(RF_TX_RX_IRQn); /* enable RF interrupts */
393 }
394}
395/*---------------------------------------------------------------------------*/
396static void
397set_send_on_cca(uint8_t enable)
398{
399 send_on_cca = enable;
400}
401/*---------------------------------------------------------------------------*/
402static void
403set_auto_ack(uint8_t enable)
404{
405 if(enable) {
407 } else {
408 REG(RFCORE_XREG_FRMCTRL0) &= ~RFCORE_XREG_FRMCTRL0_AUTOACK;
409 }
410}
411/*---------------------------------------------------------------------------*/
412static uint32_t
413get_sfd_timestamp(void)
414{
415 uint64_t sfd, timer_val, buffer;
416
417 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000000;
419 timer_val = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0;
420 timer_val |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8);
421 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000000;
422 timer_val |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16);
423 timer_val |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24);
425 timer_val |= (buffer << 32);
426
427 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000001;
430 sfd |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8);
431 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000010;
432 sfd |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16);
433 sfd |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24);
435 sfd |= (buffer << 32);
436
437 return RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd);
438}
439/*---------------------------------------------------------------------------*/
440/* Enable or disable radio test mode emmiting modulated or unmodulated
441 * (carrier) signal. See User's Guide pages 719 and 741.
442 */
443static uint32_t prev_FRMCTRL0, prev_MDMTEST1;
444static uint8_t was_on;
445
446static void
447set_test_mode(uint8_t enable, uint8_t modulated)
448{
449 radio_value_t mode;
450 get_value(RADIO_PARAM_POWER_MODE, &mode);
451
452 if(enable) {
453 if(mode == RADIO_POWER_MODE_CARRIER_ON) {
454 return;
455 }
456 was_on = (mode == RADIO_POWER_MODE_ON);
457 off();
458 prev_FRMCTRL0 = REG(RFCORE_XREG_FRMCTRL0);
459 /* This constantly transmits random data */
460 REG(RFCORE_XREG_FRMCTRL0) = 0x00000042;
461 if(!modulated) {
462 prev_MDMTEST1 = REG(RFCORE_XREG_MDMTEST1);
463 /* ...adding this we send an unmodulated carrier instead */
464 REG(RFCORE_XREG_MDMTEST1) = 0x00000018;
465 }
467 } else {
468 if(mode != RADIO_POWER_MODE_CARRIER_ON) {
469 return;
470 }
472 REG(RFCORE_XREG_FRMCTRL0) = prev_FRMCTRL0;
473 if(!modulated) {
474 REG(RFCORE_XREG_MDMTEST1) = prev_MDMTEST1;
475 }
476 if(was_on) {
477 on();
478 }
479 }
480}
481/*---------------------------------------------------------------------------*/
482/* Netstack API radio driver functions */
483/*---------------------------------------------------------------------------*/
484static int
485channel_clear(void)
486{
487 int cca;
488 uint8_t was_off = 0;
489
490 LOG_INFO("CCA\n");
491
492 /* If we are off, turn on first */
494 was_off = 1;
495 on();
496 }
497
498 /* Wait on RSSI_VALID */
500
502 cca = CC2538_RF_CCA_CLEAR;
503 } else {
504 cca = CC2538_RF_CCA_BUSY;
505 }
506
507 /* If we were off, turn back off */
508 if(was_off) {
509 off();
510 }
511
512 return cca;
513}
514/*---------------------------------------------------------------------------*/
515static int
516on(void)
517{
518 LOG_INFO("On\n");
519
520 if(!(rf_flags & RX_ACTIVE)) {
523
524 rf_flags |= RX_ACTIVE;
525 }
526
527 ENERGEST_ON(ENERGEST_TYPE_LISTEN);
528 return 1;
529}
530/*---------------------------------------------------------------------------*/
531static int
532off(void)
533{
534 LOG_INFO("Off\n");
535
536 /* Wait for ongoing TX to complete (e.g. this could be an outgoing ACK) */
538
541 }
542
543 /* Don't turn off if we are off as this will trigger a Strobe Error */
544 if(REG(RFCORE_XREG_RXENABLE) != 0) {
546 }
547
548 rf_flags &= ~RX_ACTIVE;
549
550 ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
551 return 1;
552}
553/*---------------------------------------------------------------------------*/
554static int
555init(void)
556{
557 LOG_INFO("Init\n");
558
559 if(rf_flags & RF_ON) {
560 return 0;
561 }
562
563 /* Enable clock for the RF Core while Running, in Sleep and Deep Sleep */
564 REG(SYS_CTRL_RCGCRFC) = 1;
565 REG(SYS_CTRL_SCGCRFC) = 1;
566 REG(SYS_CTRL_DCGCRFC) = 1;
567
568 REG(RFCORE_XREG_CCACTRL0) = CC2538_RF_CCA_THRES;
569
570 /*
571 * Changes from default values
572 * See User Guide, section "Register Settings Update"
573 */
574 REG(RFCORE_XREG_TXFILTCFG) = 0x09; /** TX anti-aliasing filter bandwidth */
575 REG(RFCORE_XREG_AGCCTRL1) = 0x15; /** AGC target value */
576 REG(ANA_REGS_IVCTRL) = 0x0B; /** Bias currents */
577 REG(RFCORE_XREG_FSCAL1) = 0x01; /** Tune frequency calibration */
578
579 /*
580 * Defaults:
581 * Auto CRC; Append RSSI, CRC-OK and Corr. Val.; CRC calculation;
582 * RX and TX modes with FIFOs
583 */
585
586#if CC2538_RF_AUTOACK
588#endif
589
590 /* Disable source address matching and autopend */
591 REG(RFCORE_XREG_SRCMATCH) = 0;
592
593 /* MAX FIFOP threshold */
594 REG(RFCORE_XREG_FIFOPCTRL) = CC2538_RF_MAX_PACKET_LEN;
595
596 /* Set TX Power */
597 REG(RFCORE_XREG_TXPOWER) = CC2538_RF_TX_POWER;
598
599 set_channel(rf_channel);
600
601 /* Enable SHR search */
602 set_shr_search(RADIO_SHR_SEARCH_EN);
603
604 /* Acknowledge all RF Error interrupts */
606 NVIC_EnableIRQ(RF_ERR_IRQn);
607
609 /* Disable peripheral triggers for the channel */
611
612 /*
613 * Set the channel's DST. SRC can not be set yet since it will change for
614 * each transfer
615 */
617 }
618
620 /* Disable peripheral triggers for the channel */
622
623 /*
624 * Set the channel's SRC. DST can not be set yet since it will change for
625 * each transfer
626 */
628 }
629
630 set_poll_mode(poll_mode);
631
632#if CSPRNG_ENABLED
634#endif /* CSPRNG_ENABLED */
635
636 process_start(&cc2538_rf_process, NULL);
637
638 rf_flags |= RF_ON;
639
640 return 1;
641}
642/*---------------------------------------------------------------------------*/
643static int
644prepare(const void *payload, unsigned short payload_len)
645{
646 uint8_t i;
647
648 if(payload_len > MAX_PAYLOAD_LEN) {
649 return RADIO_TX_ERR;
650 }
651
652 LOG_INFO("Prepare 0x%02x bytes\n", payload_len + CHECKSUM_LEN);
653
654 /*
655 * When we transmit in very quick bursts, make sure previous transmission
656 * is not still in progress before re-writing to the TX FIFO
657 */
659
660 if((rf_flags & RX_ACTIVE) == 0) {
661 on();
662 }
663
665
666 LOG_INFO("data = ");
667 /* Send the phy length byte first */
668 REG(RFCORE_SFR_RFDATA) = payload_len + CHECKSUM_LEN;
669
671 LOG_INFO_("<uDMA payload>");
672
673 /* Set the transfer source's end address */
675 (uint32_t)(payload) + payload_len - 1);
676
677 /* Configure the control word */
679 UDMA_TX_FLAGS | udma_xfer_size(payload_len));
680
681 /* Enabled the RF TX uDMA channel */
683
684 /* Trigger the uDMA transfer */
686
687 /*
688 * No need to wait for this to end. Even if transmit() gets called
689 * immediately, the uDMA controller will stream the frame to the TX FIFO
690 * faster than transmit() can empty it
691 */
692 } else {
693 for(i = 0; i < payload_len; i++) {
694 REG(RFCORE_SFR_RFDATA) = ((unsigned char *)(payload))[i];
695 LOG_INFO_("%02x", ((unsigned char *)(payload))[i]);
696 }
697 }
698 LOG_INFO_("\n");
699
700 return 0;
701}
702/*---------------------------------------------------------------------------*/
703static int
704transmit(unsigned short transmit_len)
705{
706 uint8_t counter;
707 int ret = RADIO_TX_ERR;
708 rtimer_clock_t t0;
709 uint8_t was_off = 0;
710
711 LOG_INFO("Transmit\n");
712
713 if(transmit_len > MAX_PAYLOAD_LEN) {
714 return RADIO_TX_ERR;
715 }
716
717 if(!(rf_flags & RX_ACTIVE)) {
718 t0 = RTIMER_NOW();
719 on();
720 was_off = 1;
721 while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ONOFF_TIME));
722 }
723
724 if(send_on_cca) {
725 if(channel_clear() == CC2538_RF_CCA_BUSY) {
726 return RADIO_TX_COLLISION;
727 }
728 }
729
730 /*
731 * prepare() double checked that TX_ACTIVE is low. If SFD is high we are
732 * receiving. Abort transmission and bail out with RADIO_TX_COLLISION
733 */
735 return RADIO_TX_COLLISION;
736 }
737
738 /* Start the transmission */
739 ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT);
740
742
743 counter = 0;
745 && (counter++ < 3)) {
747 }
748
750 LOG_ERR("TX never active.\n");
752 ret = RADIO_TX_ERR;
753 } else {
754 /* Wait for the transmission to finish */
756 ret = RADIO_TX_OK;
757 }
758 ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN);
759
760 if(was_off) {
761 off();
762 }
763
764 return ret;
765}
766/*---------------------------------------------------------------------------*/
767static int
768send(const void *payload, unsigned short payload_len)
769{
770 prepare(payload, payload_len);
771 return transmit(payload_len);
772}
773/*---------------------------------------------------------------------------*/
774static int
775read(void *buf, unsigned short bufsize)
776{
777 uint8_t i;
778 uint8_t len;
779
780 LOG_INFO("Read\n");
781
783 return 0;
784 }
785
786 /* Check the length */
787 len = REG(RFCORE_SFR_RFDATA);
788
789 /* Check for validity */
790 if(len > CC2538_RF_MAX_PACKET_LEN) {
791 /* Oops, we must be out of sync. */
792 LOG_ERR("RF: bad sync\n");
793
795 return 0;
796 }
797
798 if(len <= CC2538_RF_MIN_PACKET_LEN) {
799 LOG_ERR("RF: too short\n");
800
802 return 0;
803 }
804
805 if(len - CHECKSUM_LEN > bufsize) {
806 LOG_ERR("RF: too long\n");
807
809 return 0;
810 }
811
812 /* If we reach here, chances are the FIFO is holding a valid frame */
813 LOG_INFO("read (0x%02x bytes) = ", len);
814 len -= CHECKSUM_LEN;
815
816 /* Don't bother with uDMA for short frames (e.g. ACKs) */
817 if(CC2538_RF_CONF_RX_USE_DMA && len > UDMA_RX_SIZE_THRESHOLD) {
818 LOG_INFO_("<uDMA payload>");
819
820 /* Set the transfer destination's end address */
822 (uint32_t)(buf) + len - 1);
823
824 /* Configure the control word */
826 UDMA_RX_FLAGS | udma_xfer_size(len));
827
828 /* Enabled the RF RX uDMA channel */
830
831 /* Trigger the uDMA transfer */
833
834 /* Wait for the transfer to complete. */
836 } else {
837 for(i = 0; i < len; ++i) {
838 ((unsigned char *)(buf))[i] = REG(RFCORE_SFR_RFDATA);
839 LOG_INFO_("%02x", ((unsigned char *)(buf))[i]);
840 }
841 }
842
843 /* Read the RSSI and CRC/Corr bytes */
844 rssi = ((int8_t)REG(RFCORE_SFR_RFDATA)) - RSSI_OFFSET;
845 crc_corr = REG(RFCORE_SFR_RFDATA);
846
847 LOG_INFO_("%02x%02x\n", (uint8_t)rssi, crc_corr);
848
849 /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */
850 if(crc_corr & CRC_BIT_MASK) {
851 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi);
852 packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK);
853 } else {
854 LOG_ERR("Bad CRC\n");
856 return 0;
857 }
858
859 if(!poll_mode) {
860 /* If FIFOP==1 and FIFO==0 then we had a FIFO overflow at some point. */
863 process_poll(&cc2538_rf_process);
864 } else {
866 }
867 }
868 }
869
870 return len;
871}
872/*---------------------------------------------------------------------------*/
873static int
874receiving_packet(void)
875{
876 LOG_INFO("Receiving\n");
877
878 /*
879 * SFD high while transmitting and receiving.
880 * TX_ACTIVE high only when transmitting
881 *
882 * FSMSTAT1 & (TX_ACTIVE | SFD) == SFD <=> receiving
883 */
884 return (REG(RFCORE_XREG_FSMSTAT1)
887}
888/*---------------------------------------------------------------------------*/
889static int
890pending_packet(void)
891{
892 LOG_INFO("Pending\n");
893
895}
896/*---------------------------------------------------------------------------*/
897static radio_result_t
898get_value(radio_param_t param, radio_value_t *value)
899{
900 if(!value) {
902 }
903
904 switch(param) {
907 *value = RADIO_POWER_MODE_OFF;
908 } else {
911 }
912 return RADIO_RESULT_OK;
914 *value = (radio_value_t)get_channel();
915 return RADIO_RESULT_OK;
917 *value = get_pan_id();
918 return RADIO_RESULT_OK;
920 *value = get_short_addr();
921 return RADIO_RESULT_OK;
923 *value = 0;
926 }
928 *value |= RADIO_RX_MODE_AUTOACK;
929 }
930 if(poll_mode) {
931 *value |= RADIO_RX_MODE_POLL_MODE;
932 }
933 return RADIO_RESULT_OK;
935 *value = 0;
936 if(send_on_cca) {
938 }
939 return RADIO_RESULT_OK;
941 *value = get_tx_power();
942 return RADIO_RESULT_OK;
944 *value = get_cca_threshold();
945 return RADIO_RESULT_OK;
946 case RADIO_PARAM_RSSI:
947 *value = get_rssi();
948 return RADIO_RESULT_OK;
950 *value = rssi;
951 return RADIO_RESULT_OK;
953 *value = crc_corr & LQI_BIT_MASK;
954 return RADIO_RESULT_OK;
956 get_iq_lsbs(value);
957 return RADIO_RESULT_OK;
959 *value = CC2538_RF_CHANNEL_MIN;
960 return RADIO_RESULT_OK;
962 *value = CC2538_RF_CHANNEL_MAX;
963 return RADIO_RESULT_OK;
965 *value = OUTPUT_POWER_MIN;
966 return RADIO_RESULT_OK;
968 *value = OUTPUT_POWER_MAX;
969 return RADIO_RESULT_OK;
971 *value = (radio_value_t)3; /* 1 len byte, 2 bytes CRC */
972 return RADIO_RESULT_OK;
974 *value = (radio_value_t)32; /* 250kbps data rate. One byte = 32us.*/
975 return RADIO_RESULT_OK;
977 *value = (radio_value_t)CC2538_DELAY_BEFORE_TX;
978 return RADIO_RESULT_OK;
980 *value = (radio_value_t)CC2538_DELAY_BEFORE_RX;
981 return RADIO_RESULT_OK;
983 *value = (radio_value_t)CC2538_DELAY_BEFORE_DETECT;
984 return RADIO_RESULT_OK;
985 case RADIO_CONST_MAX_PAYLOAD_LEN:
986 *value = (radio_value_t)MAX_PAYLOAD_LEN;
987 return RADIO_RESULT_OK;
988 default:
990 }
991}
992/*---------------------------------------------------------------------------*/
993static radio_result_t
994set_value(radio_param_t param, radio_value_t value)
995{
996 switch(param) {
998 if(value == RADIO_POWER_MODE_ON) {
999 on();
1000 return RADIO_RESULT_OK;
1001 }
1002 if(value == RADIO_POWER_MODE_OFF) {
1003 off();
1004 return RADIO_RESULT_OK;
1005 }
1006 if(value == RADIO_POWER_MODE_CARRIER_ON ||
1008 set_test_mode((value == RADIO_POWER_MODE_CARRIER_ON), 0);
1009 return RADIO_RESULT_OK;
1010 }
1013 if(value < CC2538_RF_CHANNEL_MIN ||
1014 value > CC2538_RF_CHANNEL_MAX) {
1016 }
1017 set_channel(value);
1018 return RADIO_RESULT_OK;
1019 case RADIO_PARAM_PAN_ID:
1020 set_pan_id(value & 0xffff);
1021 return RADIO_RESULT_OK;
1023 set_short_addr(value & 0xffff);
1024 return RADIO_RESULT_OK;
1026 if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
1030 }
1031
1032 set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
1033 set_auto_ack((value & RADIO_RX_MODE_AUTOACK) != 0);
1034 set_poll_mode((value & RADIO_RX_MODE_POLL_MODE) != 0);
1035
1036 return RADIO_RESULT_OK;
1038 if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) {
1040 }
1041 set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0);
1042 return RADIO_RESULT_OK;
1044 if(value < OUTPUT_POWER_MIN || value > OUTPUT_POWER_MAX) {
1046 }
1047
1048 set_tx_power(value);
1049 return RADIO_RESULT_OK;
1051 set_cca_threshold(value);
1052 return RADIO_RESULT_OK;
1054 if((value != RADIO_SHR_SEARCH_EN) && (value != RADIO_SHR_SEARCH_DIS)) {
1056 }
1057 set_shr_search(value);
1058 return RADIO_RESULT_OK;
1059 default:
1061 }
1062}
1063/*---------------------------------------------------------------------------*/
1064static radio_result_t
1065get_object(radio_param_t param, void *dest, size_t size)
1066{
1067 uint8_t *target;
1068 int i;
1069
1070 if(param == RADIO_PARAM_64BIT_ADDR) {
1071 if(size != 8 || !dest) {
1073 }
1074
1075 target = dest;
1076 for(i = 0; i < 8; i++) {
1077 target[i] = ((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[7 - i] & 0xFF;
1078 }
1079
1080 return RADIO_RESULT_OK;
1081 }
1082
1084 if(size != sizeof(rtimer_clock_t) || !dest) {
1086 }
1087 *(rtimer_clock_t *)dest = get_sfd_timestamp();
1088 return RADIO_RESULT_OK;
1089 }
1090
1091#if MAC_CONF_WITH_TSCH
1092 if(param == RADIO_CONST_TSCH_TIMING) {
1093 if(size != sizeof(uint16_t *) || !dest) {
1095 }
1096 /* Assigned value: a pointer to the TSCH timing in usec */
1097 *(const uint16_t **)dest = tsch_timeslot_timing_us_10000;
1098 return RADIO_RESULT_OK;
1099 }
1100#endif /* MAC_CONF_WITH_TSCH */
1101
1103}
1104/*---------------------------------------------------------------------------*/
1105static radio_result_t
1106set_object(radio_param_t param, const void *src, size_t size)
1107{
1108 int i;
1109
1110 if(param == RADIO_PARAM_64BIT_ADDR) {
1111 if(size != 8 || !src) {
1113 }
1114
1115 for(i = 0; i < 8; i++) {
1116 ((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] = ((uint8_t *)src)[7 - i];
1117 }
1118
1119 return RADIO_RESULT_OK;
1120 }
1122}
1123/*---------------------------------------------------------------------------*/
1125 init,
1126 prepare,
1127 transmit,
1128 send,
1129 read,
1133 on,
1134 off,
1135 get_value,
1136 set_value,
1137 get_object,
1139};
1140/*---------------------------------------------------------------------------*/
1141/**
1142 * \brief Implementation of the cc2538 RF driver process
1143 *
1144 * This process is started by init(). It simply sits there waiting for
1145 * an event. Upon frame reception, the RX ISR will poll this process.
1146 * Subsequently, the contiki core will generate an event which will
1147 * call this process so that the received frame can be picked up from
1148 * the RF RX FIFO
1149 *
1150 */
1151PROCESS_THREAD(cc2538_rf_process, ev, data)
1152{
1153 int len;
1154 PROCESS_BEGIN();
1155
1156 while(1) {
1157 PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
1158
1159 if(!poll_mode) {
1162
1163 if(len > 0) {
1165
1166 NETSTACK_MAC.input();
1167 }
1168 }
1169
1170 /* If we were polled due to an RF error, reset the transceiver */
1171 if(rf_flags & RF_MUST_RESET) {
1172 uint8_t was_on;
1173 rf_flags = 0;
1174
1175 /* save state so we know if to switch on again after re-init */
1177 was_on = 0;
1178 } else {
1179 was_on = 1;
1180 }
1181 off();
1182 init();
1183 if(was_on) {
1184 /* switch back on */
1185 on();
1186 }
1187 }
1188 }
1189
1190 PROCESS_END();
1191}
1192/*---------------------------------------------------------------------------*/
1193/**
1194 * \brief The cc2538 RF RX/TX ISR
1195 *
1196 * This is the interrupt service routine for all RF interrupts relating
1197 * to RX and TX. Error conditions are handled by cc2538_rf_err_isr().
1198 * Currently, we only acknowledge the FIFOP interrupt source.
1199 */
1200void
1202{
1203 if(!poll_mode) {
1204 process_poll(&cc2538_rf_process);
1205 }
1206
1207 /* We only acknowledge FIFOP so we can safely wipe out the entire SFR */
1208 REG(RFCORE_SFR_RFIRQF0) = 0;
1209}
1210/*---------------------------------------------------------------------------*/
1211/**
1212 * \brief The cc2538 RF Error ISR
1213 *
1214 * This is the interrupt service routine for all RF errors. We
1215 * acknowledge every error type and instead of trying to be smart and
1216 * act differently depending on error condition, we simply reset the
1217 * transceiver. RX FIFO overflow is an exception, we ignore this error
1218 * since read() handles it anyway.
1219 *
1220 * However, we don't want to reset within this ISR. If the error occurs
1221 * while we are reading a frame out of the FIFO, trashing the FIFO in
1222 * the middle of read(), would result in further errors (RX underflows).
1223 *
1224 * Instead, we set a flag and poll the driver process. The process will
1225 * reset the transceiver without any undesirable consequences.
1226 */
1227void
1229{
1230 LOG_ERR("Error 0x%08lx occurred\n", REG(RFCORE_SFR_RFERRF));
1231
1232 /* If the error is not an RX FIFO overflow, set a flag */
1234 rf_flags |= RF_MUST_RESET;
1235 }
1236
1237 REG(RFCORE_SFR_RFERRF) = 0;
1238
1239 process_poll(&cc2538_rf_process);
1240}
1241/*---------------------------------------------------------------------------*/
1242
1243/** @} */
Header file for the cc2538 RF driver.
Header file for the energy estimation mechanism.
@ RF_ERR_IRQn
RF Error Interrupt.
Definition cc2538_cm3.h:110
@ RF_TX_RX_IRQn
RF Tx/Rx Interrupt.
Definition cc2538_cm3.h:109
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
Definition clock.c:150
void cc2538_rf_rx_tx_isr(void)
The cc2538 RF RX/TX ISR.
Definition cc2538-rf.c:1201
static radio_value_t get_rssi(void)
Reads the current signal strength (RSSI)
Definition cc2538-rf.c:234
#define CC2538_RF_CSP_ISRFOFF()
Send a RF OFF command strobe to the CSP.
Definition cc2538-rf.h:107
#define CC2538_RF_CSP_ISRXON()
Send an RX ON command strobe to the CSP.
Definition cc2538-rf.h:95
static void get_iq_lsbs(radio_value_t *value)
Reads the current I/Q data of the received signal.
Definition cc2538-rf.c:269
#define CC2538_RF_CSP_ISFLUSHTX()
Flush the TX FIFO.
Definition cc2538-rf.h:120
static uint8_t get_channel()
Get the current operating channel.
Definition cc2538-rf.c:166
const struct radio_driver cc2538_rf_driver
The NETSTACK data structure for the cc2538 RF driver.
Definition cc2538-rf.c:1124
static void set_channel(uint8_t channel)
Set the current operating channel.
Definition cc2538-rf.c:176
#define CC2538_RF_CSP_ISFLUSHRX()
Flush the RX FIFO.
Definition cc2538-rf.h:113
#define CC2538_RF_CSP_ISTXON()
Send a TX ON command strobe to the CSP.
Definition cc2538-rf.h:101
void cc2538_rf_err_isr(void)
The cc2538 RF Error ISR.
Definition cc2538-rf.c:1228
static int init(void)
Definition cc2538-rf.c:555
#define RFCORE_FFSM_PAN_ID0
Local address information.
Definition rfcore-ffsm.h:62
#define RFCORE_XREG_FSMSTAT1_SFD
SFD was sent/received.
#define RFCORE_SFR_MTM1
MAC Timer MUX register 1.
Definition rfcore-sfr.h:51
#define RFCORE_SFR_MTMOVF2_MTMOVF2
Register[23:16].
Definition rfcore-sfr.h:117
#define RFCORE_XREG_CCACTRL0
CCA threshold.
Definition rfcore-xreg.h:66
#define RFCORE_SFR_MTMOVF1_MTMOVF1
Register[15:8].
Definition rfcore-sfr.h:123
#define RFCORE_SFR_MTCTRL_STATE
State of MAC Timer.
Definition rfcore-sfr.h:78
#define RFCORE_XREG_FRMCTRL0
Frame handling.
Definition rfcore-xreg.h:53
#define RFCORE_XREG_FSMSTAT1
Radio status register.
Definition rfcore-xreg.h:63
#define RFCORE_XREG_SRCMATCH
Source address matching.
Definition rfcore-xreg.h:46
#define RFCORE_XREG_RXENABLE_RXENMASK
Enables the receiver.
#define RFCORE_XREG_FRMFILT0
Frame filtering control.
Definition rfcore-xreg.h:44
#define RFCORE_SFR_MTM0_MTM0
Register[7:0].
Definition rfcore-sfr.h:115
#define RFCORE_XREG_FRMCTRL0_RX_MODE
Set RX modes.
#define RFCORE_XREG_RFERRM_RFERRM
RF error interrupt mask.
#define RFCORE_XREG_FSMSTAT0
Radio status register.
Definition rfcore-xreg.h:62
#define RFCORE_SFR_MTCTRL_SYNC
Timer start/stop timing.
Definition rfcore-sfr.h:79
#define RFCORE_XREG_RFERRM
RF error interrupt mask.
Definition rfcore-xreg.h:81
#define RFCORE_XREG_RFRND_QRND
Random bit from the Q channel.
#define RFCORE_XREG_TXPOWER
Controls the output power.
Definition rfcore-xreg.h:60
#define RFCORE_SFR_MTMSEL
MAC Timer multiplex select.
Definition rfcore-sfr.h:49
#define RFCORE_SFR_MTMOVF0_MTMOVF0
Register[7:0].
Definition rfcore-sfr.h:124
#define RFCORE_XREG_FRMCTRL0_AUTOACK
Transmit ACK frame enable.
#define RFCORE_XREG_RSSISTAT
RSSI valid status register.
Definition rfcore-xreg.h:69
#define RFCORE_SFR_MTMOVF2
MAC Timer MUX overflow 2.
Definition rfcore-sfr.h:52
#define RFCORE_SFR_MTCTRL_RUN
Timer start/stop.
Definition rfcore-sfr.h:80
#define RFCORE_XREG_RFRND_IRND
Random bit from the I channel.
#define RFCORE_SFR_MTM0
MAC Timer MUX register 0.
Definition rfcore-sfr.h:50
#define RFCORE_XREG_MDMTEST1
Test Register for Modem.
#define RFCORE_SFR_RFERRF_RXOVERF
RX FIFO overflowed.
Definition rfcore-sfr.h:140
#define RFCORE_XREG_FSMSTAT1_FIFOP
FIFOP status.
#define RFCORE_FFSM_EXT_ADDR0
Local address information.
Definition rfcore-ffsm.h:54
#define RFCORE_SFR_MTMOVF0
MAC Timer MUX overflow 0.
Definition rfcore-sfr.h:54
#define RFCORE_SFR_MTMOVF1
MAC Timer MUX overflow 1.
Definition rfcore-sfr.h:53
#define RFCORE_XREG_FSMSTAT1_TX_ACTIVE
Status signal - TX states.
#define RFCORE_XREG_RFIRQM0
RF interrupt masks.
Definition rfcore-xreg.h:79
#define RFCORE_XREG_FSMSTAT1_CCA
Clear channel assessment.
#define RFCORE_XREG_FRMCTRL0_AUTOCRC
Auto CRC generation / checking.
#define RFCORE_XREG_RSSI
RSSI status register.
Definition rfcore-xreg.h:68
#define RFCORE_SFR_MTCTRL_LATCH_MODE
OVF counter latch mode.
Definition rfcore-sfr.h:77
#define RFCORE_FFSM_PAN_ID1
Local address information.
Definition rfcore-ffsm.h:63
#define RFCORE_XREG_AGCCTRL1
AGC reference level.
Definition rfcore-xreg.h:93
#define RFCORE_FFSM_SHORT_ADDR1
Local address information.
Definition rfcore-ffsm.h:65
#define RFCORE_SFR_RFERRF
RF error interrupt flags.
Definition rfcore-sfr.h:61
#define RFCORE_XREG_FIFOPCTRL
FIFOP threshold.
Definition rfcore-xreg.h:64
#define RFCORE_SFR_RFDATA
TX/RX FIFO data.
Definition rfcore-sfr.h:60
#define RFCORE_SFR_MTM1_MTM1
Register[15:8].
Definition rfcore-sfr.h:116
#define RFCORE_XREG_FSMSTAT0_FSM_FFCTRL_STATE
FIFO and FFCTRL status.
#define RFCORE_XREG_FRMCTRL0_TX_MODE
Set test modes for TX.
#define RFCORE_XREG_RXENABLE
RX enabling.
Definition rfcore-xreg.h:55
#define RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN
Enables frame filtering.
#define RFCORE_FFSM_SHORT_ADDR0
Local address information.
Definition rfcore-ffsm.h:64
#define RFCORE_SFR_RFIRQF0
RF interrupt flags.
Definition rfcore-sfr.h:63
#define RFCORE_XREG_CCACTRL0_CCA_THR
Clear-channel-assessment.
#define RFCORE_XREG_FREQCTRL
Controls the RF frequency.
Definition rfcore-xreg.h:59
#define RFCORE_SFR_MTCTRL
MAC Timer control register.
Definition rfcore-sfr.h:46
#define RFCORE_XREG_FSMSTAT1_FIFO
FIFO status.
#define RFCORE_XREG_RSSISTAT_RSSI_VALID
RSSI value is valid.
#define RFCORE_XREG_TXFILTCFG
TX filter configuration.
#define RFCORE_XREG_RFIRQM0_FIFOP
RX FIFO exceeded threshold.
#define RFCORE_XREG_RFRND
Random data.
Definition rfcore-xreg.h:83
#define RFCORE_XREG_FSCAL1
Tune frequency calibration.
Definition rfcore-xreg.h:89
#define SYS_CTRL_DCGCRFC
RF Core clocks - PM0.
Definition sys-ctrl.h:95
#define SYS_CTRL_RCGCRFC
RF Core clocks - active mode.
Definition sys-ctrl.h:93
#define SYS_CTRL_SCGCRFC
RF Core clocks - Sleep mode.
Definition sys-ctrl.h:94
void udma_set_channel_dst(uint8_t channel, uint32_t dst_end)
Sets the channel's destination address.
Definition udma.c:88
void udma_channel_mask_set(uint8_t channel)
Disable peripheral triggers for a uDMA channel.
Definition udma.c:212
void udma_channel_enable(uint8_t channel)
Enables a uDMA channel.
Definition udma.c:128
uint8_t udma_channel_get_mode(uint8_t channel)
Retrieve the current mode for a channel.
Definition udma.c:243
void udma_channel_sw_request(uint8_t channel)
Generate a software trigger to start a transfer.
Definition udma.c:233
void udma_set_channel_control_word(uint8_t channel, uint32_t ctrl)
Configure the channel's control word.
Definition udma.c:98
#define udma_xfer_size(len)
Calculate the value of the xfersize field in the control structure.
Definition udma.h:703
void udma_set_channel_src(uint8_t channel, uint32_t src_end)
Sets the channels source address.
Definition udma.c:78
#define CC2538_RF_CONF_RX_USE_DMA
RF RX over DMA.
#define CC2538_RF_CONF_TX_USE_DMA
RF TX over DMA.
#define CC2538_RF_CONF_TX_DMA_CHAN
RF -> RAM DMA channel.
Definition cc2538-conf.h:95
#define CC2538_RF_CONF_RX_DMA_CHAN
RAM -> RF DMA channel.
Definition cc2538-conf.h:96
void iq_seeder_seed(void)
This function will feed the CSPRNG with a new seed.
Definition iq-seeder.c:142
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
Definition packetbuf.c:136
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
Definition packetbuf.c:143
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
Definition packetbuf.h:67
void packetbuf_clear(void)
Clear and reset the packetbuf.
Definition packetbuf.c:75
#define PROCESS(name, strname)
Declare a process.
Definition process.h:308
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition process.h:121
#define PROCESS_END()
Define the end of a process.
Definition process.h:132
void process_start(struct process *p, process_data_t data)
Start a process.
Definition process.c:121
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition process.h:274
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
Definition process.h:179
void process_poll(struct process *p)
Request a process to be polled.
Definition process.c:366
#define RADIO_RX_MODE_ADDRESS_FILTER
Enable address-based frame filtering.
Definition radio.h:451
#define RADIO_RX_MODE_POLL_MODE
Enable/disable/get the state of radio driver poll mode operation.
Definition radio.h:461
#define RADIO_TX_MODE_SEND_ON_CCA
Radio TX mode control / retrieval.
Definition radio.h:474
enum radio_result_e radio_result_t
Radio return values when setting or getting radio parameters.
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
#define RADIO_RX_MODE_AUTOACK
Enable automatic transmission of ACK frames.
Definition radio.h:456
@ RADIO_RESULT_NOT_SUPPORTED
The parameter is not supported.
Definition radio.h:481
@ RADIO_RESULT_INVALID_VALUE
The value argument was incorrect.
Definition radio.h:482
@ RADIO_RESULT_OK
The parameter was set/read successfully.
Definition radio.h:480
@ RADIO_PARAM_POWER_MODE
When getting the value of this parameter, the radio driver should indicate whether the radio is on or...
Definition radio.h:119
@ RADIO_CONST_PHY_OVERHEAD
The physical layer header (PHR) + MAC layer footer (MFR) overhead in bytes.
Definition radio.h:338
@ RADIO_PARAM_RSSI
Received signal strength indicator in dBm.
Definition radio.h:218
@ RADIO_PARAM_LAST_PACKET_TIMESTAMP
Last packet timestamp, of type rtimer_clock_t.
Definition radio.h:286
@ RADIO_PARAM_IQ_LSBS
The current I/Q LSBs.
Definition radio.h:234
@ RADIO_PARAM_LAST_RSSI
The RSSI value of the last received packet.
Definition radio.h:226
@ RADIO_CONST_BYTE_AIR_TIME
The air time of one byte in usec, e.g.
Definition radio.h:343
@ RADIO_PARAM_RX_MODE
Radio receiver mode determines if the radio has address filter (RADIO_RX_MODE_ADDRESS_FILTER) and aut...
Definition radio.h:173
@ RADIO_PARAM_CHANNEL
Channel used for radio communication.
Definition radio.h:134
@ RADIO_PARAM_SHR_SEARCH
For enabling and disabling the SHR search.
Definition radio.h:304
@ RADIO_PARAM_LAST_LINK_QUALITY
Link quality indicator of the last received packet.
Definition radio.h:244
@ RADIO_CONST_DELAY_BEFORE_RX
The delay in usec between turning on the radio and it being actually listening (able to hear a preamb...
Definition radio.h:355
@ RADIO_PARAM_TXPOWER
Transmission power in dBm.
Definition radio.h:192
@ RADIO_PARAM_64BIT_ADDR
Long (64 bits) address for the radio, which is used by the address filter.
Definition radio.h:263
@ RADIO_CONST_DELAY_BEFORE_TX
The delay in usec between a call to the radio API's transmit function and the end of SFD transmission...
Definition radio.h:349
@ RADIO_CONST_CHANNEL_MAX
The highest radio channel number.
Definition radio.h:316
@ RADIO_PARAM_PAN_ID
The personal area network identifier (PAN ID), which is used by the h/w frame filtering functionality...
Definition radio.h:150
@ RADIO_PARAM_CCA_THRESHOLD
Clear channel assessment threshold in dBm.
Definition radio.h:205
@ RADIO_CONST_TXPOWER_MIN
The minimum transmission power in dBm.
Definition radio.h:321
@ RADIO_CONST_CHANNEL_MIN
The lowest radio channel number.
Definition radio.h:311
@ RADIO_CONST_TXPOWER_MAX
The maximum transmission power in dBm.
Definition radio.h:326
@ RADIO_CONST_DELAY_BEFORE_DETECT
The delay in usec between the end of SFD reception for an incoming frame and the radio API starting t...
Definition radio.h:361
@ RADIO_PARAM_16BIT_ADDR
The short address (16 bits) for the radio, which is used by the h/w filter.
Definition radio.h:166
@ RADIO_PARAM_TX_MODE
Radio transmission mode determines if the radio has send on CCA (RADIO_TX_MODE_SEND_ON_CCA) enabled o...
Definition radio.h:180
@ RADIO_SHR_SEARCH_EN
Enable SHR search or SHR search is enabled.
Definition radio.h:419
@ RADIO_SHR_SEARCH_DIS
Disable SHR search or SHR search is enabled.
Definition radio.h:418
@ RADIO_POWER_MODE_CARRIER_OFF
Radio powered on, but not emitting unmodulated carriers.
Definition radio.h:410
@ RADIO_POWER_MODE_OFF
Radio powered off and in the lowest possible power consumption state.
Definition radio.h:395
@ RADIO_POWER_MODE_ON
Radio powered on and able to receive frames.
Definition radio.h:400
@ RADIO_POWER_MODE_CARRIER_ON
Radio powered on and emitting unmodulated carriers.
Definition radio.h:405
@ RADIO_TX_COLLISION
TX failed due to a collision.
Definition radio.h:511
@ RADIO_TX_ERR
An error occurred during transmission.
Definition radio.h:506
@ RADIO_TX_OK
TX was successful and where an ACK was requested one was received.
Definition radio.h:498
#define RTIMER_NOW()
Get the current clock time.
Definition rtimer.h:187
const tsch_timeslot_timing_usec tsch_timeslot_timing_us_10000
TSCH timing attributes and description.
I/Q data-based seeder.
Header file for the link-layer address representation.
Header file for the logging system.
#define IEEE802154_DEFAULT_CHANNEL
The default channel for IEEE 802.15.4 networks.
Definition mac.h:52
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Packet buffer (packetbuf) management.
Header file for the radio API.
Header file with register manipulation macro definitions.
Top-level header file for cc2538 RF Core registers.
Header file for the real-time timer module.
void(* input)(void)
Callback for getting notified of incoming packet.
Definition mac.h:78
The structure of a Contiki-NG radio device driver.
Definition radio.h:534
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
Definition radio.h:770
int(* read)(void *buf, unsigned short buf_len)
Read a received packet into a buffer.
Definition radio.h:655
int(* prepare)(const void *payload, unsigned short payload_len)
Prepare the radio with a packet to be sent.
Definition radio.h:580
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
Definition radio.h:756
int(* off)(void)
Turn the radio off.
Definition radio.h:729
int(* send)(const void *payload, unsigned short payload_len)
Prepare & transmit a packet.
Definition radio.h:631
int(* receiving_packet)(void)
Check if the radio driver is currently receiving a packet.
Definition radio.h:684
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
Definition radio.h:787
int(* on)(void)
Turn the radio on.
Definition radio.h:711
int(* transmit)(unsigned short transmit_len)
Send the packet that has previously been prepared.
Definition radio.h:619
int(* pending_packet)(void)
Check if a packet has been received and is available in the radio driver's buffers.
Definition radio.h:697
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.
Definition radio.h:741
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:672
Header file for the cc2538 System Control driver.
Main API declarations for TSCH.
Header file with register, macro and function declarations for the cc2538 micro-DMA controller module...
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition uip-nd6.c:107