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  *
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 "radio.h"
57 #include "hal.h"
58 #if defined(__AVR_ATmega128RFA1__)
59 #include "atmega128rfa1_registermap.h"
60 #else
61 #include "at86rf230_registermap.h"
62 #endif
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 /*============================ MACROS ========================================*/
69 #define SUPPORTED_PART_NUMBER (2)
70 #define RF230_REVA (1)
71 #define RF230_REVB (2)
72 #define RF230B (3)
73 #define SUPPORTED_MANUFACTURER_ID (31)
74 
75 #if defined(__AVR_ATmega128RFA1__)
76 #define RF230_SUPPORTED_INTERRUPT_MASK (0xFF)
77 #else
78 /* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */
79 /* In non-extended mode this allows RX_START to sample the RF rssi at the end of the preamble */
80 /* #define RF230_SUPPORTED_INTERRUPT_MASK ( 0x08 ) //enable trx end only */
81 /* #define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0F ) //disable bat low, trx underrun */
82 #define RF230_SUPPORTED_INTERRUPT_MASK (0x0C) /* disable bat low, trx underrun, pll lock/unlock */
83 #endif
84 
85 #define RF230_MIN_CHANNEL (11)
86 #define RF230_MAX_CHANNEL (26)
87 #define RF230_MIN_ED_THRESHOLD (0)
88 #define RF230_MAX_ED_THRESHOLD (15)
89 #define RF230_MAX_TX_FRAME_LENGTH (127) /**< 127 Byte PSDU. */
90 /* #define RF230_MAX_PACKET_LEN 127 */
91 
92 #define TX_PWR_3DBM (0)
93 #define TX_PWR_17_2DBM (15)
94 
95 #define TX_PWR_MAX TX_PWR_3DBM
96 #define TX_PWR_MIN TX_PWR_17_2DBM
97 #define TX_PWR_UNDEFINED (TX_PWR_MIN + 1)
98 
99 #define BATTERY_MONITOR_HIGHEST_VOLTAGE (15)
100 #define BATTERY_MONITOR_VOLTAGE_UNDER_THRESHOLD (0)
101 #define BATTERY_MONITOR_HIGH_VOLTAGE (1)
102 #define BATTERY_MONITOR_LOW_VOLTAGE (0)
103 
104 #define FTN_CALIBRATION_DONE (0)
105 #define PLL_DCU_CALIBRATION_DONE (0)
106 #define PLL_CF_CALIBRATION_DONE (0)
107 
108 #define RC_OSC_REFERENCE_COUNT_MAX (1.005 * F_CPU * 31250UL / 8000000UL)
109 #define RC_OSC_REFERENCE_COUNT_MIN (0.995 * F_CPU * 31250UL / 8000000UL)
110 
111 #ifndef RF_CHANNEL
112 #define RF_CHANNEL 26
113 #endif
114 /*============================ TYPEDEFS ======================================*/
115 
116 /** \brief This macro defines the start value for the RADIO_* status constants.
117  *
118  * It was chosen to have this macro so that the user can define where
119  * the status returned from the TAT starts. This can be useful in a
120  * system where numerous drivers are used, and some range of status codes
121  * are occupied.
122  *
123  * \see radio_status_t
124  */
125 #define RADIO_STATUS_START_VALUE (0x40)
126 
127 /** \brief This enumeration defines the possible return values for the TAT API
128  * functions.
129  *
130  * These values are defined so that they should not collide with the
131  * return/status codes defined in the IEEE 802.15.4 standard.
132  *
133  */
134 typedef enum {
135  RADIO_SUCCESS = RADIO_STATUS_START_VALUE, /**< The requested service was performed successfully. */
136  RADIO_UNSUPPORTED_DEVICE, /**< The connected device is not an Atmel AT86RF230. */
137  RADIO_INVALID_ARGUMENT, /**< One or more of the supplied function arguments are invalid. */
138  RADIO_TIMED_OUT, /**< The requested service timed out. */
139  RADIO_WRONG_STATE, /**< The end-user tried to do an invalid state transition. */
140  RADIO_BUSY_STATE, /**< The radio transceiver is busy receiving or transmitting. */
141  RADIO_STATE_TRANSITION_FAILED, /**< The requested state transition could not be completed. */
142  RADIO_CCA_IDLE, /**< Channel is clear, available to transmit a new frame. */
143  RADIO_CCA_BUSY, /**< Channel busy. */
144  RADIO_TRX_BUSY, /**< Transceiver is busy receiving or transmitting data. */
145  RADIO_BAT_LOW, /**< Measured battery voltage is lower than voltage threshold. */
146  RADIO_BAT_OK, /**< Measured battery voltage is above the voltage threshold. */
147  RADIO_CRC_FAILED, /**< The CRC failed for the actual frame. */
148  RADIO_CHANNEL_ACCESS_FAILURE, /**< The channel access failed during the auto mode. */
149  RADIO_NO_ACK, /**< No acknowledge frame was received. */
151 
152 /**
153  * \name Transaction status codes
154  * \{
155  */
156 #define TRAC_SUCCESS 0
157 #define TRAC_SUCCESS_DATA_PENDING 1
158 #define TRAC_SUCCESS_WAIT_FOR_ACK 2
159 #define TRAC_CHANNEL_ACCESS_FAILURE 3
160 #define TRAC_NO_ACK 5
161 #define TRAC_INVALID 7
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_ED = 0, / **< Use energy detection above threshold mode. * / conflicts with atmega128rfa1 mcu definition */
172  CCA_ENERGY_DETECT = 0, /**< Use energy detection above threshold mode. */
173  CCA_CARRIER_SENSE = 1, /**< Use carrier sense mode. */
174  CCA_CARRIER_SENSE_WITH_ED = 2 /**< Use a combination of both energy detection and carrier sense. */
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 /* Hook Documentation
194 **
195 ** Sniffing Hooks:
196 ** RF230BB_HOOK_TX_PACKET(buffer,total_len)
197 ** RF230BB_HOOK_RX_PACKET(buf,len)
198 **
199 ** RF230BB_HOOK_IS_SEND_ENABLED()
200 ** RF230BB_HOOK_RADIO_ON()
201 ** RF230BB_HOOK_RADIO_OFF()
202 **
203 */
204 
205 /*============================ PROTOTYPES ====================================*/
206 
207 extern 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 /* int rf230_on(void); */
213 /* int rf230_off(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 
221 void rf230_set_promiscuous_mode(bool isPromiscuous);
222 bool rf230_is_ready_to_send();
223 
224 extern uint8_t rf230_last_correlation, rf230_last_rssi, rf230_smallest_rssi;
225 
226 uint8_t rf230_get_raw_rssi(void);
227 
228 #define rf230_rssi rf230_get_raw_rssi
229 
230 #ifdef __cplusplus
231 } /* extern "C" */
232 #endif
233 
234 #endif
235 /** @} */
236 /*EOF*/
The requested service timed out.
Definition: radio.h:109
Measured battery voltage is lower than voltage threshold.
Definition: radio.h:116
Use carrier sense mode.
Definition: radio.h:145
Use energy detection above threshold mode.
Definition: rf230bb.h:169
Channel is clear, available to transmit a new frame.
Definition: radio.h:113
The connected device is not an Atmel AT86RF230.
Definition: radio.h:107
The structure of a device driver for a radio in Contiki.
Definition: radio.h:225
#define RADIO_STATUS_START_VALUE
This macro defines the start value for the RADIO_* status constants.
Definition: rf230bb.h:125
The requested state transition could not be completed.
Definition: radio.h:112
This file contains low-level radio driver code.
The end-user tried to do an invalid state transition.
Definition: radio.h:110
Use a combination of both energy detection and carrier sense.
Definition: radio.h:146
No acknowledge frame was received.
Definition: radio.h:120
Transceiver is busy receiving or transmitting data.
Definition: radio.h:115
radio_status_t
This enumeration defines the possible return values for the TAT API functions.
Definition: radio.h:105
The requested service was performed successfully.
Definition: radio.h:106
The radio transceiver is busy receiving or transmitting.
Definition: radio.h:111
Channel busy.
Definition: radio.h:114
radio_clkm_speed_t
This enumeration defines the possible CLKM speeds.
Definition: radio.h:155
The CRC failed for the actual frame.
Definition: radio.h:118
radio_cca_mode_t
This enumeration defines the possible modes available for the Clear Channel Assessment algorithm...
Definition: radio.h:143
One or more of the supplied function arguments are invalid.
Definition: radio.h:108
This file contains the register definitions for the AT86RF230.
The channel access failed during the auto mode.
Definition: radio.h:119
Measured battery voltage is above the voltage threshold.
Definition: radio.h:117