Contiki-NG
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
53#include <string.h>
54/*---------------------------------------------------------------------------*/
55#define CHECKSUM_LEN 2
56
57/* uDMA channel control persistent flags */
58#define UDMA_TX_FLAGS (UDMA_CHCTL_ARBSIZE_128 | UDMA_CHCTL_XFERMODE_AUTO \
59 | UDMA_CHCTL_SRCSIZE_8 | UDMA_CHCTL_DSTSIZE_8 \
60 | UDMA_CHCTL_SRCINC_8 | UDMA_CHCTL_DSTINC_NONE)
61
62#define UDMA_RX_FLAGS (UDMA_CHCTL_ARBSIZE_128 | UDMA_CHCTL_XFERMODE_AUTO \
63 | UDMA_CHCTL_SRCSIZE_8 | UDMA_CHCTL_DSTSIZE_8 \
64 | UDMA_CHCTL_SRCINC_NONE | UDMA_CHCTL_DSTINC_8)
65
66/*
67 * uDMA transfer threshold. DMA will only be used to read an incoming frame
68 * if its size is above this threshold
69 */
70#define UDMA_RX_SIZE_THRESHOLD 3
71/*---------------------------------------------------------------------------*/
72/* Log configuration */
73#include "sys/log.h"
74#define LOG_MODULE "cc2538-rf"
75#define LOG_LEVEL LOG_LEVEL_NONE
76/*---------------------------------------------------------------------------*/
77/* Local RF Flags */
78#define RX_ACTIVE 0x80
79#define RF_MUST_RESET 0x40
80#define RF_ON 0x01
81
82/* Bit Masks for the last byte in the RX FIFO */
83#define CRC_BIT_MASK 0x80
84#define LQI_BIT_MASK 0x7F
85/* RSSI Offset */
86#define RSSI_OFFSET 73
87#define RSSI_INVALID -128
88
89/* 192 usec off -> on interval (RX Callib -> SFD Wait). We wait a bit more */
90#define ONOFF_TIME RTIMER_ARCH_SECOND / 3125
91/*---------------------------------------------------------------------------*/
92#ifdef CC2538_RF_CONF_AUTOACK
93#define CC2538_RF_AUTOACK CC2538_RF_CONF_AUTOACK
94#else
95#define CC2538_RF_AUTOACK 1
96#endif
97/*---------------------------------------------------------------------------
98 * MAC timer
99 *---------------------------------------------------------------------------*/
100/* Timer conversion */
101#define RADIO_TO_RTIMER(X) ((uint32_t)((uint64_t)(X) * RTIMER_ARCH_SECOND / SYS_CTRL_32MHZ))
102
103#define CLOCK_STABLE() do { \
104 while ( !(REG(SYS_CTRL_CLOCK_STA) & (SYS_CTRL_CLOCK_STA_XOSC_STB))); \
105 } while(0)
106/*---------------------------------------------------------------------------*/
107/* Are we currently in poll mode? Disabled by default */
108static uint8_t volatile poll_mode = 0;
109/* Do we perform a CCA before sending? Enabled by default. */
110static uint8_t send_on_cca = 1;
111static int8_t rssi;
112static uint8_t crc_corr;
113/*---------------------------------------------------------------------------*/
114static uint8_t rf_flags;
115static uint8_t rf_channel = IEEE802154_DEFAULT_CHANNEL;
116
117static int on(void);
118static int off(void);
119/*---------------------------------------------------------------------------*/
120/* TX Power dBm lookup table. Values from SmartRF Studio v1.16.0 */
121typedef struct output_config {
122 radio_value_t power;
123 uint8_t txpower_val;
124} output_config_t;
125
126static const output_config_t output_power[] = {
127 { 7, 0xFF },
128 { 5, 0xED },
129 { 3, 0xD5 },
130 { 1, 0xC5 },
131 { 0, 0xB6 },
132 { -1, 0xB0 },
133 { -3, 0xA1 },
134 { -5, 0x91 },
135 { -7, 0x88 },
136 { -9, 0x72 },
137 {-11, 0x62 },
138 {-13, 0x58 },
139 {-15, 0x42 },
140 {-24, 0x00 },
141};
142
143static radio_result_t get_value(radio_param_t param, radio_value_t *value);
144
145#define OUTPUT_CONFIG_COUNT (sizeof(output_power) / sizeof(output_config_t))
146
147/* Max and Min Output Power in dBm */
148#define OUTPUT_POWER_MIN (output_power[OUTPUT_CONFIG_COUNT - 1].power)
149#define OUTPUT_POWER_MAX (output_power[0].power)
150/*---------------------------------------------------------------------------*/
151/*
152 * The maximum number of bytes this driver can accept from the MAC layer for
153 * transmission or will deliver to the MAC layer after reception. Includes
154 * the MAC header and payload, but not the FCS.
155 */
156#define MAX_PAYLOAD_LEN (CC2538_RF_MAX_PACKET_LEN - CHECKSUM_LEN)
157/*---------------------------------------------------------------------------*/
158PROCESS(cc2538_rf_process, "cc2538 RF driver");
159/*---------------------------------------------------------------------------*/
160/**
161 * \brief Get the current operating channel
162 * \return Returns a value in [11,26] representing the current channel
163 */
164static uint8_t
166{
167 return rf_channel;
168}
169/*---------------------------------------------------------------------------*/
170/**
171 * \brief Set the current operating channel
172 * \param channel The desired channel as a value in [11,26]
173 */
174static void
175set_channel(uint8_t channel)
176{
177 uint8_t was_on = 0;
178
179 LOG_INFO("Set Channel\n");
180
181 /* Changes to FREQCTRL take effect after the next recalibration */
182
183 /* If we are off, save state, otherwise switch off and save state */
185 was_on = 1;
186 off();
187 }
188 REG(RFCORE_XREG_FREQCTRL) = CC2538_RF_CHANNEL_MIN +
189 (channel - CC2538_RF_CHANNEL_MIN) * CC2538_RF_CHANNEL_SPACING;
190
191 /* switch radio back on only if radio was on before - otherwise will turn on radio foor sleepy nodes */
192 if(was_on) {
193 on();
194 }
195
196 rf_channel = channel;
197}
198/*---------------------------------------------------------------------------*/
199static radio_value_t
200get_pan_id(void)
201{
202 return (radio_value_t)(REG(RFCORE_FFSM_PAN_ID1) << 8 | REG(RFCORE_FFSM_PAN_ID0));
203}
204/*---------------------------------------------------------------------------*/
205static void
206set_pan_id(uint16_t pan)
207{
208 REG(RFCORE_FFSM_PAN_ID0) = pan & 0xFF;
209 REG(RFCORE_FFSM_PAN_ID1) = pan >> 8;
210}
211/*---------------------------------------------------------------------------*/
212static radio_value_t
213get_short_addr(void)
214{
216}
217/*---------------------------------------------------------------------------*/
218static void
219set_short_addr(uint16_t addr)
220{
221 REG(RFCORE_FFSM_SHORT_ADDR0) = addr & 0xFF;
222 REG(RFCORE_FFSM_SHORT_ADDR1) = addr >> 8;
223}
224/*---------------------------------------------------------------------------*/
225/**
226 * \brief Reads the current signal strength (RSSI)
227 * \return The current RSSI in dBm
228 *
229 * This function reads the current RSSI on the currently configured
230 * channel.
231 */
232static radio_value_t
234{
235 int8_t rssi;
236 uint8_t was_off = 0;
237
238 /* If we are off, turn on first */
240 was_off = 1;
241 on();
242 }
243
244 /* Wait for a valid RSSI reading */
245 do {
246 rssi = REG(RFCORE_XREG_RSSI);
247 } while(rssi == RSSI_INVALID);
248 rssi -= RSSI_OFFSET;
249
250 /* If we were off, turn back off */
251 if(was_off) {
252 off();
253 }
254
255 return rssi;
256}
257/*---------------------------------------------------------------------------*/
258/* Returns the current CCA threshold in dBm */
259static radio_value_t
260get_cca_threshold(void)
261{
262 return (int8_t)(REG(RFCORE_XREG_CCACTRL0) & RFCORE_XREG_CCACTRL0_CCA_THR) - RSSI_OFFSET;
263}
264/*---------------------------------------------------------------------------*/
265/* Sets the CCA threshold in dBm */
266static void
267set_cca_threshold(radio_value_t value)
268{
269 REG(RFCORE_XREG_CCACTRL0) = (value & 0xFF) + RSSI_OFFSET;
270}
271/*---------------------------------------------------------------------------*/
272/* Returns the current TX power in dBm */
273static radio_value_t
274get_tx_power(void)
275{
276 int i;
277 uint8_t reg_val = REG(RFCORE_XREG_TXPOWER) & 0xFF;
278
279 /*
280 * Find the TXPOWER value in the lookup table
281 * If the value has been written with set_tx_power, we should be able to
282 * find the exact value. However, in case the register has been written in
283 * a different fashion, we return the immediately lower value of the lookup
284 */
285 for(i = 0; i < OUTPUT_CONFIG_COUNT; i++) {
286 if(reg_val >= output_power[i].txpower_val) {
287 return output_power[i].power;
288 }
289 }
290 return OUTPUT_POWER_MIN;
291}
292/*---------------------------------------------------------------------------*/
293/*
294 * Set TX power to 'at least' power dBm
295 * This works with a lookup table. If the value of 'power' does not exist in
296 * the lookup table, TXPOWER will be set to the immediately higher available
297 * value
298 */
299static void
300set_tx_power(radio_value_t power)
301{
302 int i;
303
304 for(i = OUTPUT_CONFIG_COUNT - 1; i >= 0; --i) {
305 if(power <= output_power[i].power) {
306 REG(RFCORE_XREG_TXPOWER) = output_power[i].txpower_val;
307 return;
308 }
309 }
310}
311/*---------------------------------------------------------------------------*/
312static void
313set_frame_filtering(uint8_t enable)
314{
315 if(enable) {
317 } else {
318 REG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN;
319 }
320}
321/*---------------------------------------------------------------------------*/
322static void
323set_shr_search(int enable)
324{
325 if(enable) {
326 REG(RFCORE_XREG_FRMCTRL0) &= ~RFCORE_XREG_FRMCTRL0_RX_MODE;
327 } else {
329 }
330}
331/*---------------------------------------------------------------------------*/
332static void
333mac_timer_init(void)
334{
335 CLOCK_STABLE();
339 REG(RFCORE_SFR_MTCTRL) &= ~RFCORE_SFR_MTCTRL_RUN;
344}
345/*---------------------------------------------------------------------------*/
346static void
347set_poll_mode(uint8_t enable)
348{
349 poll_mode = enable;
350
351 if(enable) {
352 mac_timer_init();
353 REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; /* mask out FIFOP interrupt source */
354 REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; /* clear pending FIFOP interrupt */
355 NVIC_DisableIRQ(RF_TX_RX_IRQn); /* disable RF interrupts */
356 } else {
357 REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; /* enable FIFOP interrupt source */
358 NVIC_EnableIRQ(RF_TX_RX_IRQn); /* enable RF interrupts */
359 }
360}
361/*---------------------------------------------------------------------------*/
362static void
363set_send_on_cca(uint8_t enable)
364{
365 send_on_cca = enable;
366}
367/*---------------------------------------------------------------------------*/
368static void
369set_auto_ack(uint8_t enable)
370{
371 if(enable) {
373 } else {
374 REG(RFCORE_XREG_FRMCTRL0) &= ~RFCORE_XREG_FRMCTRL0_AUTOACK;
375 }
376}
377/*---------------------------------------------------------------------------*/
378static uint32_t
379get_sfd_timestamp(void)
380{
381 uint64_t sfd, timer_val, buffer;
382
383 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000000;
385 timer_val = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0;
386 timer_val |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8);
387 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000000;
388 timer_val |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16);
389 timer_val |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24);
391 timer_val |= (buffer << 32);
392
393 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000001;
396 sfd |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8);
397 REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000010;
398 sfd |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16);
399 sfd |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24);
401 sfd |= (buffer << 32);
402
403 return RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd);
404}
405/*---------------------------------------------------------------------------*/
406/* Enable or disable radio test mode emmiting modulated or unmodulated
407 * (carrier) signal. See User's Guide pages 719 and 741.
408 */
409static uint32_t prev_FRMCTRL0, prev_MDMTEST1;
410static uint8_t was_on;
411
412static void
413set_test_mode(uint8_t enable, uint8_t modulated)
414{
415 radio_value_t mode;
416 get_value(RADIO_PARAM_POWER_MODE, &mode);
417
418 if(enable) {
419 if(mode == RADIO_POWER_MODE_CARRIER_ON) {
420 return;
421 }
422 was_on = (mode == RADIO_POWER_MODE_ON);
423 off();
424 prev_FRMCTRL0 = REG(RFCORE_XREG_FRMCTRL0);
425 /* This constantly transmits random data */
426 REG(RFCORE_XREG_FRMCTRL0) = 0x00000042;
427 if(!modulated) {
428 prev_MDMTEST1 = REG(RFCORE_XREG_MDMTEST1);
429 /* ...adding this we send an unmodulated carrier instead */
430 REG(RFCORE_XREG_MDMTEST1) = 0x00000018;
431 }
433 } else {
434 if(mode != RADIO_POWER_MODE_CARRIER_ON) {
435 return;
436 }
438 REG(RFCORE_XREG_FRMCTRL0) = prev_FRMCTRL0;
439 if(!modulated) {
440 REG(RFCORE_XREG_MDMTEST1) = prev_MDMTEST1;
441 }
442 if(was_on) {
443 on();
444 }
445 }
446}
447/*---------------------------------------------------------------------------*/
448/* Netstack API radio driver functions */
449/*---------------------------------------------------------------------------*/
450static int
451channel_clear(void)
452{
453 int cca;
454 uint8_t was_off = 0;
455
456 LOG_INFO("CCA\n");
457
458 /* If we are off, turn on first */
460 was_off = 1;
461 on();
462 }
463
464 /* Wait on RSSI_VALID */
466
468 cca = CC2538_RF_CCA_CLEAR;
469 } else {
470 cca = CC2538_RF_CCA_BUSY;
471 }
472
473 /* If we were off, turn back off */
474 if(was_off) {
475 off();
476 }
477
478 return cca;
479}
480/*---------------------------------------------------------------------------*/
481static int
482on(void)
483{
484 LOG_INFO("On\n");
485
486 if(!(rf_flags & RX_ACTIVE)) {
489
490 rf_flags |= RX_ACTIVE;
491 }
492
493 ENERGEST_ON(ENERGEST_TYPE_LISTEN);
494 return 1;
495}
496/*---------------------------------------------------------------------------*/
497static int
498off(void)
499{
500 LOG_INFO("Off\n");
501
502 /* Wait for ongoing TX to complete (e.g. this could be an outgoing ACK) */
504
507 }
508
509 /* Don't turn off if we are off as this will trigger a Strobe Error */
510 if(REG(RFCORE_XREG_RXENABLE) != 0) {
512 }
513
514 rf_flags &= ~RX_ACTIVE;
515
516 ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
517 return 1;
518}
519/*---------------------------------------------------------------------------*/
520static int
521init(void)
522{
523 LOG_INFO("Init\n");
524
525 if(rf_flags & RF_ON) {
526 return 0;
527 }
528
529 /* Enable clock for the RF Core while Running, in Sleep and Deep Sleep */
530 REG(SYS_CTRL_RCGCRFC) = 1;
531 REG(SYS_CTRL_SCGCRFC) = 1;
532 REG(SYS_CTRL_DCGCRFC) = 1;
533
534 REG(RFCORE_XREG_CCACTRL0) = CC2538_RF_CCA_THRES;
535
536 /*
537 * Changes from default values
538 * See User Guide, section "Register Settings Update"
539 */
540 REG(RFCORE_XREG_TXFILTCFG) = 0x09; /** TX anti-aliasing filter bandwidth */
541 REG(RFCORE_XREG_AGCCTRL1) = 0x15; /** AGC target value */
542 REG(ANA_REGS_IVCTRL) = 0x0B; /** Bias currents */
543 REG(RFCORE_XREG_FSCAL1) = 0x01; /** Tune frequency calibration */
544
545 /*
546 * Defaults:
547 * Auto CRC; Append RSSI, CRC-OK and Corr. Val.; CRC calculation;
548 * RX and TX modes with FIFOs
549 */
551
552#if CC2538_RF_AUTOACK
554#endif
555
556 /* Disable source address matching and autopend */
557 REG(RFCORE_XREG_SRCMATCH) = 0;
558
559 /* MAX FIFOP threshold */
560 REG(RFCORE_XREG_FIFOPCTRL) = CC2538_RF_MAX_PACKET_LEN;
561
562 /* Set TX Power */
563 REG(RFCORE_XREG_TXPOWER) = CC2538_RF_TX_POWER;
564
565 set_channel(rf_channel);
566
567 /* Enable SHR search */
568 set_shr_search(RADIO_SHR_SEARCH_EN);
569
570 /* Acknowledge all RF Error interrupts */
572 NVIC_EnableIRQ(RF_ERR_IRQn);
573
575 /* Disable peripheral triggers for the channel */
577
578 /*
579 * Set the channel's DST. SRC can not be set yet since it will change for
580 * each transfer
581 */
583 }
584
586 /* Disable peripheral triggers for the channel */
588
589 /*
590 * Set the channel's SRC. DST can not be set yet since it will change for
591 * each transfer
592 */
594 }
595
596 set_poll_mode(poll_mode);
597
598 process_start(&cc2538_rf_process, NULL);
599
600 rf_flags |= RF_ON;
601
602 return 1;
603}
604/*---------------------------------------------------------------------------*/
605static int
606prepare(const void *payload, unsigned short payload_len)
607{
608 uint8_t i;
609
610 if(payload_len > MAX_PAYLOAD_LEN) {
611 return RADIO_TX_ERR;
612 }
613
614 LOG_INFO("Prepare 0x%02x bytes\n", payload_len + CHECKSUM_LEN);
615
616 /*
617 * When we transmit in very quick bursts, make sure previous transmission
618 * is not still in progress before re-writing to the TX FIFO
619 */
621
622 if((rf_flags & RX_ACTIVE) == 0) {
623 on();
624 }
625
627
628 LOG_INFO("data = ");
629 /* Send the phy length byte first */
630 REG(RFCORE_SFR_RFDATA) = payload_len + CHECKSUM_LEN;
631
633 LOG_INFO_("<uDMA payload>");
634
635 /* Set the transfer source's end address */
637 (uint32_t)(payload) + payload_len - 1);
638
639 /* Configure the control word */
641 UDMA_TX_FLAGS | udma_xfer_size(payload_len));
642
643 /* Enabled the RF TX uDMA channel */
645
646 /* Trigger the uDMA transfer */
648
649 /*
650 * No need to wait for this to end. Even if transmit() gets called
651 * immediately, the uDMA controller will stream the frame to the TX FIFO
652 * faster than transmit() can empty it
653 */
654 } else {
655 for(i = 0; i < payload_len; i++) {
656 REG(RFCORE_SFR_RFDATA) = ((unsigned char *)(payload))[i];
657 LOG_INFO_("%02x", ((unsigned char *)(payload))[i]);
658 }
659 }
660 LOG_INFO_("\n");
661
662 return 0;
663}
664/*---------------------------------------------------------------------------*/
665static int
666transmit(unsigned short transmit_len)
667{
668 uint8_t counter;
669 int ret = RADIO_TX_ERR;
670 rtimer_clock_t t0;
671 uint8_t was_off = 0;
672
673 LOG_INFO("Transmit\n");
674
675 if(transmit_len > MAX_PAYLOAD_LEN) {
676 return RADIO_TX_ERR;
677 }
678
679 if(!(rf_flags & RX_ACTIVE)) {
680 t0 = RTIMER_NOW();
681 on();
682 was_off = 1;
683 while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ONOFF_TIME));
684 }
685
686 if(send_on_cca) {
687 if(channel_clear() == CC2538_RF_CCA_BUSY) {
688 return RADIO_TX_COLLISION;
689 }
690 }
691
692 /*
693 * prepare() double checked that TX_ACTIVE is low. If SFD is high we are
694 * receiving. Abort transmission and bail out with RADIO_TX_COLLISION
695 */
697 return RADIO_TX_COLLISION;
698 }
699
700 /* Start the transmission */
701 ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT);
702
704
705 counter = 0;
707 && (counter++ < 3)) {
709 }
710
712 LOG_ERR("TX never active.\n");
714 ret = RADIO_TX_ERR;
715 } else {
716 /* Wait for the transmission to finish */
718 ret = RADIO_TX_OK;
719 }
720 ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN);
721
722 if(was_off) {
723 off();
724 }
725
726 return ret;
727}
728/*---------------------------------------------------------------------------*/
729static int
730send(const void *payload, unsigned short payload_len)
731{
732 prepare(payload, payload_len);
733 return transmit(payload_len);
734}
735/*---------------------------------------------------------------------------*/
736static int
737read(void *buf, unsigned short bufsize)
738{
739 uint8_t i;
740 uint8_t len;
741
742 LOG_INFO("Read\n");
743
745 return 0;
746 }
747
748 /* Check the length */
749 len = REG(RFCORE_SFR_RFDATA);
750
751 /* Check for validity */
752 if(len > CC2538_RF_MAX_PACKET_LEN) {
753 /* Oops, we must be out of sync. */
754 LOG_ERR("RF: bad sync\n");
755
757 return 0;
758 }
759
760 if(len <= CC2538_RF_MIN_PACKET_LEN) {
761 LOG_ERR("RF: too short\n");
762
764 return 0;
765 }
766
767 if(len - CHECKSUM_LEN > bufsize) {
768 LOG_ERR("RF: too long\n");
769
771 return 0;
772 }
773
774 /* If we reach here, chances are the FIFO is holding a valid frame */
775 LOG_INFO("read (0x%02x bytes) = ", len);
776 len -= CHECKSUM_LEN;
777
778 /* Don't bother with uDMA for short frames (e.g. ACKs) */
779 if(CC2538_RF_CONF_RX_USE_DMA && len > UDMA_RX_SIZE_THRESHOLD) {
780 LOG_INFO_("<uDMA payload>");
781
782 /* Set the transfer destination's end address */
784 (uint32_t)(buf) + len - 1);
785
786 /* Configure the control word */
788 UDMA_RX_FLAGS | udma_xfer_size(len));
789
790 /* Enabled the RF RX uDMA channel */
792
793 /* Trigger the uDMA transfer */
795
796 /* Wait for the transfer to complete. */
798 } else {
799 for(i = 0; i < len; ++i) {
800 ((unsigned char *)(buf))[i] = REG(RFCORE_SFR_RFDATA);
801 LOG_INFO_("%02x", ((unsigned char *)(buf))[i]);
802 }
803 }
804
805 /* Read the RSSI and CRC/Corr bytes */
806 rssi = ((int8_t)REG(RFCORE_SFR_RFDATA)) - RSSI_OFFSET;
807 crc_corr = REG(RFCORE_SFR_RFDATA);
808
809 LOG_INFO_("%02x%02x\n", (uint8_t)rssi, crc_corr);
810
811 /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */
812 if(crc_corr & CRC_BIT_MASK) {
813 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi);
814 packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK);
815 } else {
816 LOG_ERR("Bad CRC\n");
818 return 0;
819 }
820
821 if(!poll_mode) {
822 /* If FIFOP==1 and FIFO==0 then we had a FIFO overflow at some point. */
825 process_poll(&cc2538_rf_process);
826 } else {
828 }
829 }
830 }
831
832 return len;
833}
834/*---------------------------------------------------------------------------*/
835static int
836receiving_packet(void)
837{
838 LOG_INFO("Receiving\n");
839
840 /*
841 * SFD high while transmitting and receiving.
842 * TX_ACTIVE high only when transmitting
843 *
844 * FSMSTAT1 & (TX_ACTIVE | SFD) == SFD <=> receiving
845 */
846 return (REG(RFCORE_XREG_FSMSTAT1)
849}
850/*---------------------------------------------------------------------------*/
851static int
852pending_packet(void)
853{
854 LOG_INFO("Pending\n");
855
857}
858/*---------------------------------------------------------------------------*/
859static radio_result_t
860get_value(radio_param_t param, radio_value_t *value)
861{
862 if(!value) {
864 }
865
866 switch(param) {
869 *value = RADIO_POWER_MODE_OFF;
870 } else {
873 }
874 return RADIO_RESULT_OK;
876 *value = (radio_value_t)get_channel();
877 return RADIO_RESULT_OK;
879 *value = get_pan_id();
880 return RADIO_RESULT_OK;
882 *value = get_short_addr();
883 return RADIO_RESULT_OK;
885 *value = 0;
888 }
890 *value |= RADIO_RX_MODE_AUTOACK;
891 }
892 if(poll_mode) {
893 *value |= RADIO_RX_MODE_POLL_MODE;
894 }
895 return RADIO_RESULT_OK;
897 *value = 0;
898 if(send_on_cca) {
900 }
901 return RADIO_RESULT_OK;
903 *value = get_tx_power();
904 return RADIO_RESULT_OK;
906 *value = get_cca_threshold();
907 return RADIO_RESULT_OK;
908 case RADIO_PARAM_RSSI:
909 *value = get_rssi();
910 return RADIO_RESULT_OK;
912 *value = rssi;
913 return RADIO_RESULT_OK;
915 *value = crc_corr & LQI_BIT_MASK;
916 return RADIO_RESULT_OK;
918 *value = CC2538_RF_CHANNEL_MIN;
919 return RADIO_RESULT_OK;
921 *value = CC2538_RF_CHANNEL_MAX;
922 return RADIO_RESULT_OK;
924 *value = OUTPUT_POWER_MIN;
925 return RADIO_RESULT_OK;
927 *value = OUTPUT_POWER_MAX;
928 return RADIO_RESULT_OK;
930 *value = (radio_value_t)3; /* 1 len byte, 2 bytes CRC */
931 return RADIO_RESULT_OK;
933 *value = (radio_value_t)32; /* 250kbps data rate. One byte = 32us.*/
934 return RADIO_RESULT_OK;
936 *value = (radio_value_t)CC2538_DELAY_BEFORE_TX;
937 return RADIO_RESULT_OK;
939 *value = (radio_value_t)CC2538_DELAY_BEFORE_RX;
940 return RADIO_RESULT_OK;
942 *value = (radio_value_t)CC2538_DELAY_BEFORE_DETECT;
943 return RADIO_RESULT_OK;
944 case RADIO_CONST_MAX_PAYLOAD_LEN:
945 *value = (radio_value_t)MAX_PAYLOAD_LEN;
946 return RADIO_RESULT_OK;
947 default:
949 }
950}
951/*---------------------------------------------------------------------------*/
952static radio_result_t
953set_value(radio_param_t param, radio_value_t value)
954{
955 switch(param) {
957 if(value == RADIO_POWER_MODE_ON) {
958 on();
959 return RADIO_RESULT_OK;
960 }
961 if(value == RADIO_POWER_MODE_OFF) {
962 off();
963 return RADIO_RESULT_OK;
964 }
965 if(value == RADIO_POWER_MODE_CARRIER_ON ||
967 set_test_mode((value == RADIO_POWER_MODE_CARRIER_ON), 0);
968 return RADIO_RESULT_OK;
969 }
972 if(value < CC2538_RF_CHANNEL_MIN ||
973 value > CC2538_RF_CHANNEL_MAX) {
975 }
976 set_channel(value);
977 return RADIO_RESULT_OK;
979 set_pan_id(value & 0xffff);
980 return RADIO_RESULT_OK;
982 set_short_addr(value & 0xffff);
983 return RADIO_RESULT_OK;
985 if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
989 }
990
991 set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
992 set_auto_ack((value & RADIO_RX_MODE_AUTOACK) != 0);
993 set_poll_mode((value & RADIO_RX_MODE_POLL_MODE) != 0);
994
995 return RADIO_RESULT_OK;
997 if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) {
999 }
1000 set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0);
1001 return RADIO_RESULT_OK;
1003 if(value < OUTPUT_POWER_MIN || value > OUTPUT_POWER_MAX) {
1005 }
1006
1007 set_tx_power(value);
1008 return RADIO_RESULT_OK;
1010 set_cca_threshold(value);
1011 return RADIO_RESULT_OK;
1013 if((value != RADIO_SHR_SEARCH_EN) && (value != RADIO_SHR_SEARCH_DIS)) {
1015 }
1016 set_shr_search(value);
1017 return RADIO_RESULT_OK;
1018 default:
1020 }
1021}
1022/*---------------------------------------------------------------------------*/
1023static radio_result_t
1024get_object(radio_param_t param, void *dest, size_t size)
1025{
1026 uint8_t *target;
1027 int i;
1028
1029 if(param == RADIO_PARAM_64BIT_ADDR) {
1030 if(size != 8 || !dest) {
1032 }
1033
1034 target = dest;
1035 for(i = 0; i < 8; i++) {
1036 target[i] = ((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[7 - i] & 0xFF;
1037 }
1038
1039 return RADIO_RESULT_OK;
1040 }
1041
1043 if(size != sizeof(rtimer_clock_t) || !dest) {
1045 }
1046 *(rtimer_clock_t *)dest = get_sfd_timestamp();
1047 return RADIO_RESULT_OK;
1048 }
1049
1050#if MAC_CONF_WITH_TSCH
1051 if(param == RADIO_CONST_TSCH_TIMING) {
1052 if(size != sizeof(uint16_t *) || !dest) {
1054 }
1055 /* Assigned value: a pointer to the TSCH timing in usec */
1056 *(const uint16_t **)dest = tsch_timeslot_timing_us_10000;
1057 return RADIO_RESULT_OK;
1058 }
1059#endif /* MAC_CONF_WITH_TSCH */
1060
1062}
1063/*---------------------------------------------------------------------------*/
1064static radio_result_t
1065set_object(radio_param_t param, const void *src, size_t size)
1066{
1067 int i;
1068
1069 if(param == RADIO_PARAM_64BIT_ADDR) {
1070 if(size != 8 || !src) {
1072 }
1073
1074 for(i = 0; i < 8; i++) {
1075 ((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] = ((uint8_t *)src)[7 - i];
1076 }
1077
1078 return RADIO_RESULT_OK;
1079 }
1081}
1082/*---------------------------------------------------------------------------*/
1084 init,
1085 prepare,
1086 transmit,
1087 send,
1088 read,
1092 on,
1093 off,
1094 get_value,
1095 set_value,
1096 get_object,
1098};
1099/*---------------------------------------------------------------------------*/
1100/**
1101 * \brief Implementation of the cc2538 RF driver process
1102 *
1103 * This process is started by init(). It simply sits there waiting for
1104 * an event. Upon frame reception, the RX ISR will poll this process.
1105 * Subsequently, the contiki core will generate an event which will
1106 * call this process so that the received frame can be picked up from
1107 * the RF RX FIFO
1108 *
1109 */
1110PROCESS_THREAD(cc2538_rf_process, ev, data)
1111{
1112 int len;
1113 PROCESS_BEGIN();
1114
1115 while(1) {
1116 /* Only if we are not in poll mode oder we are in poll mode and transceiver has to be reset */
1117 PROCESS_YIELD_UNTIL((!poll_mode || (poll_mode && (rf_flags & RF_MUST_RESET))) && (ev == PROCESS_EVENT_POLL));
1118
1119 if(!poll_mode) {
1122
1123 if(len > 0) {
1125
1126 NETSTACK_MAC.input();
1127 }
1128 }
1129
1130 /* If we were polled due to an RF error, reset the transceiver */
1131 if(rf_flags & RF_MUST_RESET) {
1132 uint8_t was_on;
1133 rf_flags = 0;
1134
1135 /* save state so we know if to switch on again after re-init */
1137 was_on = 0;
1138 } else {
1139 was_on = 1;
1140 }
1141 off();
1142 init();
1143 if(was_on) {
1144 /* switch back on */
1145 on();
1146 }
1147 }
1148 }
1149
1150 PROCESS_END();
1151}
1152/*---------------------------------------------------------------------------*/
1153/**
1154 * \brief The cc2538 RF RX/TX ISR
1155 *
1156 * This is the interrupt service routine for all RF interrupts relating
1157 * to RX and TX. Error conditions are handled by cc2538_rf_err_isr().
1158 * Currently, we only acknowledge the FIFOP interrupt source.
1159 */
1160void
1162{
1163 if(!poll_mode) {
1164 process_poll(&cc2538_rf_process);
1165 }
1166
1167 /* We only acknowledge FIFOP so we can safely wipe out the entire SFR */
1168 REG(RFCORE_SFR_RFIRQF0) = 0;
1169}
1170/*---------------------------------------------------------------------------*/
1171/**
1172 * \brief The cc2538 RF Error ISR
1173 *
1174 * This is the interrupt service routine for all RF errors. We
1175 * acknowledge every error type and instead of trying to be smart and
1176 * act differently depending on error condition, we simply reset the
1177 * transceiver. RX FIFO overflow is an exception, we ignore this error
1178 * since read() handles it anyway.
1179 *
1180 * However, we don't want to reset within this ISR. If the error occurs
1181 * while we are reading a frame out of the FIFO, trashing the FIFO in
1182 * the middle of read(), would result in further errors (RX underflows).
1183 *
1184 * Instead, we set a flag and poll the driver process. The process will
1185 * reset the transceiver without any undesirable consequences.
1186 */
1187void
1189{
1190 LOG_ERR("Error 0x%08lx occurred\n", REG(RFCORE_SFR_RFERRF));
1191
1192 /* If the error is not an RX FIFO overflow, set a flag */
1194 rf_flags |= RF_MUST_RESET;
1195 }
1196
1197 REG(RFCORE_SFR_RFERRF) = 0;
1198
1199 process_poll(&cc2538_rf_process);
1200}
1201/*---------------------------------------------------------------------------*/
1202
1203/** @} */
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:1161
static radio_value_t get_rssi(void)
Reads the current signal strength (RSSI)
Definition: cc2538-rf.c:233
#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
#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:165
const struct radio_driver cc2538_rf_driver
The NETSTACK data structure for the cc2538 RF driver.
Definition: cc2538-rf.c:1083
static void set_channel(uint8_t channel)
Set the current operating channel.
Definition: cc2538-rf.c:175
#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:1188
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Definition: cc2538-rf.c:1110
static int init(void)
Definition: cc2538-rf.c:521
#define RFCORE_FFSM_PAN_ID0
Local address information.
Definition: rfcore-ffsm.h:62
#define RFCORE_XREG_FSMSTAT1_SFD
SFD was sent/received.
Definition: rfcore-xreg.h:283
#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.
Definition: rfcore-xreg.h:228
#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.
Definition: rfcore-xreg.h:213
#define RFCORE_XREG_RFERRM_RFERRM
RF error interrupt mask.
Definition: rfcore-xreg.h:393
#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_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.
Definition: rfcore-xreg.h:211
#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_SFR_MTM0
MAC Timer MUX register 0.
Definition: rfcore-sfr.h:50
#define RFCORE_XREG_MDMTEST1
Test Register for Modem.
Definition: rfcore-xreg.h:100
#define RFCORE_SFR_RFERRF_RXOVERF
RX FIFO overflowed.
Definition: rfcore-sfr.h:140
#define RFCORE_XREG_FSMSTAT1_FIFOP
FIFOP status.
Definition: rfcore-xreg.h:282
#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.
Definition: rfcore-xreg.h:287
#define RFCORE_XREG_RFIRQM0
RF interrupt masks.
Definition: rfcore-xreg.h:79
#define RFCORE_XREG_FSMSTAT1_CCA
Clear channel assessment.
Definition: rfcore-xreg.h:284
#define RFCORE_XREG_FRMCTRL0_AUTOCRC
Auto CRC generation / checking.
Definition: rfcore-xreg.h:210
#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.
Definition: rfcore-xreg.h:275
#define RFCORE_XREG_FRMCTRL0_TX_MODE
Set test modes for TX.
Definition: rfcore-xreg.h:214
#define RFCORE_XREG_RXENABLE
RX enabling.
Definition: rfcore-xreg.h:55
#define RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN
Enables frame filtering.
Definition: rfcore-xreg.h:149
#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.
Definition: rfcore-xreg.h:307
#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.
Definition: rfcore-xreg.h:281
#define RFCORE_XREG_RSSISTAT_RSSI_VALID
RSSI value is valid.
Definition: rfcore-xreg.h:327
#define RFCORE_XREG_TXFILTCFG
TX filter configuration.
Definition: rfcore-xreg.h:141
#define RFCORE_XREG_RFIRQM0_FIFOP
RX FIFO exceeded threshold.
Definition: rfcore-xreg.h:373
#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:80
void udma_channel_mask_set(uint8_t channel)
Disable peripheral triggers for a uDMA channel.
Definition: udma.c:204
void udma_channel_enable(uint8_t channel)
Enables a uDMA channel.
Definition: udma.c:120
uint8_t udma_channel_get_mode(uint8_t channel)
Retrieve the current mode for a channel.
Definition: udma.c:235
void udma_channel_sw_request(uint8_t channel)
Generate a software trigger to start a transfer.
Definition: udma.c:225
void udma_set_channel_control_word(uint8_t channel, uint32_t ctrl)
Configure the channel's control word.
Definition: udma.c:90
#define udma_xfer_size(len)
Calculate the value of the xfersize field in the control structure.
Definition: udma.h:697
void udma_set_channel_src(uint8_t channel, uint32_t src_end)
Sets the channels source address.
Definition: udma.c:70
#define CC2538_RF_CONF_RX_USE_DMA
RF RX over DMA.
Definition: cc2538-conf.h:231
#define CC2538_RF_CONF_TX_USE_DMA
RF TX over DMA.
Definition: cc2538-conf.h:227
#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 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:307
#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
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
Definition: process.h:178
void process_poll(struct process *p)
Request a process to be polled.
Definition: process.c:371
#define RADIO_RX_MODE_ADDRESS_FILTER
Enable address-based frame filtering.
Definition: radio.h:443
#define RADIO_RX_MODE_POLL_MODE
Enable/disable/get the state of radio driver poll mode operation.
Definition: radio.h:453
#define RADIO_TX_MODE_SEND_ON_CCA
Radio TX mode control / retrieval.
Definition: radio.h:466
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:448
@ RADIO_RESULT_NOT_SUPPORTED
The parameter is not supported.
Definition: radio.h:473
@ RADIO_RESULT_INVALID_VALUE
The value argument was incorrect.
Definition: radio.h:474
@ RADIO_RESULT_OK
The parameter was set/read successfully.
Definition: radio.h:472
@ 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:330
@ 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:278
@ 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:335
@ 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:296
@ RADIO_PARAM_LAST_LINK_QUALITY
Link quality indicator of the last received packet.
Definition: radio.h:236
@ 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:347
@ 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:255
@ 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:341
@ RADIO_CONST_CHANNEL_MAX
The highest radio channel number.
Definition: radio.h:308
@ 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:313
@ RADIO_CONST_CHANNEL_MIN
The lowest radio channel number.
Definition: radio.h:303
@ RADIO_CONST_TXPOWER_MAX
The maximum transmission power in dBm.
Definition: radio.h:318
@ 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:353
@ 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:411
@ RADIO_SHR_SEARCH_DIS
Disable SHR search or SHR search is enabled.
Definition: radio.h:410
@ RADIO_POWER_MODE_CARRIER_OFF
Radio powered on, but not emitting unmodulated carriers.
Definition: radio.h:402
@ RADIO_POWER_MODE_OFF
Radio powered off and in the lowest possible power consumption state.
Definition: radio.h:387
@ RADIO_POWER_MODE_ON
Radio powered on and able to receive frames.
Definition: radio.h:392
@ RADIO_POWER_MODE_CARRIER_ON
Radio powered on and emitting unmodulated carriers.
Definition: radio.h:397
@ RADIO_TX_COLLISION
TX failed due to a collision.
Definition: radio.h:503
@ RADIO_TX_ERR
An error occurred during transmission.
Definition: radio.h:498
@ RADIO_TX_OK
TX was successful and where an ACK was requested one was received.
Definition: radio.h:490
#define RTIMER_NOW()
Get the current clock time.
Definition: rtimer.h:185
const tsch_timeslot_timing_usec tsch_timeslot_timing_us_10000
TSCH timing attributes and description.
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:72
The structure of a Contiki-NG radio device driver.
Definition: radio.h:526
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
Definition: radio.h:762
int(* read)(void *buf, unsigned short buf_len)
Read a received packet into a buffer.
Definition: radio.h:647
int(* prepare)(const void *payload, unsigned short payload_len)
Prepare the radio with a packet to be sent.
Definition: radio.h:572
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
Definition: radio.h:748
int(* off)(void)
Turn the radio off.
Definition: radio.h:721
int(* send)(const void *payload, unsigned short payload_len)
Prepare & transmit a packet.
Definition: radio.h:623
int(* receiving_packet)(void)
Check if the radio driver is currently receiving a packet.
Definition: radio.h:676
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
Definition: radio.h:779
int(* on)(void)
Turn the radio on.
Definition: radio.h:703
int(* transmit)(unsigned short transmit_len)
Send the packet that has previously been prepared.
Definition: radio.h:611
int(* pending_packet)(void)
Check if a packet has been received and is available in the radio driver's buffers.
Definition: radio.h:689
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.
Definition: radio.h:733
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:664
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