Contiki 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 RF230BB_H_
53 #define RF230BB_H_
54 /*============================ INCLUDE =======================================*/
55 #include <stdint.h>
56 #include <stdbool.h>
57 #include "hal.h"
58 #if defined(__AVR_ATmega128RFA1__)
60 #elif defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__)
62 #else
63 #include "at86rf230_registermap.h"
64 #endif
65 
66 
67 /*============================ MACROS ========================================*/
68 #define SUPPORTED_PART_NUMBER ( 2 )
69 #define RF230_REVA ( 1 )
70 #define RF230_REVB ( 2 )
71 #define SUPPORTED_MANUFACTURER_ID ( 31 )
72 
73 #if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__)
74 #define RF230_SUPPORTED_INTERRUPT_MASK ( 0xFF )
75 #else
76 /* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */
77 /* In non-extended mode this allows RX_START to sample the RF rssi at the end of the preamble */
78 //#define RF230_SUPPORTED_INTERRUPT_MASK ( 0x08 ) //enable trx end only
79 //#define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0F ) //disable bat low, trx underrun
80 #define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0C ) //disable bat low, trx underrun, pll lock/unlock
81 #endif
82 
83 #define RF230_MIN_CHANNEL ( 11 )
84 #define RF230_MAX_CHANNEL ( 26 )
85 #define RF230_MIN_ED_THRESHOLD ( 0 )
86 #define RF230_MAX_ED_THRESHOLD ( 15 )
87 #define RF230_MAX_TX_FRAME_LENGTH ( 127 ) /**< 127 Byte PSDU. */
88 
89 #define TX_PWR_3DBM ( 0 )
90 #define TX_PWR_17_2DBM ( 15 )
91 
92 #define TX_PWR_MAX TX_PWR_3DBM
93 #define TX_PWR_MIN TX_PWR_17_2DBM
94 #define TX_PWR_UNDEFINED (TX_PWR_MIN+1)
95 
96 
97 #define BATTERY_MONITOR_HIGHEST_VOLTAGE ( 15 )
98 #define BATTERY_MONITOR_VOLTAGE_UNDER_THRESHOLD ( 0 )
99 #define BATTERY_MONITOR_HIGH_VOLTAGE ( 1 )
100 #define BATTERY_MONITOR_LOW_VOLTAGE ( 0 )
101 
102 #define FTN_CALIBRATION_DONE ( 0 )
103 #define PLL_DCU_CALIBRATION_DONE ( 0 )
104 #define PLL_CF_CALIBRATION_DONE ( 0 )
105 
106 #define RC_OSC_REFERENCE_COUNT_MAX (1.005*F_CPU*31250UL/8000000UL)
107 #define RC_OSC_REFERENCE_COUNT_MIN (0.995*F_CPU*31250UL/8000000UL)
108 
109 #ifndef RF_CHANNEL
110 #define RF_CHANNEL 26
111 #endif
112 /*============================ TYPEDEFS ======================================*/
113 
114 /** \brief This macro defines the start value for the RADIO_* status constants.
115  *
116  * It was chosen to have this macro so that the user can define where
117  * the status returned from the TAT starts. This can be useful in a
118  * system where numerous drivers are used, and some range of status codes
119  * are occupied.
120  *
121  * \see radio_status_t
122  */
123 #define RADIO_STATUS_START_VALUE ( 0x40 )
124 
125 /** \brief This enumeration defines the possible return values for the TAT API
126  * functions.
127  *
128  * These values are defined so that they should not collide with the
129  * return/status codes defined in the IEEE 802.15.4 standard.
130  *
131  */
132 typedef enum{
133  RADIO_SUCCESS = RADIO_STATUS_START_VALUE, /**< The requested service was performed successfully. */
134  RADIO_UNSUPPORTED_DEVICE, /**< The connected device is not an Atmel AT86RF230. */
135  RADIO_INVALID_ARGUMENT, /**< One or more of the supplied function arguments are invalid. */
136  RADIO_TIMED_OUT, /**< The requested service timed out. */
137  RADIO_WRONG_STATE, /**< The end-user tried to do an invalid state transition. */
138  RADIO_BUSY_STATE, /**< The radio transceiver is busy receiving or transmitting. */
139  RADIO_STATE_TRANSITION_FAILED, /**< The requested state transition could not be completed. */
140  RADIO_CCA_IDLE, /**< Channel is clear, available to transmit a new frame. */
141  RADIO_CCA_BUSY, /**< Channel busy. */
142  RADIO_TRX_BUSY, /**< Transceiver is busy receiving or transmitting data. */
143  RADIO_BAT_LOW, /**< Measured battery voltage is lower than voltage threshold. */
144  RADIO_BAT_OK, /**< Measured battery voltage is above the voltage threshold. */
145  RADIO_CRC_FAILED, /**< The CRC failed for the actual frame. */
146  RADIO_CHANNEL_ACCESS_FAILURE, /**< The channel access failed during the auto mode. */
147  RADIO_NO_ACK, /**< No acknowledge frame was received. */
149 
150 
151 /**
152  * \name Transaction status codes
153  * \{
154  */
155 #define TRAC_SUCCESS 0
156 #define TRAC_SUCCESS_DATA_PENDING 1
157 #define TRAC_SUCCESS_WAIT_FOR_ACK 2
158 #define TRAC_CHANNEL_ACCESS_FAILURE 3
159 #define TRAC_NO_ACK 5
160 #define TRAC_INVALID 7
161 /** \} */
162 
163 
164 /** \brief This enumeration defines the possible modes available for the
165  * Clear Channel Assessment algorithm.
166  *
167  * These constants are extracted from the datasheet.
168  *
169  */
170 typedef enum{
171  CCA_ENERGY_DETECT = 0, /**< Use energy detection above threshold mode. */
172  CCA_CARRIER_SENSE = 1, /**< Use carrier sense mode. */
173  CCA_CARRIER_SENSE_WITH_ED = 2 /**< Use a combination of both energy detection and carrier sense. */
175 
176 
177 /** \brief This enumeration defines the possible CLKM speeds.
178  *
179  * These constants are extracted from the RF230 datasheet.
180  *
181  */
182 typedef enum{
183  CLKM_DISABLED = 0,
184  CLKM_1MHZ = 1,
185  CLKM_2MHZ = 2,
186  CLKM_4MHZ = 3,
187  CLKM_8MHZ = 4,
188  CLKM_16MHZ = 5
190 
191 typedef void (*radio_rx_callback) (uint16_t data);
192 
193 
194 /* Hook Documentation
195 **
196 ** Sniffing Hooks:
197 ** RF230BB_HOOK_TX_PACKET(buffer,total_len)
198 ** RF230BB_HOOK_RX_PACKET(buf,len)
199 **
200 ** RF230BB_HOOK_IS_SEND_ENABLED()
201 ** RF230BB_HOOK_RADIO_ON()
202 ** RF230BB_HOOK_RADIO_OFF()
203 **
204 */
205 
206 
207 /*============================ PROTOTYPES ====================================*/
208 
209 const struct radio_driver rf230_driver;
210 
211 int rf230_init(void);
212 void rf230_warm_reset(void);
213 void rf230_start_sneeze(void);
214 void rf230_set_channel(uint8_t channel);
215 void rf230_listen_channel(uint8_t channel);
216 uint8_t rf230_get_channel(void);
217 void rf230_set_pan_addr(unsigned pan,unsigned addr,const uint8_t ieee_addr[8]);
218 void rf230_set_txpower(uint8_t power);
219 uint8_t rf230_get_txpower(void);
220 void rf230_set_rpc(uint8_t rpc);
221 uint8_t rf230_get_rpc(void);
222 
223 void rf230_set_promiscuous_mode(bool isPromiscuous);
224 bool rf230_is_ready_to_send();
225 
226 extern uint8_t rf230_last_correlation,rf230_last_rssi,rf230_smallest_rssi;
227 
228 uint8_t rf230_get_raw_rssi(void);
229 
230 #define rf230_rssi rf230_get_raw_rssi
231 
232 #endif /* RF230BB_H_ */
233 /** @} */
234 /*EOF*/
The end-user tried to do an invalid state transition.
Definition: rf230bb.h:137
This file contains RF230-formatted register definitions for the atmega128rfa1.
#define RADIO_STATUS_START_VALUE
This macro defines the start value for the RADIO_* status constants.
Definition: rf230bb.h:123
static uip_ds6_addr_t * addr
Pointer to a router list entry.
Definition: uip-nd6.c:124
The CRC failed for the actual frame.
Definition: rf230bb.h:145
The requested service timed out.
Definition: rf230bb.h:136
The requested service was performed successfully.
Definition: rf230bb.h:133
Use a combination of both energy detection and carrier sense.
Definition: rf230bb.h:173
The structure of a device driver for a radio in Contiki.
Definition: radio.h:237
The connected device is not an Atmel AT86RF230.
Definition: rf230bb.h:134
This file contains low-level radio driver code.
radio_cca_mode_t
This enumeration defines the possible modes available for the Clear Channel Assessment algorithm...
Definition: rf230bb.h:170
The radio transceiver is busy receiving or transmitting.
Definition: rf230bb.h:138
Channel busy.
Definition: rf230bb.h:141
Measured battery voltage is lower than voltage threshold.
Definition: rf230bb.h:143
Use energy detection above threshold mode.
Definition: rf230bb.h:171
One or more of the supplied function arguments are invalid.
Definition: rf230bb.h:135
No acknowledge frame was received.
Definition: rf230bb.h:147
Measured battery voltage is above the voltage threshold.
Definition: rf230bb.h:144
The channel access failed during the auto mode.
Definition: rf230bb.h:146
radio_status_t
This enumeration defines the possible return values for the TAT API functions.
Definition: rf230bb.h:132
radio_clkm_speed_t
This enumeration defines the possible CLKM speeds.
Definition: rf230bb.h:182
This file contains RF230-formatted register definitions for the atmega128rfa1.
The requested state transition could not be completed.
Definition: rf230bb.h:139
Use carrier sense mode.
Definition: rf230bb.h:172
Channel is clear, available to transmit a new frame.
Definition: rf230bb.h:140
Transceiver is busy receiving or transmitting data.
Definition: rf230bb.h:142
This file contains the register definitions for the AT86RF230.