- Main Page
- Related Pages
- Modules
- Data Structures
- Files

# radio.h

Go to the documentation of this file.

    00001 /* Copyright (c) 2007-2009 Axel Wachtler
    00002    All rights reserved.
    00003
    00004    Redistribution and use in source and binary forms, with or without
    00005    modification, are permitted provided that the following conditions
    00006    are met:
    00007
    00008    * Redistributions of source code must retain the above copyright
    00009      notice, this list of conditions and the following disclaimer.
    00010    * Redistributions in binary form must reproduce the above copyright
    00011      notice, this list of conditions and the following disclaimer in the
    00012      documentation and/or other materials provided with the distribution.
    00013    * Neither the name of the authors nor the names of its contributors
    00014      may be used to endorse or promote products derived from this software
    00015      without specific prior written permission.
    00016
    00017    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00018    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00019    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00020    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00021    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    00022    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    00023    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    00024    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    00025    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    00026    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    00027    POSSIBILITY OF SUCH DAMAGE. */
    00028
    00029 /* $Id: radio.h,v 1.15 2010/01/20 20:11:14 awachtler Exp $ */
    00035 #ifndef RADIO_H
    00036 #define RADIO_H
    00037
    00038 /* === Includes ============================================================== */
    00039 #include <stdbool.h>
    00040 #include <stdio.h>
    00041 #include <util/crc16.h>
    00042 #include "const.h"
    00043
    00044 /* === Externals ============================================================= */
    00045
    00046 /* === Types ================================================================= */
    00047
    00052 typedef enum
    00053 {
    00054     STATE_OFF = 0,
    00055     STATE_TX,
    00057     STATE_RX,
    00060     STATE_TXAUTO,
    00061     STATE_RXAUTO,
    00062     STATE_SLEEP,
    00063 } radio_state_t;
    00064
    00069 typedef enum
    00070 {
    00071     TX_OK,
    00072     TX_CCA_FAIL,
    00073     TX_NO_ACK,
    00074     TX_FAIL,
    00075 } radio_tx_done_t;
    00076
    00077
    00082 typedef enum SHORTENUM
    00083 {
    00084 #if defined(CCA_BUSY)
    00085
    00089     RADIO_CCA_FREE = CCA_IDLE,
    00090     RADIO_CCA_BUSY = CCA_BUSY,
    00091     RADIO_CCA_FAIL = 255,
    00092 #else
    00093
    00094     RADIO_CCA_FREE = 0,
    00096     RADIO_CCA_BUSY,
    00098     RADIO_CCA_FAIL
    00099 #endif
    00100
    00101 } radio_cca_t;
    00102
    00103
    00107 typedef enum SHORTENUM
    00108 {
    00110     phyCurrentChannel,
    00112     phyChannelsSupported,
    00114     phyTransmitPower,
    00116     phyIdleState,
    00126     phyCCAMode,
    00128     phyPanId,
    00130     phyShortAddr,
    00132     phyLongAddr,
    00133
    00134 } radio_attribute_t;
    00135
    00136
    00146 typedef union radio_param_t
    00147 {
    00148 #if defined __cplusplus
    00149 public:
    00150     radio_param_t(int8_t c) { channel = c; } /* also used for txpwr_t */
    00151     radio_param_t(radio_state_t s) { idle_state = s; }
    00152     radio_param_t(uint8_t m) { cca_mode = m; }
    00153     radio_param_t(uint16_t p) { pan_id = p; } /* also used for short_addr */
    00154     radio_param_t(uint64_t *la) { long_addr = la; }
    00155 #endif
    00156
    00157     channel_t channel;
    00159     txpwr_t   tx_pwr;
    00161     radio_state_t idle_state;
    00163     ccamode_t cca_mode;
    00165     uint16_t pan_id;
    00167     uint16_t short_addr;
    00169     uint64_t *long_addr;
    00170 } radio_param_t;
    00171
    00172
    00177 typedef enum SHORTENUM
    00178 {
    00179     #ifndef SUCCESS
    00180
    00181     SUCCESS = 0,
    00182     #endif
    00183     STATE_SET_FAILED = 1,
    00184     SET_PARM_FAILED,
    00185     GET_PARM_FAILED,
    00186     GENERAL_ERROR,
    00187 } radio_error_t;
    00188
    00189
    00194 typedef struct
    00195 {
    00196     uint8_t  channel;
    00198     uint8_t  tx_pwr;
    00199     uint8_t  cca_mode;
    00200     radio_state_t state;
    00201     radio_state_t idle_state;
    00202     uint8_t  rxrssi;
    00203     uint8_t  rxlqi;
    00204     uint8_t  *rxframe;
    00205     uint8_t  rxframesz;
    00206 } radio_status_t;
    00207
    00208 /* === Macros ================================================================ */
    00209
    00214 #define VOID_RSSI (0xff)
    00215
    00216 #if defined(DOXYGEN)
    00217
    00222 #  define RP_CHANNEL(x)
    00223 #elif defined __cplusplus
    00224 #  define RP_CHANNEL(x) phyCurrentChannel,radio_param_t((channel_t)x)
    00225 #else
    00226 #  define RP_CHANNEL(x) phyCurrentChannel,(radio_param_t){.channel=x}
    00227 #endif
    00228
    00229 #if defined(DOXYGEN)
    00230
    00235 #  define RP_TXPWR(x)
    00236 #elif defined __cplusplus
    00237 #  define RP_TXPWR(x)   phyTransmitPower,radio_param_t((txpwr_t)x)
    00238 #else
    00239 #  define RP_TXPWR(x)   phyTransmitPower,(radio_param_t){.tx_pwr=x}
    00240 #endif
    00241
    00242 #if defined(DOXYGEN)
    00243
    00248 #  define RP_IDLESTATE(x)
    00249 #elif defined __cplusplus
    00250 #  define RP_IDLESTATE(x)  phyIdleState,radio_param_t(x)
    00251 #else
    00252 #  define RP_IDLESTATE(x)  phyIdleState,(radio_param_t){.idle_state=x}
    00253 #endif
    00254
    00255 #if defined(DOXYGEN)
    00256
    00261 #  define RP_CCAMODE(x)
    00262 #elif defined __cplusplus
    00263 #  define RP_CCAMODE(x)  phyCCAMode,radio_param_t((ccamode_t)x)
    00264 #else
    00265 #  define RP_CCAMODE(x) phyCCAMode,(radio_param_t){.cca_mode=x}
    00266 #endif
    00267
    00268 #if defined(DOXYGEN)
    00269
    00274 #  define RP_PANID(x)
    00275 #elif defined __cplusplus
    00276 #  define RP_PANID(x) phyPanId,radio_param_t((uint16_t)x)
    00277 #else
    00278 #  define RP_PANID(x) phyPanId,(radio_param_t){.pan_id=x}
    00279 #endif
    00280
    00281 #if defined(DOXYGEN)
    00282
    00287 #  define RP_SHORTADDR(x)
    00288 #elif defined __cplusplus
    00289 #  define RP_SHORTADDR(x) phyShortAddr,radio_param_t((uint16_t)x)
    00290 #else
    00291 #  define RP_SHORTADDR(x) phyShortAddr,(radio_param_t){.short_addr=x}
    00292 #endif
    00293
    00294 #if defined(DOXYGEN)
    00295
    00300 #  define RP_LONGADDR(x)
    00301 #elif defined __cplusplus
    00302 #  define RP_LONGADDR(x) phyLongAddr,radio_param_t((uint64_t *)x)
    00303 #else
    00304 #  define RP_LONGADDR(x) phyLongAddr,(radio_param_t){.long_addr=x}
    00305 #endif
    00306
    00307 #define CRC_CCITT_UPDATE(crc, data) _crc_ccitt_update(crc, data)
    00308
    00309 #ifndef RADIO_CFG_EEOFFSET
    00310
    00311 #define RADIO_CFG_EEOFFSET (8)
    00312 #endif
    00313
    00314 #ifndef RADIO_CFG_DATA
    00315
    00316 #define RADIO_CFG_DATA {chan: 16, txp: 0, cca: 1, edt: 11, clkm: 0, crc: 0xab12}
    00317 #endif
    00318
    00319 /* === Prototypes ============================================================ */
    00320 #ifdef __cplusplus
    00321 extern "C" {
    00322 #endif
    00323
    00324
    00340 void radio_init(uint8_t * rxbuf, uint8_t rxbufsz);
    00341
    00342
    00349 void radio_force_state(radio_state_t state);
    00350
    00351
    00357 void radio_set_state(radio_state_t state);
    00358
    00372 void radio_set_param(radio_attribute_t attr, radio_param_t parm);
    00373
    00393 void radio_send_frame(uint8_t len, uint8_t *frm, uint8_t compcrc);
    00394
    00395
    00401 radio_cca_t radio_do_cca(void);
    00402
    00403
    00404
    00405 int radio_putchar(int c);
    00406 int radio_getchar(void);
    00407
    00408
    00409
    00410 /* application call back functions to radio library */
    00411
    00412
    00422 void usr_radio_error(radio_error_t err);
    00423
    00430 void usr_radio_irq(uint8_t cause);
    00431
    00432
    00459 uint8_t * usr_radio_receive_frame(uint8_t len, uint8_t *frm, uint8_t lqi, uint8_t rssi, uint8_t crc_fail);
    00460
    00461
    00468 void usr_radio_tx_done(radio_tx_done_t status);
    00469
    00470
    00471 #ifdef __cplusplus
    00472 } /* extern "C" */
    00473 #endif
    00474 #endif  /* #ifndef RADIO_H */
    00475 /* EOF */