Contiki-Inga 3.x
rf230bb.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  * David Kopf dak664@embarqmail.com
13  * Ivan Delamer delamer@ieee.com
14  *
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are met:
19  *
20  * * Redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer.
22  * * Redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in
24  * the documentation and/or other materials provided with the
25  * distribution.
26  * * Neither the name of the copyright holders nor the names of
27  * contributors may be used to endorse or promote products derived
28  * from this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40  * POSSIBILITY OF SUCH DAMAGE.
41  */
42 /**
43  * \addtogroup radiorf230
44  * @{
45  */
46 /**
47  * \file
48  * \brief This file contains radio driver code.
49  *
50  */
51 
52 #ifndef RADIO_H
53 #define RADIO_H
54 /*============================ INCLUDE =======================================*/
55 #include <stdint.h>
56 #include <stdbool.h>
57 #include "hal.h"
58 #if defined(__AVR_ATmega128RFA1__)
60 #else
61 #include "at86rf230_registermap.h"
62 #endif
63 
64 
65 /*============================ MACROS ========================================*/
66 #define SUPPORTED_PART_NUMBER ( 2 )
67 #define RF230_REVA ( 1 )
68 #define RF230_REVB ( 2 )
69 #define SUPPORTED_MANUFACTURER_ID ( 31 )
70 
71 #if defined(__AVR_ATmega128RFA1__)
72 #define RF230_SUPPORTED_INTERRUPT_MASK ( 0xFF )
73 #else
74 /* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */
75 /* In non-extended mode this allows RX_START to sample the RF rssi at the end of the preamble */
76 //#define RF230_SUPPORTED_INTERRUPT_MASK ( 0x08 ) //enable trx end only
77 //#define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0F ) //disable bat low, trx underrun
78 #define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0C ) //disable bat low, trx underrun, pll lock/unlock
79 #endif
80 
81 #define RF230_MIN_CHANNEL ( 11 )
82 #define RF230_MAX_CHANNEL ( 26 )
83 #define RF230_MIN_ED_THRESHOLD ( 0 )
84 #define RF230_MAX_ED_THRESHOLD ( 15 )
85 #define RF230_MAX_TX_FRAME_LENGTH ( 127 ) /**< 127 Byte PSDU. */
86 
87 #define TX_PWR_3DBM ( 0 )
88 #define TX_PWR_17_2DBM ( 15 )
89 
90 #define TX_PWR_MAX TX_PWR_3DBM
91 #define TX_PWR_MIN TX_PWR_17_2DBM
92 #define TX_PWR_UNDEFINED (TX_PWR_MIN+1)
93 
94 
95 #define BATTERY_MONITOR_HIGHEST_VOLTAGE ( 15 )
96 #define BATTERY_MONITOR_VOLTAGE_UNDER_THRESHOLD ( 0 )
97 #define BATTERY_MONITOR_HIGH_VOLTAGE ( 1 )
98 #define BATTERY_MONITOR_LOW_VOLTAGE ( 0 )
99 
100 #define FTN_CALIBRATION_DONE ( 0 )
101 #define PLL_DCU_CALIBRATION_DONE ( 0 )
102 #define PLL_CF_CALIBRATION_DONE ( 0 )
103 
104 #define RC_OSC_REFERENCE_COUNT_MAX (1.005*F_CPU*31250UL/8000000UL)
105 #define RC_OSC_REFERENCE_COUNT_MIN (0.995*F_CPU*31250UL/8000000UL)
106 
107 #ifndef RF_CHANNEL
108 #define RF_CHANNEL 26
109 #endif
110 /*============================ TYPEDEFS ======================================*/
111 
112 /** \brief This macro defines the start value for the RADIO_* status constants.
113  *
114  * It was chosen to have this macro so that the user can define where
115  * the status returned from the TAT starts. This can be useful in a
116  * system where numerous drivers are used, and some range of status codes
117  * are occupied.
118  *
119  * \see radio_status_t
120  */
121 #define RADIO_STATUS_START_VALUE ( 0x40 )
122 
123 /** \brief This enumeration defines the possible return values for the TAT API
124  * functions.
125  *
126  * These values are defined so that they should not collide with the
127  * return/status codes defined in the IEEE 802.15.4 standard.
128  *
129  */
130 typedef enum{
131  RADIO_SUCCESS = RADIO_STATUS_START_VALUE, /**< The requested service was performed successfully. */
132  RADIO_UNSUPPORTED_DEVICE, /**< The connected device is not an Atmel AT86RF230. */
133  RADIO_INVALID_ARGUMENT, /**< One or more of the supplied function arguments are invalid. */
134  RADIO_TIMED_OUT, /**< The requested service timed out. */
135  RADIO_WRONG_STATE, /**< The end-user tried to do an invalid state transition. */
136  RADIO_BUSY_STATE, /**< The radio transceiver is busy receiving or transmitting. */
137  RADIO_STATE_TRANSITION_FAILED, /**< The requested state transition could not be completed. */
138  RADIO_CCA_IDLE, /**< Channel is clear, available to transmit a new frame. */
139  RADIO_CCA_BUSY, /**< Channel busy. */
140  RADIO_TRX_BUSY, /**< Transceiver is busy receiving or transmitting data. */
141  RADIO_BAT_LOW, /**< Measured battery voltage is lower than voltage threshold. */
142  RADIO_BAT_OK, /**< Measured battery voltage is above the voltage threshold. */
143  RADIO_CRC_FAILED, /**< The CRC failed for the actual frame. */
144  RADIO_CHANNEL_ACCESS_FAILURE, /**< The channel access failed during the auto mode. */
145  RADIO_NO_ACK, /**< No acknowledge frame was received. */
147 
148 
149 /**
150  * \name Transaction status codes
151  * \{
152  */
153 #define TRAC_SUCCESS 0
154 #define TRAC_SUCCESS_DATA_PENDING 1
155 #define TRAC_SUCCESS_WAIT_FOR_ACK 2
156 #define TRAC_CHANNEL_ACCESS_FAILURE 3
157 #define TRAC_NO_ACK 5
158 #define TRAC_INVALID 7
159 /** \} */
160 
161 
162 /** \brief This enumeration defines the possible modes available for the
163  * Clear Channel Assessment algorithm.
164  *
165  * These constants are extracted from the datasheet.
166  *
167  */
168 typedef enum{
169  CCA_ENERGY_DETECT = 0, /**< Use energy detection above threshold mode. */
170  CCA_CARRIER_SENSE = 1, /**< Use carrier sense mode. */
171  CCA_CARRIER_SENSE_WITH_ED = 2 /**< Use a combination of both energy detection and carrier sense. */
173 
174 
175 /** \brief This enumeration defines the possible CLKM speeds.
176  *
177  * These constants are extracted from the RF230 datasheet.
178  *
179  */
180 typedef enum{
181  CLKM_DISABLED = 0,
182  CLKM_1MHZ = 1,
183  CLKM_2MHZ = 2,
184  CLKM_4MHZ = 3,
185  CLKM_8MHZ = 4,
186  CLKM_16MHZ = 5
188 
189 typedef void (*radio_rx_callback) (uint16_t data);
190 
191 
192 /* Hook Documentation
193 **
194 ** Sniffing Hooks:
195 ** RF230BB_HOOK_TX_PACKET(buffer,total_len)
196 ** RF230BB_HOOK_RX_PACKET(buf,len)
197 **
198 ** RF230BB_HOOK_IS_SEND_ENABLED()
199 ** RF230BB_HOOK_RADIO_ON()
200 ** RF230BB_HOOK_RADIO_OFF()
201 **
202 */
203 
204 
205 /*============================ PROTOTYPES ====================================*/
206 
207 const struct radio_driver rf230_driver;
208 
209 int rf230_init(void);
210 void rf230_warm_reset(void);
211 void rf230_start_sneeze(void);
212 void rf230_set_channel(uint8_t channel);
213 void rf230_listen_channel(uint8_t channel);
214 uint8_t rf230_get_channel(void);
215 void rf230_set_pan_addr(unsigned pan,unsigned addr,const uint8_t ieee_addr[8]);
216 /** Set transmission power.
217  * @param power
218  */
219 void rf230_set_txpower(uint8_t power);
220 uint8_t rf230_get_txpower(void);
221 
222 void rf230_set_promiscuous_mode(bool isPromiscuous);
223 bool rf230_is_ready_to_send();
224 
225 extern uint8_t rf230_last_correlation,rf230_last_rssi,rf230_smallest_rssi;
226 
227 uint8_t rf230_get_raw_rssi(void);
228 
229 #define rf230_rssi rf230_get_raw_rssi
230 
231 #endif
232 /** @} */
233 /*EOF*/