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