Contiki-NG
radio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32
33/**
34 * \file
35 * Header file for the radio API
36 * \author
37 * Adam Dunkels <adam@sics.se>
38 * Joakim Eriksson <joakime@sics.se>
39 * Niclas Finne <nfi@sics.se>
40 * Nicolas Tsiftes <nvt@sics.se>
41 */
42
43/**
44 * \addtogroup dev
45 * @{
46 */
47
48/**
49 * \defgroup radio Radio API
50 *
51 * The radio API module defines a set of functions that a radio device
52 * driver must implement.
53 *
54 * @{
55 */
56
57#ifndef RADIO_H_
58#define RADIO_H_
59
60#include <stddef.h>
61
62/**
63 * Each radio has a set of parameters that designate the current
64 * configuration and state of the radio. Parameters can either have
65 * values of type `radio_value_t`, or, when this type is insufficient, a
66 * generic object that is specified by a memory pointer and the size
67 * of the object.
68 *
69 * The `radio_value_t` type is set to an integer type that can hold most
70 * values used to configure the radio, and is therefore the most
71 * common type used for a parameter. Certain parameters require
72 * objects of a considerably larger size than `radio_value_t`, however,
73 * and in these cases the documentation below for the parameter will
74 * indicate this.
75 *
76 * All radio parameters that can vary during runtime are prefixed by
77 * `RADIO_PARAM_`, whereas those "parameters" that are guaranteed to
78 * remain immutable are prefixed by `RADIO_CONST_`. Each mutable
79 * parameter has a set of valid parameter values. When attempting to
80 * set a parameter to an invalid value, the radio will return
81 * `RADIO_RESULT_INVALID_VALUE`.
82 *
83 * Some radios support only a subset of the defined radio parameters.
84 * When trying to set or get such an unsupported parameter, the radio
85 * will return `RADIO_RESULT_NOT_SUPPORTED`.
86 */
87
88typedef int radio_value_t;
89typedef unsigned radio_param_t;
90
91/**
92 * \brief Radio parameters and constants
93 *
94 * The fields of this enum are expected to be used as the `param` argument
95 * of `get_value()`, `set_value()`, `get_object()` and `set_object()`.
96 *
97 * More specifically, fields prefixed with `RADIO_PARAM_` may be passed as an
98 * argument to any of those four functions. Exceptions are documented on a
99 * per-field basis. Fields prefixed with `RADIO_CONST_` will only be passed as
100 * an argument to `get_value()` and `get_object()`.
101 */
103
104 /**
105 * When getting the value of this parameter, the radio driver should
106 * indicate whether the radio is on or not.
107 *
108 * `RADIO_POWER_MODE_ON`: The radio is powered and ready to receive frames
109 * `RADIO_POWER_MODE_OFF`: The radio is powered off
110 *
111 * When setting the value of this parameter, the driver should put the radio
112 * part in the corresponding state.
113 * `RADIO_POWER_MODE_ON`: The radio should be powered on and ready to receive
114 * frames. This is equivalent to a call to `NETSTACK_RADIO.on()`.
115 * `RADIO_POWER_MODE_OFF`: The radio should be put in the lowest power
116 * consumption state available. This is equivalent to a call to
117 * `NETSTACK_RADIO.off()`.
118 */
120
121 /**
122 * Channel used for radio communication. The channel depends on the
123 * communication standard used by the radio. The values can range
124 * from `RADIO_CONST_CHANNEL_MIN` to `RADIO_CONST_CHANNEL_MAX`.
125 *
126 * When setting this parameter, the change should take effect immediately
127 * if the radio is in `RADIO_POWER_MODE_ON`. Otherwise the change should take
128 * effect the next time the radio turns on.
129 *
130 * When reading this parameter, the driver should return the currently
131 * configured channel if the radio is in `RADIO_POWER_MODE_ON`, or the last
132 * used channel is the radio is currently in `RADIO_POWER_MODE_OFF`.
133 */
135
136 /**
137 * The personal area network identifier (PAN ID), which is used by the h/w
138 * frame filtering functionality of some radios.
139 *
140 * Setting this param will typically require the radio driver to commit the
141 * PAN ID to some radio hardware register used for frame filtering.
142 *
143 * Getting this param will typically require the radio driver to return the
144 * value currently stored in the respective hardware register.
145 *
146 * If the hardware does not support frame filtering, there is no expectation
147 * to perform such filtering in the radio driver software. In the case of
148 * such radios, the driver can simply return `RADIO_RESULT_NOT_SUPPORTED`.
149 */
151
152 /**
153 * The short address (16 bits) for the radio, which is used by the h/w
154 * filter.
155 *
156 * Setting this param will typically require the radio driver to commit the
157 * value to some radio hardware register used for frame filtering.
158 *
159 * Getting this param will typically require the radio driver to return the
160 * value currently stored in the respective hardware register.
161 *
162 * If the hardware does not support frame filtering, there is no expectation
163 * to perform such filtering in the radio driver software. In the case of
164 * such radios, the driver can simply return `RADIO_RESULT_NOT_SUPPORTED`.
165 */
167
168 /**
169 * Radio receiver mode determines if the radio has address filter
170 * (`RADIO_RX_MODE_ADDRESS_FILTER`) and auto-ACK (`RADIO_RX_MODE_AUTOACK`)
171 * enabled. This parameter is set as a bit mask.
172 */
174
175 /**
176 * Radio transmission mode determines if the radio has send on CCA
177 * (`RADIO_TX_MODE_SEND_ON_CCA`) enabled or not. This parameter is set
178 * as a bit mask.
179 */
181
182 /**
183 * Transmission power in dBm. The values can range from
184 * `RADIO_CONST_TXPOWER_MIN` to `RADIO_CONST_TXPOWER_MAX`.
185 *
186 * Some radios restrict the available values to a subset of this
187 * range. If an unavailable TXPOWER value is requested to be set,
188 * the radio may select another TXPOWER close to the requested
189 * one. When getting the value of this parameter, the actual value
190 * used by the radio will be returned.
191 */
193
194 /**
195 * Clear channel assessment threshold in dBm. This threshold
196 * determines the minimum RSSI level at which the radio will assume
197 * that there is a packet in the air.
198 *
199 * The CCA threshold must be set to a level above the noise floor of
200 * the deployment. Otherwise mechanisms such as send-on-CCA and
201 * low-power-listening duty cycling protocols may not work
202 * correctly. Hence, the default value of the system may not be
203 * optimal for any given deployment.
204 */
206
207 /**
208 * Received signal strength indicator in dBm.
209 *
210 * When getting this parameter, the radio driver should return the current
211 * RSSI value as reported by the radio.
212 *
213 * This may require turning on the radio and requesting an RSSI sample.
214 *
215 * This parameter will only be passed as an argument to the `get_value()`
216 * function.
217 */
219
220 /**
221 * The RSSI value of the last received packet.
222 *
223 * This parameter will only be passed as an argument to the `get_value()`
224 * function.
225 */
227
228 /**
229 * The current I/Q LSBs.
230 *
231 * This parameter will only be passed as an argument to the `get_value()`
232 * function.
233 */
235
236 /**
237 * Link quality indicator of the last received packet.
238 *
239 * The value returned should be an unsigned number between 0x00 and 0xFF.
240 *
241 * This parameter will only be passed as an argument to the `get_value()`
242 * function.
243 */
245
246 /**
247 * Long (64 bits) address for the radio, which is used by the address filter.
248 * The address is specified in network byte order.
249 *
250 * Because this parameter value is larger than what fits in `radio_value_t`,
251 * it needs to be used with `get_object()`/`set_object()`.
252 *
253 * Setting this param will typically require the radio driver to commit the
254 * value to some radio hardware register used for frame filtering.
255 *
256 * Getting this param will typically require the radio driver to return the
257 * value currently stored in the respective hardware register.
258 *
259 * If the hardware does not support frame filtering, there is no expectation
260 * to perform such filtering in the radio driver software. In the case of
261 * such radios, the driver can simply return `RADIO_RESULT_NOT_SUPPORTED`.
262 */
264
265 /**
266 * Last packet timestamp, of type `rtimer_clock_t`.
267 *
268 * The timestamp corresponds to the point in time between the end of
269 * reception of the synchronisation header and the start of reception of the
270 * physical header (PHR).
271 *
272 * ```
273 * +---------------+-----+---------------+---------------+-----+
274 * | SHR | PHR | MHR | MAC Payload | MFR |
275 * +---------------+-----+---------------+---------------+-----+
276 * ^
277 * --- Timestamp --|
278 * ```
279 *
280 * Because this parameter value may be larger than what fits in `radio_value_t`,
281 * it needs to be used with `get_object()`/`set_object()`.
282 *
283 * This parameter will only be passed as an argument to the `get_object()`
284 * function.
285 */
287
288 /**
289 * For enabling and disabling the SHR search
290 *
291 * Setting this param to `RADIO_SHR_SEARCH_DIS` will disable SHR search.
292 * This means that when the radio is in receive mode it can be used to
293 * sample RSSI or to perform a clear channel assessment (CCA), but it will
294 * not receive frames.
295 *
296 * Setting this param to `RADIO_SHR_SEARCH_EN` will enable SHR search.
297 * This means that when the radio is in receive mode it will receive frames
298 * as normal.
299 *
300 * When setting this parameter, the change should take effect immediately
301 * if the radio is in `RADIO_POWER_MODE_ON`. Otherwise the change should take
302 * effect the next time the radio turns on.
303 */
305
306 /* Constants (read only) */
307
308 /**
309 * The lowest radio channel number
310 */
312
313 /**
314 * The highest radio channel number
315 */
317
318 /**
319 * The minimum transmission power in dBm
320 */
322
323 /**
324 * The maximum transmission power in dBm.
325 */
327
328 /* A pointer to TSCH timings in micro-seconds (tsch_timeslot_timing_usec *) */
329 RADIO_CONST_TSCH_TIMING,
330
331 /**
332 * The physical layer header (PHR) + MAC layer footer (MFR) overhead in
333 * bytes. This does _not_ include the synchronisation header (SHR).
334 *
335 * For example, on IEEE 802.15.4 at 2.4 GHz this will be 3 bytes: 1 byte for
336 * the frame length (PHR) + 2 bytes for the CRC (MFR)
337 */
339
340 /**
341 * The air time of one byte in usec, e.g. 32 for IEEE 802.15.4 at 2.4 GHz
342 */
344
345 /**
346 * The delay in usec between a call to the radio API's transmit function and
347 * the end of SFD transmission.
348 */
350
351 /**
352 * The delay in usec between turning on the radio and it being actually
353 * listening (able to hear a preamble)
354 */
356
357 /**
358 * The delay in usec between the end of SFD reception for an incoming frame
359 * and the radio API starting to return `receiving_packet() != 0`
360 */
362
363 /*
364 * The maximum payload the radio driver is able to handle.
365 *
366 * This includes the MAC header and MAC payload, but not any tail bytes
367 * added automatically by the radio. For example, in the typical case of
368 * .15.4 operation at 2.4GHz, this will be 125 bytes (127 bytes minus the
369 * FCS / CRC16).
370 *
371 * This is the maximum number of bytes that:
372 * - The MAC layer will ask the radio driver to transmit.
373 * This corresponds to the payload_len argument of the prepare() and
374 * send() and the transmit_len argument of transmit().
375 * - The radio driver will deliver to the MAC layer after frame reception.
376 * The buf_len of the read function will typically be greater than or
377 * equal to this value.
378 *
379 * Supporting this constant in the radio driver's get_value function is
380 * mandatory.
381 */
382 RADIO_CONST_MAX_PAYLOAD_LEN,
383};
384
385/**
386 * Radio power modes
387 *
388 * Used as the `value` argument of `get_value()` / `set_value()` when `param`
389 * is `RADIO_PARAM_POWER_MODE`.
390 */
392 /**
393 * Radio powered off and in the lowest possible power consumption state.
394 */
396
397 /**
398 * Radio powered on and able to receive frames.
399 */
401
402 /**
403 * Radio powered on and emitting unmodulated carriers.
404 */
406
407 /**
408 * Radio powered on, but not emitting unmodulated carriers.
409 */
412
413/**
414 * Possible values of the `get_value()` / `set_value()` `value` argument when
415 * the `param` argument is `RADIO_PARAM_SHR_SEARCH`.
416 */
418 RADIO_SHR_SEARCH_DIS = 0, /**< Disable SHR search or SHR search is enabled */
419 RADIO_SHR_SEARCH_EN = 1, /**< Enable SHR search or SHR search is enabled */
420};
421
422/*---------------------------------------------------------------------------*/
423/**
424 * \name Radio RX mode
425 *
426 * The radio reception mode controls address filtering and automatic
427 * transmission of acknowledgements in the radio (if such operations
428 * are supported by the radio). A single parameter is used to allow
429 * setting these features simultaneously as an atomic operation.
430 *
431 * These macros are meant to be used as the `value` argument of `get_value()`
432 * and `set_value()` when the `param` argument is `RADIO_PARAM_RX_MODE`.
433 *
434 * To enable both address filter and transmissions of automatic
435 * acknowledgments:
436 *
437 * ```
438 * NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE,
439 * RADIO_RX_MODE_ADDRESS_FILTER | RADIO_RX_MODE_AUTOACK);
440 * ```
441 * @{
442 */
443
444/**
445 * Enable address-based frame filtering.
446 *
447 * This will typically involve filtering based on PAN ID, Short address and
448 * long address. The filtering will consider the params RADIO_PARAM_PAN_ID,
449 * RADIO_PARAM_16BIT_ADDR and RADIO_PARAM_64BIT_ADDR respectively.
450 */
451#define RADIO_RX_MODE_ADDRESS_FILTER (1 << 0)
452
453/**
454 * Enable automatic transmission of ACK frames
455 */
456#define RADIO_RX_MODE_AUTOACK (1 << 1)
457
458/**
459 * Enable/disable/get the state of radio driver poll mode operation
460 */
461#define RADIO_RX_MODE_POLL_MODE (1 << 2)
462/** @} */
463/*---------------------------------------------------------------------------*/
464/**
465 * Radio TX mode control / retrieval
466 *
467 * The radio transmission mode controls whether transmissions should
468 * be done using clear channel assessment (if supported by the
469 * radio). If send-on-CCA is enabled, the radio's send function will
470 * wait for a radio-specific time window for the channel to become
471 * clear. If this does not happen, the send function will return
472 * `RADIO_TX_COLLISION`.
473 */
474#define RADIO_TX_MODE_SEND_ON_CCA (1 << 0)
475
476/**
477 * Radio return values when setting or getting radio parameters.
478 */
479typedef enum radio_result_e {
480 RADIO_RESULT_OK, /**< The parameter was set/read successfully */
481 RADIO_RESULT_NOT_SUPPORTED, /**< The parameter is not supported */
482 RADIO_RESULT_INVALID_VALUE, /**< The `value` argument was incorrect */
483
484 /**
485 * An error occurred when getting/setting the parameter, but the arguments
486 * were otherwise correct.
487 */
490
491/**
492 * Radio return values for the `transmit()` function.
493 */
495 /**
496 * TX was successful and where an ACK was requested one was received
497 */
499
500 /**
501 * An error occurred during transmission.
502 *
503 * This will typically signify that the transmitted frame was too long/short
504 * or that an error occurred at the radio driver level.
505 */
507
508 /**
509 * TX failed due to a collision
510 */
512
513 /**
514 * A unicast frame was sent OK but an ACK was _not_ received
515 */
517};
518/*---------------------------------------------------------------------------*/
519/**
520 * \name The Contiki-NG RF driver API
521 * @{
522 */
523/**
524 * The structure of a Contiki-NG radio device driver.
525 *
526 * Typically this data structure will represent the driver of an IEEE
527 * 802.15.4-compliant radio hardware.
528 *
529 * This data structure is the only required interface between the radio driver
530 * and the Contiki-NG network stack. All functions implemented in the radio
531 * driver, including those pointed to by the fields of this structure can
532 * be static.
533 */
535
536 /**
537 * Initialise the radio hardware.
538 *
539 * \retval 1 Initialisation successful
540 * \retval 0 Initialisation failed
541 *
542 * This function will be called once during boot. It shall perform one-off
543 * initialisation of the radio driver and hardware. Typical operations to
544 * implement as part of this function are initialisation of driver internal
545 * data structures and initial configuration of the radio hardware.
546 *
547 * This function is expected to apply configuration that persists across
548 * radio on/off cycles. Non-persistent changes should be implemented as part
549 * of `on()` instead.
550 *
551 * This function may, but is not strictly expected to put the radio in RX mode.
552 * The Contiki-NG boot sequence will put the radio in RX mode explicitly by
553 * a subsequent call to `on()`.
554 */
555 int (* init)(void);
556
557 /**
558 * Prepare the radio with a packet to be sent.
559 *
560 * \param payload A pointer to the location of the packet
561 * \param payload_len The length of the packet to be sent
562 * \retval 0 Packet copied successfully
563 * \retval 1 The packet could not be copied
564 *
565 * This function is expected to copy `payload_len` bytes from the location
566 * pointed to by `payload` to a location internal to the radio driver. In a
567 * typical scenario this will be a separate buffer in RAM, or the radio
568 * hardware's FIFO.
569 *
570 * `payload` will contain the MAC header (MHR) and MAC payload, but it
571 * will _not_ contain the physical header or the MAC footer (MFR).
572 *
573 * `payload_len` must be lower than or equal to the value retrieved when calling
574 * NETSTACK_RADIO.get_value(RADIO_CONST_MAX_PAYLOAD_LEN, ...)
575 *
576 * This function will return an error if the radio driver could not copy
577 * the packet to a location internal to the driver. Commonly this may happen
578 * if the latter is occupied by a previous packet which has yet to be sent.
579 */
580 int (* prepare)(const void *payload, unsigned short payload_len);
581
582 /**
583 * Send the packet that has previously been prepared.
584 *
585 * \param transmit_len The number of bytes to transmit
586 * \return This function will return one of the radio_tx_e enumerators
587 *
588 * The radio driver is not expected to remember the packet even if TX fails.
589 *
590 * `transmit_len` is equal the length of a previously prepared packet.
591 * Semantically it is identical to the `payload_len` argument of the
592 * `prepare()` function.
593 *
594 * A previously prepared packet shall contain the MAC header (MHR) and MAC
595 * payload, but it shall _not_ contain the physical header or the MAC footer
596 * (MFR). This function shall make sure that all necessary physical layer
597 * symbols are transmitted before the packet. In the case of .15.4 radios
598 * this includes the synch header (SHR), preamble and physical header (PHR).
599 * This function shall also make sure that the MFR is transmitted.
600 *
601 * Unless an error occurs, this function will wait until the packet has
602 * been fully transmitted.
603 *
604 * If `RADIO_PARAM_TX_MODE & RADIO_TX_MODE_SEND_ON_CCA` then this function
605 * should perform a CCA before transmission. If this CCA fails the function
606 * shall return `RADIO_TX_COLLISION`.
607 *
608 * This function may be called while the radio is powered-off, or while the
609 * radio is in RX mode. In the former case, it shall power on the radio and
610 * enter TX mode, ideally bypassing RX mode to reduce off->TX turnaround
611 * time. In the latter case, the function shall perform an RX-TX transition.
612 *
613 * This function may leave the radio in RX mode after transmission, but this
614 * is not necessary since the caller will explicitly request the correct
615 * radio state after this function returns: This will either be a request to
616 * revert to RX mode by a call to `on()`, or a request to power the radio
617 * down by a call to `off()`.
618 */
619 int (* transmit)(unsigned short transmit_len);
620
621 /**
622 * Prepare & transmit a packet.
623 *
624 * \param payload A pointer to the location of the packet
625 * \param payload_len The length of the packet to be sent
626 * \return This function will return one of the radio_tx_e enumerators
627 *
628 * This function shall behave exactly as a call to `prepare()`, immediately
629 * followed by a call to `transmit()`.
630 */
631 int (* send)(const void *payload, unsigned short payload_len);
632
633 /**
634 * Read a received packet into a buffer.
635 *
636 * \param buf A pointer the the buffer where the packet is to be copied
637 * \param buf_len The length of `buf`
638 * \return The number of bytes copied to `buf`
639 *
640 * If the radio has no correctly-received packets then this function will
641 * return 0.
642 *
643 * The buffer `buf` will be allocated by the caller.
644 *
645 * The radio driver is not expected to remember the packet after this call
646 * returns.
647 *
648 * This function is expected to be able to deliver a packet to the MAC layer
649 * even if the radio is powered down by a call to `off()`.
650 *
651 * When this function returns, `buf` will contain the MAC header (MHR) and
652 * MAC payload, but it will _not_ contain the physical header or the MAC
653 * footer (MFR).
654 */
655 int (* read)(void *buf, unsigned short buf_len);
656
657 /**
658 * Perform a Clear-Channel Assessment (CCA) to find out if there is
659 * a packet in the air or not.
660 *
661 * \retval 0 The channel is busy
662 * \retval 1 The channel is clear
663 *
664 * It is up to the radio driver's developer to decide how the CCA will be
665 * performed. Some radios have built-in, .15.4-compliant CCA operation; for
666 * those radios, it is up to the developer to decide which CCA mode to use.
667 *
668 * This function should not be called while the radio is not in RX mode. If
669 * this happens, this function shall return 0 and it will _not_ try to
670 * power-on the radio in order to perform a CCA.
671 */
672 int (* channel_clear)(void);
673
674 /**
675 * Check if the radio driver is currently receiving a packet.
676 *
677 * \retval 1 Reception of a packet is in progress
678 * \retval 0 No reception in progress
679 *
680 * If at the point of calling this function the radio is not in RX mode, for
681 * example as a result of a previous call to `off()`, this function will
682 * immediately return 0.
683 */
684 int (* receiving_packet)(void);
685
686 /**
687 * Check if a packet has been received and is available in the radio driver's
688 * buffers.
689 *
690 * \retval 1 One (or more) packet(s) is (are) available
691 * \retval 0 No packets available
692 *
693 * This function may be called while the radio is powered down by a previous
694 * call to `off()`. If that happens, the function shall not power on the
695 * radio.
696 */
697 int (* pending_packet)(void);
698
699 /**
700 * Turn the radio on.
701 *
702 * \retval 1 The call was successful and the radio is now in RX mode
703 * \retval 0 The call failed
704 *
705 * This function will put the radio in a state ready to receive packets. The
706 * function will power-on and configure the radio if necessary.
707 *
708 * This function shall not intentionally discard any previously received
709 * packets.
710 */
711 int (* on)(void);
712
713 /**
714 * Turn the radio off.
715 *
716 * \retval 1 Success
717 * \retval 0 Error
718 *
719 * This function shall put the radio to its lowest power consumption state.
720 *
721 * This function may be called immediately after the reception of a packet,
722 * but before this packet gets copied to the upper layers through a call to
723 * `read()`. If powering down the radio would result in the received packet
724 * getting lost, due to e.g. non-retention of the radio's hardware FIFO,
725 * then the radio driver shall make sure any received packets get copied to
726 * RAM first. This function shall not intentionally discard any previously
727 * received packets.
728 */
729 int (* off)(void);
730
731 /**
732 * Get a radio parameter value.
733 *
734 * \param param The parameter to retrieve: An enumerator of `radio_param_e`
735 * \param value A pointer to store the value of `param`
736 * \return An enumerator of `radio_result_t`
737 *
738 * This function shall copy the current value of parameter `param` to the
739 * location pointed to by `value`. The caller shall allocate `value`.
740 */
741 radio_result_t (* get_value)(radio_param_t param, radio_value_t *value);
742
743 /**
744 * Set a radio parameter value.
745 *
746 * \param param The parameter to set: An enumerator of `radio_param_e`
747 * \param value The new value for `param`
748 * \return An enumerator of `radio_result_t`
749 *
750 * This function shall set the value of a radio parameter.
751 *
752 * If this function is called while the radio is powered on, the requested
753 * change shall take effect immediately. If the radio is powered-off, the
754 * change shall take effect in the next power-on cycle.
755 */
756 radio_result_t (* set_value)(radio_param_t param, radio_value_t value);
757
758 /**
759 * Get a radio parameter object.
760 *
761 * \param param The parameter to retrieve: An enumerator of `radio_param_e`
762 * \param dest A pointer to a buffer where the value of `param` shall be stored
763 * \param size The size of the `dest` buffer
764 * \return An enumerator of `radio_result_t`
765 *
766 * The argument `dest` must point to a memory area of at least `size` bytes,
767 * and this memory area will contain the parameter object if the function
768 * succeeds. `dest` shall be allocated by the caller.
769 */
770 radio_result_t (* get_object)(radio_param_t param, void *dest, size_t size);
771
772 /**
773 * Set a radio parameter object.
774 *
775 * \param param The parameter to set: An enumerator of `radio_param_e`
776 * \param src A pointer to a buffer where the new value is stored
777 * \param size The size of the `src` buffer
778 * \return An enumerator of `radio_result_t`
779 *
780 * The memory area referred to by the argument `src` will not be accessed
781 * after the function returns.
782 *
783 * If this function is called while the radio is powered on, the requested
784 * change shall take effect immediately. If the radio is powered-off, the
785 * change shall take effect in the next power-on cycle.
786 */
787 radio_result_t (* set_object)(radio_param_t param, const void *src,
788 size_t size);
789};
790/** @} */
791/*---------------------------------------------------------------------------*/
792#endif /* RADIO_H_ */
793/*---------------------------------------------------------------------------*/
794/** @} */
795/** @} */
radio_result_e
Radio return values when setting or getting radio parameters.
Definition: radio.h:479
radio_param_e
Radio parameters and constants.
Definition: radio.h:102
radio_shr_search_e
Possible values of the get_value() / set_value() value argument when the param argument is RADIO_PARA...
Definition: radio.h:417
enum radio_result_e radio_result_t
Radio return values when setting or getting radio parameters.
radio_power_mode_e
Radio power modes.
Definition: radio.h:391
radio_tx_e
Radio return values for the transmit() function.
Definition: radio.h:494
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
@ RADIO_RESULT_ERROR
An error occurred when getting/setting the parameter, but the arguments were otherwise correct.
Definition: radio.h:488
@ 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_NOACK
A unicast frame was sent OK but an ACK was not received.
Definition: radio.h:516
@ 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
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(* init)(void)
Initialise the radio hardware.
Definition: radio.h:555
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