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