00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00035 #ifndef RADIO_H
00036 #define RADIO_H
00037
00038
00039 #include <stdbool.h>
00040 #include <stdio.h>
00041 #include <util/crc16.h>
00042 #include "const.h"
00043
00049
00050
00051
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
00144 phyTxPa,
00146 phyRxLna
00147
00148 } radio_attribute_t;
00149
00150
00159 typedef union radio_param_t
00160 {
00161 #if defined __cplusplus
00162 public:
00163 radio_param_t(int8_t c) { channel = c; }
00164
00165 radio_param_t(uint8_t m) { cca_mode = m; }
00166 radio_param_t(uint16_t p) { pan_id = p; }
00167 radio_param_t(uint64_t *la) { long_addr = la; }
00168 #endif
00169
00170 channel_t channel;
00172 txpwr_t tx_pwr;
00174 radio_state_t idle_state;
00176 ccamode_t cca_mode;
00178 uint16_t pan_id;
00180 uint16_t short_addr;
00182 uint64_t *long_addr;
00184 uint8_t data_rate;
00185
00187 uint8_t tx_pa;
00189 uint8_t rx_lna;
00190
00191 } radio_param_t;
00192
00193
00197 typedef enum SHORTENUM
00198 {
00199 #ifndef SUCCESS
00200
00201 SUCCESS = 0,
00202 #endif
00203 STATE_SET_FAILED = 1,
00204 SET_PARM_FAILED,
00205 GET_PARM_FAILED,
00206 GENERAL_ERROR,
00207 } radio_error_t;
00208
00209
00213 typedef struct
00214 {
00215 uint8_t channel;
00217 uint8_t tx_pwr;
00218 uint8_t cca_mode;
00219 radio_state_t state;
00220 radio_state_t idle_state;
00221 uint8_t *rxframe;
00222 uint8_t rxframesz;
00223 uint8_t tx_pa;
00224 uint8_t rx_lna;
00225 } radio_status_t;
00226
00227
00228
00232 #define VOID_RSSI (0xff)
00233
00234 #if defined(DOXYGEN)
00235
00239 # define RP_CHANNEL(x)
00240 #elif defined __cplusplus
00241 # define RP_CHANNEL(x) phyCurrentChannel,radio_param_t((channel_t)x)
00242 #else
00243 # define RP_CHANNEL(x) phyCurrentChannel,(radio_param_t){.channel=x}
00244 #endif
00245
00246 #if defined(DOXYGEN)
00247
00251 # define RP_TXPWR(x)
00252 #elif defined __cplusplus
00253 # define RP_TXPWR(x) phyTransmitPower,radio_param_t((txpwr_t)x)
00254 #else
00255 # define RP_TXPWR(x) phyTransmitPower,(radio_param_t){.tx_pwr=x}
00256 #endif
00257
00258 #if defined(DOXYGEN)
00259
00263 # define RP_IDLESTATE(x)
00264 #elif defined __cplusplus
00265 # define RP_IDLESTATE(x) phyIdleState,radio_param_t(x)
00266 #else
00267 # define RP_IDLESTATE(x) phyIdleState,(radio_param_t){.idle_state=x}
00268 #endif
00269
00270 #if defined(DOXYGEN)
00271
00275 # define RP_CCAMODE(x)
00276 #elif defined __cplusplus
00277 # define RP_CCAMODE(x) phyCCAMode,radio_param_t((ccamode_t)x)
00278 #else
00279 # define RP_CCAMODE(x) phyCCAMode,(radio_param_t){.cca_mode=x}
00280 #endif
00281
00282 #if defined(DOXYGEN)
00283
00287 # define RP_PANID(x)
00288 #elif defined __cplusplus
00289 # define RP_PANID(x) phyPanId,radio_param_t((uint16_t)x)
00290 #else
00291 # define RP_PANID(x) phyPanId,(radio_param_t){.pan_id=x}
00292 #endif
00293
00294 #if defined(DOXYGEN)
00295
00299 # define RP_SHORTADDR(x)
00300 #elif defined __cplusplus
00301 # define RP_SHORTADDR(x) phyShortAddr,radio_param_t((uint16_t)x)
00302 #else
00303 # define RP_SHORTADDR(x) phyShortAddr,(radio_param_t){.short_addr=x}
00304 #endif
00305
00306 #if defined(DOXYGEN)
00307
00311 # define RP_LONGADDR(x)
00312 #elif defined __cplusplus
00313 # define RP_LONGADDR(x) phyLongAddr,radio_param_t((uint64_t *)x)
00314 #else
00315 # define RP_LONGADDR(x) phyLongAddr,(radio_param_t){.long_addr=x}
00316 #endif
00317
00318
00319 #if defined(DOXYGEN)
00320
00324 # define RP_DATARATE(x)
00325 #elif defined __cplusplus
00326 # define RP_DATARATE(x) phyDataRate,radio_param_t((uint16_t)x)
00327 #else
00328 # define RP_DATARATE(x) phyDataRate,(radio_param_t){.data_rate=x}
00329 #endif
00330
00331 #if defined(DOXYGEN)
00332
00336 # define RP_CHANNEL(x)
00337 #elif defined __cplusplus
00338 # define RP_TX_PA(x) phyTxPa,radio_param_t((tx_pa_t)x)
00339 #else
00340 # define RP_TX_PA(x) phyTxPa,(radio_param_t){.tx_pa=x}
00341 #endif
00342
00343 #if defined(DOXYGEN)
00344
00348 # define RP_RX_LNA(x)
00349 #elif defined __cplusplus
00350 # define RP_RX_LNA(x) phyRxLna,radio_param_t((rx_lna_t)x)
00351 #else
00352 # define RP_RX_LNA(x) phyRxLna,(radio_param_t){.rx_lna=x}
00353 #endif
00354
00355 #define CRC_CCITT_UPDATE(crc, data) _crc_ccitt_update(crc, data)
00356
00357 #ifndef RADIO_CFG_EEOFFSET
00358
00359 #define RADIO_CFG_EEOFFSET (8)
00360 #endif
00361
00362 #ifndef RADIO_CFG_DATA
00363
00364 #define RADIO_CFG_DATA {chan: 16, txp: 0, cca: 1, edt: 11, clkm: 0, crc: 0xab12}
00365 #endif
00366
00367
00368 #ifdef __cplusplus
00369 extern "C" {
00370 #endif
00371
00372
00387 void radio_init(uint8_t * rxbuf, uint8_t rxbufsz);
00388
00389
00395 void radio_force_state(radio_state_t state);
00396
00397
00402 void radio_set_state(radio_state_t state);
00403
00427 void radio_set_param(radio_attribute_t attr, radio_param_t parm);
00428
00447 void radio_send_frame(uint8_t len, uint8_t *frm, uint8_t compcrc);
00448
00449
00454 radio_cca_t radio_do_cca(void);
00455
00456 int radio_putchar(int c);
00457 int radio_getchar(void);
00458
00459
00460
00461
00470 void usr_radio_error(radio_error_t err);
00471
00477 void usr_radio_irq(uint8_t cause);
00478
00504 uint8_t * usr_radio_receive_frame(uint8_t len, uint8_t *frm, uint8_t lqi, int8_t ed, uint8_t crc_fail);
00505
00506
00512 void usr_radio_tx_done(radio_tx_done_t status);
00513
00514
00515 #ifdef __cplusplus
00516 }
00517 #endif
00518
00519
00523 #endif
00524