µracoli Manual  Version foo
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 {
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 
111  RADIO_CCA_FAIL
112 #endif
113 
114 } radio_cca_t;
115 
116 
119 typedef enum SHORTENUM
120 {
145 
148 
153 
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 
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
213 } radio_error_t;
214 
215 
219 typedef struct
220 {
221  uint8_t channel;
223  uint8_t tx_pwr;
224  uint8_t cca_mode;
227  uint8_t *rxframe;
228  uint8_t rxframesz;
229  uint8_t tx_pa;
230  uint8_t rx_lna;
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 
434 
453 void radio_send_frame(uint8_t len, uint8_t *frm, uint8_t compcrc);
454 
455 
461 
462 int radio_putchar(int c);
463 int radio_getchar(void);
464 
465 /* application call back functions to radio library */
466 
467 
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 
519 
520 
521 #ifdef __cplusplus
522 } /* extern "C" */
523 #endif
524 
525 
529 #endif /* #ifndef RADIO_H */
530 /* EOF */
radio_state_t idle_state
Definition: radio.h:226
uint8_t * rxframe
Definition: radio.h:227
void radio_init(uint8_t *rxbuf, uint8_t rxbufsz)
Radio related ressource initialization.
ccamode_t cca_mode
Definition: radio.h:182
Definition: radio.h:88
uint8_t tx_pa
Definition: radio.h:193
uint16_t pan_id
Definition: radio.h:184
void radio_force_state(radio_state_t state)
Force the radio to the requested state. (using CMD_FORCE_TRX_OFF)
void usr_radio_tx_done(radio_tx_done_t status)
radio_cca_t radio_do_cca(void)
Perform CCA Measure.
uint8_t ccamode_t
Definition: const.h:334
void usr_radio_error(radio_error_t err)
Structure for storage of radio parameters.
Definition: radio.h:219
uint8_t channel
Definition: radio.h:221
uint8_t radio_state_t
Definition: radio.h:78
uint8_t cca_mode
Definition: radio.h:224
int8_t txpwr_t
Definition: const.h:326
radio_attribute_t
Definition: radio.h:119
radio_cca_t
Definition: radio.h:95
radio_tx_done_t
Definition: radio.h:83
radio_error_t
Error codes.
Definition: radio.h:203
Definition: radio.h:207
Container for handover of radio parameter values.
Definition: radio.h:165
uint8_t rx_lna
Definition: radio.h:195
uint8_t data_rate
Definition: radio.h:190
void radio_send_frame(uint8_t len, uint8_t *frm, uint8_t compcrc)
Frame transmission.
radio_state_t state
Definition: radio.h:225
uint64_t * long_addr
Definition: radio.h:188
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.
uint16_t short_addr
Definition: radio.h:186
uint8_t rxframesz
Definition: radio.h:228
void usr_radio_irq(uint8_t cause)
radio_state_t idle_state
Definition: radio.h:180
channel_t channel
Definition: radio.h:176
void radio_set_param(radio_attribute_t attr, radio_param_t parm)
Set a radio parameter.
Definition: radio.h:85
int8_t channel_t
Definition: const.h:323
txpwr_t tx_pwr
Definition: radio.h:178
void radio_set_state(radio_state_t state)
Bring the the radio in the requested state.
uint8_t tx_pwr
Definition: radio.h:223
Definition: radio.h:150