µracoli Manual Version foo

- µracoli
- User Guide
- Reference Guide

radio.h
1 /* Copyright (c) 2007-2009 Axel Wachtler
2 All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * 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 * Neither the name of the authors 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND 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 COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE. */
28
29 /* $Id$ */
35 #ifndef RADIO_H
36 #define RADIO_H
37
38 /* === Includes ============================================================== */
39 #include <stdbool.h>
40 #include <stdio.h>
41 #include <util/crc16.h>
42 #include "const.h"
43
49 /* === Externals ============================================================= */
50
51 /* === Types ================================================================= */
52
58 #define STATE_OFF (0)
59
60 #define STATE_TX (1)
61
62 #define STATE_RX (2)
63
64 #define STATE_TXAUTO (3)
65
66 #define STATE_RXAUTO (4)
67
68 #define STATE_SLEEP (5)
69
78 typedef uint8_t radio_state_t;
79
83 typedef enum
84 {
85 TX_OK,
86 TX_CCA_FAIL,
87 TX_NO_ACK,
88 TX_FAIL,
89 } radio_tx_done_t;
90
91
95 typedef enum SHORTENUM
96 {
97 #if defined(CCA_BUSY)
98
102 RADIO_CCA_FREE = CCA_IDLE,
103 RADIO_CCA_BUSY = CCA_BUSY,
104 RADIO_CCA_FAIL = 255,
105 #else
106
107 RADIO_CCA_FREE = 0,
109 RADIO_CCA_BUSY,
111 RADIO_CCA_FAIL
112 #endif
113
114 } radio_cca_t;
115
116
119 typedef enum SHORTENUM
120 {
122 phyCurrentChannel,
124 phyChannelsSupported,
126 phyTransmitPower,
128 phyIdleState,
138 phyCCAMode,
140 phyPanId,
142 phyShortAddr,
144 phyLongAddr,
145
147 phyDataRate,
148
150 phyTxPa,
152 phyRxLna
153
154 } radio_attribute_t;
155
156
165 typedef union radio_param_t
166 {
167 #if defined __cplusplus
168 public:
169 radio_param_t(int8_t c) { channel = c; } /* also used for txpwr_t */
170 //radio_param_t(radio_state_t s) { idle_state = s; }
171 radio_param_t(uint8_t m) { cca_mode = m; } /* also used for data_rate, tx_pa, rx_lna */
172 radio_param_t(uint16_t p) { pan_id = p; } /* also used for short_addr */
173 radio_param_t(uint64_t *la) { long_addr = la; }
174 #endif
175
176 channel_t channel;
178 txpwr_t tx_pwr;
180 radio_state_t idle_state;
182 ccamode_t cca_mode;
184 uint16_t pan_id;
186 uint16_t short_addr;
188 uint64_t *long_addr;
190 uint8_t data_rate;
191
193 uint8_t tx_pa;
195 uint8_t rx_lna;
196
197 } radio_param_t;
198
199
203 typedef enum SHORTENUM
204 {
205 #ifndef SUCCESS
206
207 SUCCESS = 0,
208 #endif
209 STATE_SET_FAILED = 1,
210 SET_PARM_FAILED,
211 GET_PARM_FAILED,
212 GENERAL_ERROR,
213 } radio_error_t;
214
215
219 typedef struct
220 {
221 uint8_t channel;
223 uint8_t tx_pwr;
224 uint8_t cca_mode;
225 radio_state_t state;
226 radio_state_t idle_state;
227 uint8_t *rxframe;
228 uint8_t rxframesz;
229 uint8_t tx_pa;
230 uint8_t rx_lna;
231 } radio_status_t;
232
233 /* === Macros ================================================================ */
234
238 #define VOID_RSSI (0xff)
239
240 #if defined(DOXYGEN)
241
245 # define RP_CHANNEL(x)
246 #elif defined __cplusplus
247 # define RP_CHANNEL(x) phyCurrentChannel,radio_param_t((channel_t)x)
248 #else
249 # define RP_CHANNEL(x) phyCurrentChannel,(radio_param_t){.channel=x}
250 #endif
251
252 #if defined(DOXYGEN)
253
257 # define RP_TXPWR(x)
258 #elif defined __cplusplus
259 # define RP_TXPWR(x) phyTransmitPower,radio_param_t((txpwr_t)x)
260 #else
261 # define RP_TXPWR(x) phyTransmitPower,(radio_param_t){.tx_pwr=x}
262 #endif
263
264 #if defined(DOXYGEN)
265
269 # define RP_IDLESTATE(x)
270 #elif defined __cplusplus
271 # define RP_IDLESTATE(x) phyIdleState,radio_param_t(x)
272 #else
273 # define RP_IDLESTATE(x) phyIdleState,(radio_param_t){.idle_state=x}
274 #endif
275
276 #if defined(DOXYGEN)
277
281 # define RP_CCAMODE(x)
282 #elif defined __cplusplus
283 # define RP_CCAMODE(x) phyCCAMode,radio_param_t((ccamode_t)x)
284 #else
285 # define RP_CCAMODE(x) phyCCAMode,(radio_param_t){.cca_mode=x}
286 #endif
287
288 #if defined(DOXYGEN)
289
293 # define RP_PANID(x)
294 #elif defined __cplusplus
295 # define RP_PANID(x) phyPanId,radio_param_t((uint16_t)x)
296 #else
297 # define RP_PANID(x) phyPanId,(radio_param_t){.pan_id=x}
298 #endif
299
300 #if defined(DOXYGEN)
301
305 # define RP_SHORTADDR(x)
306 #elif defined __cplusplus
307 # define RP_SHORTADDR(x) phyShortAddr,radio_param_t((uint16_t)x)
308 #else
309 # define RP_SHORTADDR(x) phyShortAddr,(radio_param_t){.short_addr=x}
310 #endif
311
312 #if defined(DOXYGEN)
313
317 # define RP_LONGADDR(x)
318 #elif defined __cplusplus
319 # define RP_LONGADDR(x) phyLongAddr,radio_param_t((uint64_t *)x)
320 #else
321 # define RP_LONGADDR(x) phyLongAddr,(radio_param_t){.long_addr=x}
322 #endif
323
324
325 #if defined(DOXYGEN)
326
330 # define RP_DATARATE(x)
331 #elif defined __cplusplus
332 # define RP_DATARATE(x) phyDataRate,radio_param_t((uint16_t)x)
333 #else
334 # define RP_DATARATE(x) phyDataRate,(radio_param_t){.data_rate=x}
335 #endif
336
337 #if defined(DOXYGEN)
338
342 # define RP_CHANNEL(x)
343 #elif defined __cplusplus
344 # define RP_TX_PA(x) phyTxPa,radio_param_t((tx_pa_t)x)
345 #else
346 # define RP_TX_PA(x) phyTxPa,(radio_param_t){.tx_pa=x}
347 #endif
348
349 #if defined(DOXYGEN)
350
354 # define RP_RX_LNA(x)
355 #elif defined __cplusplus
356 # define RP_RX_LNA(x) phyRxLna,radio_param_t((rx_lna_t)x)
357 #else
358 # define RP_RX_LNA(x) phyRxLna,(radio_param_t){.rx_lna=x}
359 #endif
360
361 #define CRC_CCITT_UPDATE(crc, data) _crc_ccitt_update(crc, data)
362
363 #ifndef RADIO_CFG_EEOFFSET
364
365 #define RADIO_CFG_EEOFFSET (8)
366 #endif
367
368 #ifndef RADIO_CFG_DATA
369
370 #define RADIO_CFG_DATA {chan: 16, txp: 0, cca: 1, edt: 11, clkm: 0, crc: 0xab12}
371 #endif
372
373 /* === Prototypes ============================================================ */
374 #ifdef __cplusplus
375 extern "C" {
376 #endif
377
378
393 void radio_init(uint8_t * rxbuf, uint8_t rxbufsz);
394
395
401 void radio_force_state(radio_state_t state);
402
403
408 void radio_set_state(radio_state_t state);
409
433 void radio_set_param(radio_attribute_t attr, radio_param_t parm);
434
453 void radio_send_frame(uint8_t len, uint8_t *frm, uint8_t compcrc);
454
455
460 radio_cca_t radio_do_cca(void);
461
462 int radio_putchar(int c);
463 int radio_getchar(void);
464
465 /* application call back functions to radio library */
466
467
476 void usr_radio_error(radio_error_t err);
477
483 void usr_radio_irq(uint8_t cause);
484
510 uint8_t * usr_radio_receive_frame(uint8_t len, uint8_t *frm, uint8_t lqi, int8_t ed, uint8_t crc_fail);
511
512
518 void usr_radio_tx_done(radio_tx_done_t status);
519
520
521 #ifdef __cplusplus
522 } /* extern "C" */
523 #endif
524
525
529 #endif /* #ifndef RADIO_H */
530 /* EOF */
radio_status_t::idle_state
radio_state_t idle_state
Definition: radio.h:226
GET_PARM_FAILED
Definition: radio.h:211
radio_status_t::rxframe
uint8_t * rxframe
Definition: radio.h:227
phyChannelsSupported
Definition: radio.h:124
phyShortAddr
Definition: radio.h:142
phyIdleState
Definition: radio.h:128
TX_CCA_FAIL
Definition: radio.h:86
phyTransmitPower
Definition: radio.h:126
radio_init
void radio_init(uint8_t *rxbuf, uint8_t rxbufsz)
Radio related ressource initialization.
radio_param_t::cca_mode
ccamode_t cca_mode
Definition: radio.h:182
TX_FAIL
Definition: radio.h:88
radio_param_t::tx_pa
uint8_t tx_pa
Definition: radio.h:193
radio_param_t::pan_id
uint16_t pan_id
Definition: radio.h:184
radio_force_state
void radio_force_state(radio_state_t state)
Force the radio to the requested state. (using CMD_FORCE_TRX_OFF)
usr_radio_tx_done
void usr_radio_tx_done(radio_tx_done_t status)
phyCurrentChannel
Definition: radio.h:122
radio_do_cca
radio_cca_t radio_do_cca(void)
Perform CCA Measure.
ccamode_t
uint8_t ccamode_t
Definition: const.h:334
usr_radio_error
void usr_radio_error(radio_error_t err)
radio_status_t
Structure for storage of radio parameters.
Definition: radio.h:219
radio_status_t::channel
uint8_t channel
Definition: radio.h:221
radio_state_t
uint8_t radio_state_t
Definition: radio.h:78
radio_status_t::cca_mode
uint8_t cca_mode
Definition: radio.h:224
txpwr_t
int8_t txpwr_t
Definition: const.h:326
radio_attribute_t
radio_attribute_t
Definition: radio.h:119
phyRxLna
Definition: radio.h:152
radio_cca_t
radio_cca_t
Definition: radio.h:95
radio_tx_done_t
radio_tx_done_t
Definition: radio.h:83
radio_error_t
radio_error_t
Error codes.
Definition: radio.h:203
SUCCESS
Definition: radio.h:207
phyPanId
Definition: radio.h:140
radio_param_t
Container for handover of radio parameter values.
Definition: radio.h:165
SET_PARM_FAILED
Definition: radio.h:210
radio_param_t::rx_lna
uint8_t rx_lna
Definition: radio.h:195
radio_param_t::data_rate
uint8_t data_rate
Definition: radio.h:190
radio_send_frame
void radio_send_frame(uint8_t len, uint8_t *frm, uint8_t compcrc)
Frame transmission.
radio_status_t::state
radio_state_t state
Definition: radio.h:225
phyCCAMode
Definition: radio.h:138
radio_param_t::long_addr
uint64_t * long_addr
Definition: radio.h:188
usr_radio_receive_frame
uint8_t * usr_radio_receive_frame(uint8_t len, uint8_t *frm, uint8_t lqi, int8_t ed, uint8_t crc_fail)
Frame reception callback function.
radio_param_t::short_addr
uint16_t short_addr
Definition: radio.h:186
phyDataRate
Definition: radio.h:147
radio_status_t::rxframesz
uint8_t rxframesz
Definition: radio.h:228
usr_radio_irq
void usr_radio_irq(uint8_t cause)
radio_param_t::idle_state
radio_state_t idle_state
Definition: radio.h:180
phyLongAddr
Definition: radio.h:144
RADIO_CCA_FREE
Definition: radio.h:107
radio_param_t::channel
channel_t channel
Definition: radio.h:176
TX_NO_ACK
Definition: radio.h:87
radio_set_param
void radio_set_param(radio_attribute_t attr, radio_param_t parm)
Set a radio parameter.
TX_OK
Definition: radio.h:85
channel_t
int8_t channel_t
Definition: const.h:323
STATE_SET_FAILED
Definition: radio.h:209
radio_param_t::tx_pwr
txpwr_t tx_pwr
Definition: radio.h:178
radio_set_state
void radio_set_state(radio_state_t state)
Bring the the radio in the requested state.
RADIO_CCA_FAIL
Definition: radio.h:111
radio_status_t::tx_pwr
uint8_t tx_pwr
Definition: radio.h:223
phyTxPa
Definition: radio.h:150
RADIO_CCA_BUSY
Definition: radio.h:109
GENERAL_ERROR
Definition: radio.h:212