Contiki 2.5
radio.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, Swedish Institute of Computer Science
2  * All rights reserved.
3  *
4  * Additional fixes for AVR contributed by:
5  *
6  * Colin O'Flynn coflynn@newae.com
7  * Eric Gnoske egnoske@gmail.com
8  * Blake Leverett bleverett@gmail.com
9  * Mike Vidales mavida404@gmail.com
10  * Kevin Brown kbrown3@uccs.edu
11  * Nate Bohlmann nate@elfwerks.com
12  *
13  * All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are met:
17  *
18  * * Redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer.
20  * * Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in
22  * the documentation and/or other materials provided with the
23  * distribution.
24  * * Neither the name of the copyright holders nor the names of
25  * contributors may be used to endorse or promote products derived
26  * from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 /**
41  * \addtogroup radiorf230
42  * @{
43  */
44 /**
45  * \file
46  * \brief This file contains radio driver code.
47  *
48  * $Id: radio.h,v 1.2 2008/10/14 18:37:28 c_oflynn Exp $
49  */
50 
51 #ifndef RADIO_H
52 #define RADIO_H
53 /*============================ INCLUDE =======================================*/
54 #include <stdint.h>
55 #include <stdbool.h>
56 #include "at86rf230_registermap.h"
57 #include "hal.h"
58 
59 /*============================ MACROS ========================================*/
60 #define SUPPORTED_PART_NUMBER ( 2 )
61 #define RF230_REVA ( 1 )
62 #define RF230_REVB ( 2 )
63 #define SUPPORTED_MANUFACTURER_ID ( 31 )
64 #define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0C )
65 
66 #define RF230_MIN_CHANNEL ( 11 )
67 #define RF230_MAX_CHANNEL ( 26 )
68 #define RF230_MIN_ED_THRESHOLD ( 0 )
69 #define RF230_MAX_ED_THRESHOLD ( 15 )
70 #define RF230_MAX_TX_FRAME_LENGTH ( 127 ) /**< 127 Byte PSDU. */
71 
72 #define TX_PWR_3DBM ( 0 )
73 #define TX_PWR_17_2DBM ( 15 )
74 
75 #define BATTERY_MONITOR_HIGHEST_VOLTAGE ( 15 )
76 #define BATTERY_MONITOR_VOLTAGE_UNDER_THRESHOLD ( 0 )
77 #define BATTERY_MONITOR_HIGH_VOLTAGE ( 1 )
78 #define BATTERY_MONITOR_LOW_VOLTAGE ( 0 )
79 
80 #define FTN_CALIBRATION_DONE ( 0 )
81 #define PLL_DCU_CALIBRATION_DONE ( 0 )
82 #define PLL_CF_CALIBRATION_DONE ( 0 )
83 
84 #define RC_OSC_REFERENCE_COUNT_MAX (1.005*F_CPU*31250UL/8000000UL)
85 #define RC_OSC_REFERENCE_COUNT_MIN (0.995*F_CPU*31250UL/8000000UL)
86 /*============================ TYPEDEFS ======================================*/
87 
88 /** \brief This macro defines the start value for the RADIO_* status constants.
89  *
90  * It was chosen to have this macro so that the user can define where
91  * the status returned from the TAT starts. This can be useful in a
92  * system where numerous drivers are used, and some range of status codes
93  * are occupied.
94  *
95  * \see radio_status_t
96  */
97 #define RADIO_STATUS_START_VALUE ( 0x40 )
98 
99 /** \brief This enumeration defines the possible return values for the TAT API
100  * functions.
101  *
102  * These values are defined so that they should not collide with the
103  * return/status codes defined in the IEEE 802.15.4 standard.
104  *
105  */
106 typedef enum{
107  RADIO_SUCCESS = RADIO_STATUS_START_VALUE, /**< The requested service was performed successfully. */
108  RADIO_UNSUPPORTED_DEVICE, /**< The connected device is not an Atmel AT86RF230. */
109  RADIO_INVALID_ARGUMENT, /**< One or more of the supplied function arguments are invalid. */
110  RADIO_TIMED_OUT, /**< The requested service timed out. */
111  RADIO_WRONG_STATE, /**< The end-user tried to do an invalid state transition. */
112  RADIO_BUSY_STATE, /**< The radio transceiver is busy receiving or transmitting. */
113  RADIO_STATE_TRANSITION_FAILED, /**< The requested state transition could not be completed. */
114  RADIO_CCA_IDLE, /**< Channel is clear, available to transmit a new frame. */
115  RADIO_CCA_BUSY, /**< Channel busy. */
116  RADIO_TRX_BUSY, /**< Transceiver is busy receiving or transmitting data. */
117  RADIO_BAT_LOW, /**< Measured battery voltage is lower than voltage threshold. */
118  RADIO_BAT_OK, /**< Measured battery voltage is above the voltage threshold. */
119  RADIO_CRC_FAILED, /**< The CRC failed for the actual frame. */
120  RADIO_CHANNEL_ACCESS_FAILURE, /**< The channel access failed during the auto mode. */
121  RADIO_NO_ACK, /**< No acknowledge frame was received. */
123 
124 
125 /**
126  * \name Transaction status codes
127  * \{
128  */
129 #define TRAC_SUCCESS 0
130 #define TRAC_SUCCESS_DATA_PENDING 1
131 #define TRAC_SUCCESS_WAIT_FOR_ACK 2
132 #define TRAC_CHANNEL_ACCESS_FAILURE 3
133 #define TRAC_NO_ACK 5
134 #define TRAC_INVALID 7
135 /** \} */
136 
137 
138 /** \brief This enumeration defines the possible modes available for the
139  * Clear Channel Assessment algorithm.
140  *
141  * These constants are extracted from the datasheet.
142  *
143  */
144 typedef enum{
145  CCA_ED = 0, /**< Use energy detection above threshold mode. */
146  CCA_CARRIER_SENSE = 1, /**< Use carrier sense mode. */
147  CCA_CARRIER_SENSE_WITH_ED = 2 /**< Use a combination of both energy detection and carrier sense. */
149 
150 
151 /** \brief This enumeration defines the possible CLKM speeds.
152  *
153  * These constants are extracted from the RF230 datasheet.
154  *
155  */
156 typedef enum{
157  CLKM_DISABLED = 0,
158  CLKM_1MHZ = 1,
159  CLKM_2MHZ = 2,
160  CLKM_4MHZ = 3,
161  CLKM_8MHZ = 4,
162  CLKM_16MHZ = 5
164 
165 typedef void (*radio_rx_callback) (uint16_t data);
166 extern uint8_t rxMode;
167 /*============================ PROTOTYPES ====================================*/
168 radio_status_t radio_init(bool cal_rc_osc,
170  hal_trx_end_isr_event_handler_t trx_end_event,
171  radio_rx_callback rx_callback);
172 uint8_t radio_get_saved_rssi_value(void);
173 uint8_t radio_get_operating_channel( void );
175 uint8_t radio_get_tx_power_level( void );
176 radio_status_t radio_set_tx_power_level( uint8_t power_level );
177 
178 uint8_t radio_get_cca_mode( void );
179 uint8_t radio_get_ed_threshold( void );
180 radio_status_t radio_set_cca_mode( uint8_t mode, uint8_t ed_threshold );
181 radio_status_t radio_do_cca( void );
182 radio_status_t radio_get_rssi_value( uint8_t *rssi );
183 
184 uint8_t radio_batmon_get_voltage_threshold( void );
185 uint8_t radio_batmon_get_voltage_range( void );
186 radio_status_t radio_batmon_configure( bool range, uint8_t voltage_threshold );
188 
189 uint8_t radio_get_clock_speed( void );
190 radio_status_t radio_set_clock_speed( bool direct, uint8_t clock_speed );
193 
194 uint8_t radio_get_trx_state( void );
195 radio_status_t radio_set_trx_state( uint8_t new_state );
198 void radio_reset_state_machine( void );
199 void radio_reset_trx( void );
200 
201 void radio_use_auto_tx_crc( bool auto_crc_on );
202 radio_status_t radio_send_data( uint8_t data_length, uint8_t *data );
203 
204 uint8_t radio_get_device_role( void );
205 void radio_set_device_role( bool i_am_coordinator );
206 uint16_t radio_get_pan_id( void );
207 void radio_set_pan_id( uint16_t new_pan_id );
208 uint16_t radio_get_short_address( void );
209 void radio_set_short_address( uint16_t new_short_address );
210 void radio_get_extended_address( uint8_t *extended_address );
211 void radio_set_extended_address( uint8_t *extended_address );
212 radio_status_t radio_configure_csma( uint8_t seed0, uint8_t be_csma_seed1 );
213 bool calibrate_rc_osc_clkm(void);
214 void calibrate_rc_osc_32k(void);
215 uint8_t * radio_frame_data(void);
216 uint8_t radio_frame_length(void);
217 #define delay_us( us ) ( _delay_loop_2( ( F_CPU / 4000000UL ) * ( us ) ) )
218 
219 #endif
220 /** @} */
221 /*EOF*/