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_8h_source.html,v 1.1.1.4 2013/04/09 21:11:37 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 
00049 /* === Externals ============================================================= */
00050 
00051 /* === Types ================================================================= */
00052 
00058 #define  STATE_OFF (0)
00059 
00060 #define  STATE_TX (1)
00061 
00062 #define STATE_RX (2)
00063 
00064 #define STATE_TXAUTO (3)
00065 
00066 #define STATE_RXAUTO (4)
00067 
00068 #define STATE_SLEEP (5)
00069 
00070 
00072 typedef uint8_t radio_state_t;
00073 
00077 typedef enum
00078 {
00079     TX_OK,          
00080     TX_CCA_FAIL,        
00081     TX_NO_ACK,          
00082     TX_FAIL,            
00083 } radio_tx_done_t;
00084 
00085 
00089 typedef enum SHORTENUM
00090 {
00091 #if defined(CCA_BUSY)
00092 
00096     RADIO_CCA_FREE = CCA_IDLE,
00097     RADIO_CCA_BUSY = CCA_BUSY,
00098     RADIO_CCA_FAIL = 255,
00099 #else
00100 
00101     RADIO_CCA_FREE = 0,
00103     RADIO_CCA_BUSY,
00105     RADIO_CCA_FAIL
00106 #endif
00107 
00108 } radio_cca_t;
00109 
00110 
00113 typedef enum SHORTENUM
00114 {
00116     phyCurrentChannel,
00118     phyChannelsSupported,
00120     phyTransmitPower,
00122     phyIdleState,
00132     phyCCAMode,
00134     phyPanId,
00136     phyShortAddr,
00138     phyLongAddr,
00139 
00141     phyDataRate,
00142 
00143 } radio_attribute_t;
00144 
00145 
00154 typedef union radio_param_t
00155 {
00156 #if defined __cplusplus
00157 public:
00158     radio_param_t(int8_t c) { channel = c; } /* also used for txpwr_t */
00159     //radio_param_t(radio_state_t s) { idle_state = s; }
00160     radio_param_t(uint8_t m) { cca_mode = m; } /* use used for data_rate */
00161     radio_param_t(uint16_t p) { pan_id = p; } /* also used for short_addr */
00162     radio_param_t(uint64_t *la) { long_addr = la; }
00163 #endif
00164 
00165     channel_t channel;
00167     txpwr_t   tx_pwr;
00169     radio_state_t idle_state;
00171     ccamode_t cca_mode;
00173     uint16_t pan_id;
00175     uint16_t short_addr;
00177     uint64_t *long_addr;
00179     uint8_t data_rate;
00180 
00181 } radio_param_t;
00182 
00183 
00187 typedef enum SHORTENUM
00188 {
00189     #ifndef SUCCESS
00190 
00191     SUCCESS = 0,        
00192     #endif
00193     STATE_SET_FAILED = 1,   
00194     SET_PARM_FAILED,    
00195     GET_PARM_FAILED,    
00196     GENERAL_ERROR,      
00197 } radio_error_t;
00198 
00199 
00203 typedef struct
00204 {
00205     uint8_t  channel;      
00207     uint8_t  tx_pwr;       
00208     uint8_t  cca_mode;     
00209     radio_state_t state;      
00210     radio_state_t idle_state; 
00211     uint8_t  *rxframe;      
00212     uint8_t  rxframesz;     
00213 } radio_status_t;
00214 
00215 /* === Macros ================================================================ */
00216 
00220 #define VOID_RSSI (0xff)
00221 
00222 #if defined(DOXYGEN)
00223 
00227 #  define RP_CHANNEL(x)
00228 #elif defined __cplusplus
00229 #  define RP_CHANNEL(x) phyCurrentChannel,radio_param_t((channel_t)x)
00230 #else
00231 #  define RP_CHANNEL(x) phyCurrentChannel,(radio_param_t){.channel=x}
00232 #endif
00233 
00234 #if defined(DOXYGEN)
00235 
00239 #  define RP_TXPWR(x)
00240 #elif defined __cplusplus
00241 #  define RP_TXPWR(x)   phyTransmitPower,radio_param_t((txpwr_t)x)
00242 #else
00243 #  define RP_TXPWR(x)   phyTransmitPower,(radio_param_t){.tx_pwr=x}
00244 #endif
00245 
00246 #if defined(DOXYGEN)
00247 
00251 #  define RP_IDLESTATE(x)
00252 #elif defined __cplusplus
00253 #  define RP_IDLESTATE(x)  phyIdleState,radio_param_t(x)
00254 #else
00255 #  define RP_IDLESTATE(x)  phyIdleState,(radio_param_t){.idle_state=x}
00256 #endif
00257 
00258 #if defined(DOXYGEN)
00259 
00263 #  define RP_CCAMODE(x)
00264 #elif defined __cplusplus
00265 #  define RP_CCAMODE(x)  phyCCAMode,radio_param_t((ccamode_t)x)
00266 #else
00267 #  define RP_CCAMODE(x) phyCCAMode,(radio_param_t){.cca_mode=x}
00268 #endif
00269 
00270 #if defined(DOXYGEN)
00271 
00275 #  define RP_PANID(x)
00276 #elif defined __cplusplus
00277 #  define RP_PANID(x) phyPanId,radio_param_t((uint16_t)x)
00278 #else
00279 #  define RP_PANID(x) phyPanId,(radio_param_t){.pan_id=x}
00280 #endif
00281 
00282 #if defined(DOXYGEN)
00283 
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 
00299 #  define RP_LONGADDR(x)
00300 #elif defined __cplusplus
00301 #  define RP_LONGADDR(x) phyLongAddr,radio_param_t((uint64_t *)x)
00302 #else
00303 #  define RP_LONGADDR(x) phyLongAddr,(radio_param_t){.long_addr=x}
00304 #endif
00305 
00306 
00307 #if defined(DOXYGEN)
00308 
00312 #  define RP_DATARATE(x)
00313 #elif defined __cplusplus
00314 #  define RP_DATARATE(x) phyDataRate,radio_param_t((uint16_t)x)
00315 #else
00316 #  define RP_DATARATE(x) phyDataRate,(radio_param_t){.data_rate=x}
00317 #endif
00318 
00319 
00320 #define CRC_CCITT_UPDATE(crc, data) _crc_ccitt_update(crc, data)
00321 
00322 #ifndef RADIO_CFG_EEOFFSET
00323 
00324 #define RADIO_CFG_EEOFFSET (8)
00325 #endif
00326 
00327 #ifndef RADIO_CFG_DATA
00328 
00329 #define RADIO_CFG_DATA {chan: 16, txp: 0, cca: 1, edt: 11, clkm: 0, crc: 0xab12}
00330 #endif
00331 
00332 /* === Prototypes ============================================================ */
00333 #ifdef __cplusplus
00334 extern "C" {
00335 #endif
00336 
00337 
00352 void radio_init(uint8_t * rxbuf, uint8_t rxbufsz);
00353 
00354 
00360 void radio_force_state(radio_state_t state);
00361 
00362 
00367 void radio_set_state(radio_state_t state);
00368 
00392 void radio_set_param(radio_attribute_t attr, radio_param_t parm);
00393 
00412 void radio_send_frame(uint8_t len, uint8_t *frm, uint8_t compcrc);
00413 
00414 
00419 radio_cca_t radio_do_cca(void);
00420 
00421 
00422 
00423 int radio_putchar(int c);
00424 int radio_getchar(void);
00425 
00426 
00427 
00428 /* application call back functions to radio library */
00429 
00430 
00439 void usr_radio_error(radio_error_t err);
00440 
00446 void usr_radio_irq(uint8_t cause);
00447 
00473 uint8_t * usr_radio_receive_frame(uint8_t len, uint8_t *frm, uint8_t lqi, int8_t ed, uint8_t crc_fail);
00474 
00475 
00481 void usr_radio_tx_done(radio_tx_done_t status);
00482 
00483 
00484 #ifdef __cplusplus
00485 } /* extern "C" */
00486 #endif
00487 
00488 
00492 #endif  /* #ifndef RADIO_H */
00493 /* EOF */

This documentation for µracoli was generated on Tue Apr 9 2013 by  doxygen 1.7.1