HelloWorld_IDS01A4 mbed application for Spirit1 P2P demo.

Dependencies:   mbed

Fork of HelloWorld_IDS01A5_Program by rosarium pila

mbed 2.0 (a.k.a classic) HelloWorld example for Spirit1 to transfer data from one node to another.
To send the predefined data packet from the sender to the receiver, user needs to press User Button on the board. The LED on the receiver expansion board will toggle on reception of data successfully.
Data packets sent and received can be seen on USB serial terminal.

EVALUATION BOARDS RF FREQUENCY DESCRIPTION :
X-NUCLEO-IDS01A4 868 MHz 868 MHz RF expansion board based on SPIRIT1

Committer:
rosarium
Date:
Thu May 25 16:38:55 2017 +0000
Revision:
0:2ddc0583bcec
First draft version of HelloWorld_IDS01A5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rosarium 0:2ddc0583bcec 1 /*
rosarium 0:2ddc0583bcec 2 * Copyright (c) 2005, Swedish Institute of Computer Science.
rosarium 0:2ddc0583bcec 3 * All rights reserved.
rosarium 0:2ddc0583bcec 4 *
rosarium 0:2ddc0583bcec 5 * Redistribution and use in source and binary forms, with or without
rosarium 0:2ddc0583bcec 6 * modification, are permitted provided that the following conditions
rosarium 0:2ddc0583bcec 7 * are met:
rosarium 0:2ddc0583bcec 8 * 1. Redistributions of source code must retain the above copyright
rosarium 0:2ddc0583bcec 9 * notice, this list of conditions and the following disclaimer.
rosarium 0:2ddc0583bcec 10 * 2. Redistributions in binary form must reproduce the above copyright
rosarium 0:2ddc0583bcec 11 * notice, this list of conditions and the following disclaimer in the
rosarium 0:2ddc0583bcec 12 * documentation and/or other materials provided with the distribution.
rosarium 0:2ddc0583bcec 13 * 3. Neither the name of the Institute nor the names of its contributors
rosarium 0:2ddc0583bcec 14 * may be used to endorse or promote products derived from this software
rosarium 0:2ddc0583bcec 15 * without specific prior written permission.
rosarium 0:2ddc0583bcec 16 *
rosarium 0:2ddc0583bcec 17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
rosarium 0:2ddc0583bcec 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
rosarium 0:2ddc0583bcec 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
rosarium 0:2ddc0583bcec 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
rosarium 0:2ddc0583bcec 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
rosarium 0:2ddc0583bcec 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
rosarium 0:2ddc0583bcec 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
rosarium 0:2ddc0583bcec 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
rosarium 0:2ddc0583bcec 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
rosarium 0:2ddc0583bcec 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
rosarium 0:2ddc0583bcec 27 * SUCH DAMAGE.
rosarium 0:2ddc0583bcec 28 *
rosarium 0:2ddc0583bcec 29 * This file is part of the Contiki operating system.
rosarium 0:2ddc0583bcec 30 *
rosarium 0:2ddc0583bcec 31 */
rosarium 0:2ddc0583bcec 32
rosarium 0:2ddc0583bcec 33 /**
rosarium 0:2ddc0583bcec 34 * \file
rosarium 0:2ddc0583bcec 35 * Header file for the radio API
rosarium 0:2ddc0583bcec 36 * \author
rosarium 0:2ddc0583bcec 37 * Adam Dunkels <adam@sics.se>
rosarium 0:2ddc0583bcec 38 * Joakim Eriksson <joakime@sics.se>
rosarium 0:2ddc0583bcec 39 * Niclas Finne <nfi@sics.se>
rosarium 0:2ddc0583bcec 40 * Nicolas Tsiftes <nvt@sics.se>
rosarium 0:2ddc0583bcec 41 */
rosarium 0:2ddc0583bcec 42
rosarium 0:2ddc0583bcec 43 /**
rosarium 0:2ddc0583bcec 44 * \addtogroup dev
rosarium 0:2ddc0583bcec 45 * @{
rosarium 0:2ddc0583bcec 46 */
rosarium 0:2ddc0583bcec 47
rosarium 0:2ddc0583bcec 48 /**
rosarium 0:2ddc0583bcec 49 * \defgroup radio Radio API
rosarium 0:2ddc0583bcec 50 *
rosarium 0:2ddc0583bcec 51 * The radio API module defines a set of functions that a radio device
rosarium 0:2ddc0583bcec 52 * driver must implement.
rosarium 0:2ddc0583bcec 53 *
rosarium 0:2ddc0583bcec 54 * @{
rosarium 0:2ddc0583bcec 55 */
rosarium 0:2ddc0583bcec 56
rosarium 0:2ddc0583bcec 57 #ifndef RADIO_H_
rosarium 0:2ddc0583bcec 58 #define RADIO_H_
rosarium 0:2ddc0583bcec 59
rosarium 0:2ddc0583bcec 60 #include <stddef.h>
rosarium 0:2ddc0583bcec 61
rosarium 0:2ddc0583bcec 62 /**
rosarium 0:2ddc0583bcec 63 * Each radio has a set of parameters that designate the current
rosarium 0:2ddc0583bcec 64 * configuration and state of the radio. Parameters can either have
rosarium 0:2ddc0583bcec 65 * values of type radio_value_t, or, when this type is insufficient, a
rosarium 0:2ddc0583bcec 66 * generic object that is specified by a memory pointer and the size
rosarium 0:2ddc0583bcec 67 * of the object.
rosarium 0:2ddc0583bcec 68 *
rosarium 0:2ddc0583bcec 69 * The radio_value_t type is set to an integer type that can hold most
rosarium 0:2ddc0583bcec 70 * values used to configure the radio, and is therefore the most
rosarium 0:2ddc0583bcec 71 * common type used for a parameter. Certain parameters require
rosarium 0:2ddc0583bcec 72 * objects of a considerably larger size than radio_value_t, however,
rosarium 0:2ddc0583bcec 73 * and in these cases the documentation below for the parameter will
rosarium 0:2ddc0583bcec 74 * indicate this.
rosarium 0:2ddc0583bcec 75 *
rosarium 0:2ddc0583bcec 76 * All radio parameters that can vary during runtime are prefixed by
rosarium 0:2ddc0583bcec 77 * "RADIO_PARAM", whereas those "parameters" that are guaranteed to
rosarium 0:2ddc0583bcec 78 * remain immutable are prefixed by "RADIO_CONST". Each mutable
rosarium 0:2ddc0583bcec 79 * parameter has a set of valid parameter values. When attempting to
rosarium 0:2ddc0583bcec 80 * set a parameter to an invalid value, the radio will return
rosarium 0:2ddc0583bcec 81 * RADIO_RESULT_INVALID_VALUE.
rosarium 0:2ddc0583bcec 82 *
rosarium 0:2ddc0583bcec 83 * Some radios support only a subset of the defined radio parameters.
rosarium 0:2ddc0583bcec 84 * When trying to set or get such an unsupported parameter, the radio
rosarium 0:2ddc0583bcec 85 * will return RADIO_RESULT_NOT_SUPPORTED.
rosarium 0:2ddc0583bcec 86 */
rosarium 0:2ddc0583bcec 87
rosarium 0:2ddc0583bcec 88 typedef int radio_value_t;
rosarium 0:2ddc0583bcec 89 typedef unsigned radio_param_t;
rosarium 0:2ddc0583bcec 90
rosarium 0:2ddc0583bcec 91 enum {
rosarium 0:2ddc0583bcec 92
rosarium 0:2ddc0583bcec 93 /* Radio power mode determines if the radio is on
rosarium 0:2ddc0583bcec 94 (RADIO_POWER_MODE_ON) or off (RADIO_POWER_MODE_OFF). */
rosarium 0:2ddc0583bcec 95 RADIO_PARAM_POWER_MODE,
rosarium 0:2ddc0583bcec 96
rosarium 0:2ddc0583bcec 97 /*
rosarium 0:2ddc0583bcec 98 * Channel used for radio communication. The channel depends on the
rosarium 0:2ddc0583bcec 99 * communication standard used by the radio. The values can range
rosarium 0:2ddc0583bcec 100 * from RADIO_CONST_CHANNEL_MIN to RADIO_CONST_CHANNEL_MAX.
rosarium 0:2ddc0583bcec 101 */
rosarium 0:2ddc0583bcec 102 RADIO_PARAM_CHANNEL,
rosarium 0:2ddc0583bcec 103
rosarium 0:2ddc0583bcec 104 /* Personal area network identifier, which is used by the address filter. */
rosarium 0:2ddc0583bcec 105 RADIO_PARAM_PAN_ID,
rosarium 0:2ddc0583bcec 106
rosarium 0:2ddc0583bcec 107 /* Short address (16 bits) for the radio, which is used by the address
rosarium 0:2ddc0583bcec 108 filter. */
rosarium 0:2ddc0583bcec 109 RADIO_PARAM_16BIT_ADDR,
rosarium 0:2ddc0583bcec 110
rosarium 0:2ddc0583bcec 111 /*
rosarium 0:2ddc0583bcec 112 * Radio receiver mode determines if the radio has address filter
rosarium 0:2ddc0583bcec 113 * (RADIO_RX_MODE_ADDRESS_FILTER) and auto-ACK (RADIO_RX_MODE_AUTOACK)
rosarium 0:2ddc0583bcec 114 * enabled. This parameter is set as a bit mask.
rosarium 0:2ddc0583bcec 115 */
rosarium 0:2ddc0583bcec 116 RADIO_PARAM_RX_MODE,
rosarium 0:2ddc0583bcec 117
rosarium 0:2ddc0583bcec 118 /*
rosarium 0:2ddc0583bcec 119 * Radio transmission mode determines if the radio has send on CCA
rosarium 0:2ddc0583bcec 120 * (RADIO_TX_MODE_SEND_ON_CCA) enabled or not. This parameter is set
rosarium 0:2ddc0583bcec 121 * as a bit mask.
rosarium 0:2ddc0583bcec 122 */
rosarium 0:2ddc0583bcec 123 RADIO_PARAM_TX_MODE,
rosarium 0:2ddc0583bcec 124
rosarium 0:2ddc0583bcec 125 /*
rosarium 0:2ddc0583bcec 126 * Transmission power in dBm. The values can range from
rosarium 0:2ddc0583bcec 127 * RADIO_CONST_TXPOWER_MIN to RADIO_CONST_TXPOWER_MAX.
rosarium 0:2ddc0583bcec 128 *
rosarium 0:2ddc0583bcec 129 * Some radios restrict the available values to a subset of this
rosarium 0:2ddc0583bcec 130 * range. If an unavailable TXPOWER value is requested to be set,
rosarium 0:2ddc0583bcec 131 * the radio may select another TXPOWER close to the requested
rosarium 0:2ddc0583bcec 132 * one. When getting the value of this parameter, the actual value
rosarium 0:2ddc0583bcec 133 * used by the radio will be returned.
rosarium 0:2ddc0583bcec 134 */
rosarium 0:2ddc0583bcec 135 RADIO_PARAM_TXPOWER,
rosarium 0:2ddc0583bcec 136
rosarium 0:2ddc0583bcec 137 /*
rosarium 0:2ddc0583bcec 138 * Clear channel assessment threshold in dBm. This threshold
rosarium 0:2ddc0583bcec 139 * determines the minimum RSSI level at which the radio will assume
rosarium 0:2ddc0583bcec 140 * that there is a packet in the air.
rosarium 0:2ddc0583bcec 141 *
rosarium 0:2ddc0583bcec 142 * The CCA threshold must be set to a level above the noise floor of
rosarium 0:2ddc0583bcec 143 * the deployment. Otherwise mechanisms such as send-on-CCA and
rosarium 0:2ddc0583bcec 144 * low-power-listening duty cycling protocols may not work
rosarium 0:2ddc0583bcec 145 * correctly. Hence, the default value of the system may not be
rosarium 0:2ddc0583bcec 146 * optimal for any given deployment.
rosarium 0:2ddc0583bcec 147 */
rosarium 0:2ddc0583bcec 148 RADIO_PARAM_CCA_THRESHOLD,
rosarium 0:2ddc0583bcec 149
rosarium 0:2ddc0583bcec 150 /* Received signal strength indicator in dBm. */
rosarium 0:2ddc0583bcec 151 RADIO_PARAM_RSSI,
rosarium 0:2ddc0583bcec 152
rosarium 0:2ddc0583bcec 153 /*
rosarium 0:2ddc0583bcec 154 * Long (64 bits) address for the radio, which is used by the address filter.
rosarium 0:2ddc0583bcec 155 * The address is specified in network byte order.
rosarium 0:2ddc0583bcec 156 *
rosarium 0:2ddc0583bcec 157 * Because this parameter value is larger than what fits in radio_value_t,
rosarium 0:2ddc0583bcec 158 * it needs to be used with radio.get_object()/set_object().
rosarium 0:2ddc0583bcec 159 */
rosarium 0:2ddc0583bcec 160 RADIO_PARAM_64BIT_ADDR,
rosarium 0:2ddc0583bcec 161
rosarium 0:2ddc0583bcec 162 /* Constants (read only) */
rosarium 0:2ddc0583bcec 163
rosarium 0:2ddc0583bcec 164 /* The lowest radio channel. */
rosarium 0:2ddc0583bcec 165 RADIO_CONST_CHANNEL_MIN,
rosarium 0:2ddc0583bcec 166 /* The highest radio channel. */
rosarium 0:2ddc0583bcec 167 RADIO_CONST_CHANNEL_MAX,
rosarium 0:2ddc0583bcec 168
rosarium 0:2ddc0583bcec 169 /* The minimum transmission power in dBm. */
rosarium 0:2ddc0583bcec 170 RADIO_CONST_TXPOWER_MIN,
rosarium 0:2ddc0583bcec 171 /* The maximum transmission power in dBm. */
rosarium 0:2ddc0583bcec 172 RADIO_CONST_TXPOWER_MAX
rosarium 0:2ddc0583bcec 173 };
rosarium 0:2ddc0583bcec 174
rosarium 0:2ddc0583bcec 175 /* Radio power modes */
rosarium 0:2ddc0583bcec 176 enum {
rosarium 0:2ddc0583bcec 177 RADIO_POWER_MODE_OFF,
rosarium 0:2ddc0583bcec 178 RADIO_POWER_MODE_ON
rosarium 0:2ddc0583bcec 179 };
rosarium 0:2ddc0583bcec 180
rosarium 0:2ddc0583bcec 181 /**
rosarium 0:2ddc0583bcec 182 * The radio reception mode controls address filtering and automatic
rosarium 0:2ddc0583bcec 183 * transmission of acknowledgements in the radio (if such operations
rosarium 0:2ddc0583bcec 184 * are supported by the radio). A single parameter is used to allow
rosarium 0:2ddc0583bcec 185 * setting these features simultaneously as an atomic operation.
rosarium 0:2ddc0583bcec 186 *
rosarium 0:2ddc0583bcec 187 * To enable both address filter and transmissions of automatic
rosarium 0:2ddc0583bcec 188 * acknowledgments:
rosarium 0:2ddc0583bcec 189 *
rosarium 0:2ddc0583bcec 190 * NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE,
rosarium 0:2ddc0583bcec 191 * RADIO_RX_MODE_ADDRESS_FILTER | RADIO_RX_MODE_AUTOACK);
rosarium 0:2ddc0583bcec 192 */
rosarium 0:2ddc0583bcec 193 #define RADIO_RX_MODE_ADDRESS_FILTER (1 << 0)
rosarium 0:2ddc0583bcec 194 #define RADIO_RX_MODE_AUTOACK (1 << 1)
rosarium 0:2ddc0583bcec 195
rosarium 0:2ddc0583bcec 196 /**
rosarium 0:2ddc0583bcec 197 * The radio transmission mode controls whether transmissions should
rosarium 0:2ddc0583bcec 198 * be done using clear channel assessment (if supported by the
rosarium 0:2ddc0583bcec 199 * radio). If send-on-CCA is enabled, the radio's send function will
rosarium 0:2ddc0583bcec 200 * wait for a radio-specific time window for the channel to become
rosarium 0:2ddc0583bcec 201 * clear. If this does not happen, the send function will return
rosarium 0:2ddc0583bcec 202 * RADIO_TX_COLLISION.
rosarium 0:2ddc0583bcec 203 */
rosarium 0:2ddc0583bcec 204 #define RADIO_TX_MODE_SEND_ON_CCA (1 << 0)
rosarium 0:2ddc0583bcec 205
rosarium 0:2ddc0583bcec 206 /* Radio return values when setting or getting radio parameters. */
rosarium 0:2ddc0583bcec 207 typedef enum {
rosarium 0:2ddc0583bcec 208 RADIO_RESULT_OK,
rosarium 0:2ddc0583bcec 209 RADIO_RESULT_NOT_SUPPORTED,
rosarium 0:2ddc0583bcec 210 RADIO_RESULT_INVALID_VALUE,
rosarium 0:2ddc0583bcec 211 RADIO_RESULT_ERROR
rosarium 0:2ddc0583bcec 212 } radio_result_t;
rosarium 0:2ddc0583bcec 213
rosarium 0:2ddc0583bcec 214 /* Radio return values for transmissions. */
rosarium 0:2ddc0583bcec 215 enum {
rosarium 0:2ddc0583bcec 216 RADIO_TX_OK,
rosarium 0:2ddc0583bcec 217 RADIO_TX_ERR,
rosarium 0:2ddc0583bcec 218 RADIO_TX_COLLISION,
rosarium 0:2ddc0583bcec 219 RADIO_TX_NOACK,
rosarium 0:2ddc0583bcec 220 };
rosarium 0:2ddc0583bcec 221
rosarium 0:2ddc0583bcec 222 /**
rosarium 0:2ddc0583bcec 223 * The structure of a device driver for a radio in Contiki.
rosarium 0:2ddc0583bcec 224 */
rosarium 0:2ddc0583bcec 225 struct radio_driver {
rosarium 0:2ddc0583bcec 226
rosarium 0:2ddc0583bcec 227 int (* init)(void);
rosarium 0:2ddc0583bcec 228
rosarium 0:2ddc0583bcec 229 /** Prepare the radio with a packet to be sent. */
rosarium 0:2ddc0583bcec 230 int (* prepare)(const void *payload, unsigned short payload_len);
rosarium 0:2ddc0583bcec 231
rosarium 0:2ddc0583bcec 232 /** Send the packet that has previously been prepared. */
rosarium 0:2ddc0583bcec 233 int (* transmit)(unsigned short transmit_len);
rosarium 0:2ddc0583bcec 234
rosarium 0:2ddc0583bcec 235 /** Prepare & transmit a packet. */
rosarium 0:2ddc0583bcec 236 int (* send)(const void *payload, unsigned short payload_len);
rosarium 0:2ddc0583bcec 237
rosarium 0:2ddc0583bcec 238 /** Read a received packet into a buffer. */
rosarium 0:2ddc0583bcec 239 int (* read)(void *buf, unsigned short buf_len);
rosarium 0:2ddc0583bcec 240
rosarium 0:2ddc0583bcec 241 /** Perform a Clear-Channel Assessment (CCA) to find out if there is
rosarium 0:2ddc0583bcec 242 a packet in the air or not. */
rosarium 0:2ddc0583bcec 243 int (* channel_clear)(void);
rosarium 0:2ddc0583bcec 244
rosarium 0:2ddc0583bcec 245 /** Check if the radio driver is currently receiving a packet */
rosarium 0:2ddc0583bcec 246 int (* receiving_packet)(void);
rosarium 0:2ddc0583bcec 247
rosarium 0:2ddc0583bcec 248 /** Check if the radio driver has just received a packet */
rosarium 0:2ddc0583bcec 249 int (* pending_packet)(void);
rosarium 0:2ddc0583bcec 250
rosarium 0:2ddc0583bcec 251 /** Turn the radio on. */
rosarium 0:2ddc0583bcec 252 int (* on)(void);
rosarium 0:2ddc0583bcec 253
rosarium 0:2ddc0583bcec 254 /** Turn the radio off. */
rosarium 0:2ddc0583bcec 255 int (* off)(void);
rosarium 0:2ddc0583bcec 256
rosarium 0:2ddc0583bcec 257 /** Get a radio parameter value. */
rosarium 0:2ddc0583bcec 258 radio_result_t (* get_value)(radio_param_t param, radio_value_t *value);
rosarium 0:2ddc0583bcec 259
rosarium 0:2ddc0583bcec 260 /** Set a radio parameter value. */
rosarium 0:2ddc0583bcec 261 radio_result_t (* set_value)(radio_param_t param, radio_value_t value);
rosarium 0:2ddc0583bcec 262
rosarium 0:2ddc0583bcec 263 /**
rosarium 0:2ddc0583bcec 264 * Get a radio parameter object. The argument 'dest' must point to a
rosarium 0:2ddc0583bcec 265 * memory area of at least 'size' bytes, and this memory area will
rosarium 0:2ddc0583bcec 266 * contain the parameter object if the function succeeds.
rosarium 0:2ddc0583bcec 267 */
rosarium 0:2ddc0583bcec 268 radio_result_t (* get_object)(radio_param_t param, void *dest, size_t size);
rosarium 0:2ddc0583bcec 269
rosarium 0:2ddc0583bcec 270 /**
rosarium 0:2ddc0583bcec 271 * Set a radio parameter object. The memory area referred to by the
rosarium 0:2ddc0583bcec 272 * argument 'src' will not be accessed after the function returns.
rosarium 0:2ddc0583bcec 273 */
rosarium 0:2ddc0583bcec 274 radio_result_t (* set_object)(radio_param_t param, const void *src,
rosarium 0:2ddc0583bcec 275 size_t size);
rosarium 0:2ddc0583bcec 276
rosarium 0:2ddc0583bcec 277 };
rosarium 0:2ddc0583bcec 278
rosarium 0:2ddc0583bcec 279 #endif /* RADIO_H_ */
rosarium 0:2ddc0583bcec 280
rosarium 0:2ddc0583bcec 281 /** @} */
rosarium 0:2ddc0583bcec 282 /** @} */