radio.h
Go to the documentation of this file.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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef RADIO_H
00052 #define RADIO_H
00053
00054 #include <stdint.h>
00055 #include <stdbool.h>
00056 #include "at86rf230_registermap.h"
00057 #include "hal.h"
00058
00059
00060 #define SUPPORTED_PART_NUMBER ( 2 )
00061 #define RF230_REVA ( 1 )
00062 #define RF230_REVB ( 2 )
00063 #define SUPPORTED_MANUFACTURER_ID ( 31 )
00064 #define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0C )
00065
00066 #define RF230_MIN_CHANNEL ( 11 )
00067 #define RF230_MAX_CHANNEL ( 26 )
00068 #define RF230_MIN_ED_THRESHOLD ( 0 )
00069 #define RF230_MAX_ED_THRESHOLD ( 15 )
00070 #define RF230_MAX_TX_FRAME_LENGTH ( 127 )
00071
00072 #define TX_PWR_3DBM ( 0 )
00073 #define TX_PWR_17_2DBM ( 15 )
00074
00075 #define BATTERY_MONITOR_HIGHEST_VOLTAGE ( 15 )
00076 #define BATTERY_MONITOR_VOLTAGE_UNDER_THRESHOLD ( 0 )
00077 #define BATTERY_MONITOR_HIGH_VOLTAGE ( 1 )
00078 #define BATTERY_MONITOR_LOW_VOLTAGE ( 0 )
00079
00080 #define FTN_CALIBRATION_DONE ( 0 )
00081 #define PLL_DCU_CALIBRATION_DONE ( 0 )
00082 #define PLL_CF_CALIBRATION_DONE ( 0 )
00083
00084 #define RC_OSC_REFERENCE_COUNT_MAX (1.005*F_CPU*31250UL/8000000UL)
00085 #define RC_OSC_REFERENCE_COUNT_MIN (0.995*F_CPU*31250UL/8000000UL)
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #define RADIO_STATUS_START_VALUE ( 0x40 )
00098
00099
00100
00101
00102
00103
00104
00105
00106 typedef enum{
00107 RADIO_SUCCESS = RADIO_STATUS_START_VALUE,
00108 RADIO_UNSUPPORTED_DEVICE,
00109 RADIO_INVALID_ARGUMENT,
00110 RADIO_TIMED_OUT,
00111 RADIO_WRONG_STATE,
00112 RADIO_BUSY_STATE,
00113 RADIO_STATE_TRANSITION_FAILED,
00114 RADIO_CCA_IDLE,
00115 RADIO_CCA_BUSY,
00116 RADIO_TRX_BUSY,
00117 RADIO_BAT_LOW,
00118 RADIO_BAT_OK,
00119 RADIO_CRC_FAILED,
00120 RADIO_CHANNEL_ACCESS_FAILURE,
00121 RADIO_NO_ACK,
00122 }radio_status_t;
00123
00124
00125
00126
00127
00128
00129 #define TRAC_SUCCESS 0
00130 #define TRAC_SUCCESS_DATA_PENDING 1
00131 #define TRAC_SUCCESS_WAIT_FOR_ACK 2
00132 #define TRAC_CHANNEL_ACCESS_FAILURE 3
00133 #define TRAC_NO_ACK 5
00134 #define TRAC_INVALID 7
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 typedef enum{
00145 CCA_ED = 0,
00146 CCA_CARRIER_SENSE = 1,
00147 CCA_CARRIER_SENSE_WITH_ED = 2
00148 }radio_cca_mode_t;
00149
00150
00151
00152
00153
00154
00155
00156 typedef enum{
00157 CLKM_DISABLED = 0,
00158 CLKM_1MHZ = 1,
00159 CLKM_2MHZ = 2,
00160 CLKM_4MHZ = 3,
00161 CLKM_8MHZ = 4,
00162 CLKM_16MHZ = 5
00163 }radio_clkm_speed_t;
00164
00165 typedef void (*radio_rx_callback) (uint16_t data);
00166 extern uint8_t rxMode;
00167
00168 radio_status_t radio_init(bool cal_rc_osc,
00169 hal_rx_start_isr_event_handler_t rx_event,
00170 hal_trx_end_isr_event_handler_t trx_end_event,
00171 radio_rx_callback rx_callback);
00172 uint8_t radio_get_saved_rssi_value(void);
00173 uint8_t radio_get_operating_channel( void );
00174 radio_status_t radio_set_operating_channel( uint8_t channel );
00175 uint8_t radio_get_tx_power_level( void );
00176 radio_status_t radio_set_tx_power_level( uint8_t power_level );
00177
00178 uint8_t radio_get_cca_mode( void );
00179 uint8_t radio_get_ed_threshold( void );
00180 radio_status_t radio_set_cca_mode( uint8_t mode, uint8_t ed_threshold );
00181 radio_status_t radio_do_cca( void );
00182 radio_status_t radio_get_rssi_value( uint8_t *rssi );
00183
00184 uint8_t radio_batmon_get_voltage_threshold( void );
00185 uint8_t radio_batmon_get_voltage_range( void );
00186 radio_status_t radio_batmon_configure( bool range, uint8_t voltage_threshold );
00187 radio_status_t radio_batmon_get_status( void );
00188
00189 uint8_t radio_get_clock_speed( void );
00190 radio_status_t radio_set_clock_speed( bool direct, uint8_t clock_speed );
00191 radio_status_t radio_calibrate_filter( void );
00192 radio_status_t radio_calibrate_pll( void );
00193
00194 uint8_t radio_get_trx_state( void );
00195 radio_status_t radio_set_trx_state( uint8_t new_state );
00196 radio_status_t radio_enter_sleep_mode( void );
00197 radio_status_t radio_leave_sleep_mode( void );
00198 void radio_reset_state_machine( void );
00199 void radio_reset_trx( void );
00200
00201 void radio_use_auto_tx_crc( bool auto_crc_on );
00202 radio_status_t radio_send_data( uint8_t data_length, uint8_t *data );
00203
00204 uint8_t radio_get_device_role( void );
00205 void radio_set_device_role( bool i_am_coordinator );
00206 uint16_t radio_get_pan_id( void );
00207 void radio_set_pan_id( uint16_t new_pan_id );
00208 uint16_t radio_get_short_address( void );
00209 void radio_set_short_address( uint16_t new_short_address );
00210 void radio_get_extended_address( uint8_t *extended_address );
00211 void radio_set_extended_address( uint8_t *extended_address );
00212 radio_status_t radio_configure_csma( uint8_t seed0, uint8_t be_csma_seed1 );
00213 bool calibrate_rc_osc_clkm(void);
00214 void calibrate_rc_osc_32k(void);
00215 uint8_t * radio_frame_data(void);
00216 uint8_t radio_frame_length(void);
00217 #define delay_us( us ) ( _delay_loop_2( ( F_CPU / 4000000UL ) * ( us ) ) )
00218
00219 #endif
00220
00221