rf230bb.h

Go to the documentation of this file.
00001 /*   Copyright (c) 2008, Swedish Institute of Computer Science
00002  *  All rights reserved.
00003  *
00004  *  Additional fixes for AVR contributed by:
00005  *
00006  *      Colin O'Flynn coflynn@newae.com
00007  *      Eric Gnoske egnoske@gmail.com
00008  *      Blake Leverett bleverett@gmail.com
00009  *      Mike Vidales mavida404@gmail.com
00010  *      Kevin Brown kbrown3@uccs.edu
00011  *      Nate Bohlmann nate@elfwerks.com
00012  *
00013  *   All rights reserved.
00014  *
00015  *   Redistribution and use in source and binary forms, with or without
00016  *   modification, are permitted provided that the following conditions are met:
00017  *
00018  *   * Redistributions of source code must retain the above copyright
00019  *     notice, this list of conditions and the following disclaimer.
00020  *   * Redistributions in binary form must reproduce the above copyright
00021  *     notice, this list of conditions and the following disclaimer in
00022  *     the documentation and/or other materials provided with the
00023  *     distribution.
00024  *   * Neither the name of the copyright holders nor the names of
00025  *     contributors may be used to endorse or promote products derived
00026  *     from this software without specific prior written permission.
00027  *
00028  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00029  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00032  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00033  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00034  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00035  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00036  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00037  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00038  *  POSSIBILITY OF SUCH DAMAGE.
00039  */
00040 /**
00041  *    \addtogroup radiorf230
00042  *   @{
00043  */
00044 /**
00045  *  \file
00046  *  \brief This file contains radio driver code.
00047  *
00048  *   $Id: rf230bb.h,v 1.6 2010/12/15 16:50:44 dak664 Exp $
00049  */
00050 
00051 #ifndef RADIO_H
00052 #define RADIO_H
00053 /*============================ INCLUDE =======================================*/
00054 #include <stdint.h>
00055 #include <stdbool.h>
00056 #include "hal.h"
00057 #if defined(__AVR_ATmega128RFA1__)
00058 #include "atmega128rfa1_registermap.h"
00059 #else
00060 #include "at86rf230_registermap.h"
00061 #endif
00062 
00063 
00064 /*============================ MACROS ========================================*/
00065 #define SUPPORTED_PART_NUMBER                   ( 2 )
00066 #define RF230_REVA                              ( 1 )
00067 #define RF230_REVB                              ( 2 )
00068 #define SUPPORTED_MANUFACTURER_ID               ( 31 )
00069 /* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */
00070 /* In non-extended mode this allows RX_START to sample the RF rssi at the end of the preamble */
00071 //#define RF230_SUPPORTED_INTERRUPT_MASK        ( 0x0C )  //disable RX_START
00072 #define RF230_SUPPORTED_INTERRUPT_MASK          ( 0x0F )
00073 
00074 #define RF230_MIN_CHANNEL                       ( 11 )
00075 #define RF230_MAX_CHANNEL                       ( 26 )
00076 #define RF230_MIN_ED_THRESHOLD                  ( 0 )
00077 #define RF230_MAX_ED_THRESHOLD                  ( 15 )
00078 #define RF230_MAX_TX_FRAME_LENGTH               ( 127 ) /**< 127 Byte PSDU. */
00079 //#define RF230_MAX_PACKET_LEN                    127
00080 
00081 #define TX_PWR_3DBM                             ( 0 )
00082 #define TX_PWR_17_2DBM                          ( 15 )
00083 
00084 #define TX_PWR_MAX                             TX_PWR_3DBM
00085 #define TX_PWR_MIN                             TX_PWR_17_2DBM
00086 #define TX_PWR_UNDEFINED                       (TX_PWR_MIN+1)
00087 
00088 
00089 #define BATTERY_MONITOR_HIGHEST_VOLTAGE         ( 15 )
00090 #define BATTERY_MONITOR_VOLTAGE_UNDER_THRESHOLD ( 0 )
00091 #define BATTERY_MONITOR_HIGH_VOLTAGE            ( 1 )
00092 #define BATTERY_MONITOR_LOW_VOLTAGE             ( 0 )
00093 
00094 #define FTN_CALIBRATION_DONE                    ( 0 )
00095 #define PLL_DCU_CALIBRATION_DONE                ( 0 )
00096 #define PLL_CF_CALIBRATION_DONE                 ( 0 )
00097 
00098 #define RC_OSC_REFERENCE_COUNT_MAX  (1.005*F_CPU*31250UL/8000000UL)
00099 #define RC_OSC_REFERENCE_COUNT_MIN  (0.995*F_CPU*31250UL/8000000UL)
00100 
00101 #ifndef RF_CHANNEL
00102 #define RF_CHANNEL              26
00103 #endif
00104 /*============================ TYPEDEFS ======================================*/
00105 
00106 /** \brief  This macro defines the start value for the RADIO_* status constants.
00107  *
00108  *          It was chosen to have this macro so that the user can define where
00109  *          the status returned from the TAT starts. This can be useful in a
00110  *          system where numerous drivers are used, and some range of status codes
00111  *          are occupied.
00112  *
00113  *  \see radio_status_t
00114  */
00115 #define RADIO_STATUS_START_VALUE                  ( 0x40 )
00116 
00117 /** \brief  This enumeration defines the possible return values for the TAT API
00118  *          functions.
00119  *
00120  *          These values are defined so that they should not collide with the
00121  *          return/status codes defined in the IEEE 802.15.4 standard.
00122  *
00123  */
00124 typedef enum{
00125     RADIO_SUCCESS = RADIO_STATUS_START_VALUE,  /**< The requested service was performed successfully. */
00126     RADIO_UNSUPPORTED_DEVICE,         /**< The connected device is not an Atmel AT86RF230. */
00127     RADIO_INVALID_ARGUMENT,           /**< One or more of the supplied function arguments are invalid. */
00128     RADIO_TIMED_OUT,                  /**< The requested service timed out. */
00129     RADIO_WRONG_STATE,                /**< The end-user tried to do an invalid state transition. */
00130     RADIO_BUSY_STATE,                 /**< The radio transceiver is busy receiving or transmitting. */
00131     RADIO_STATE_TRANSITION_FAILED,    /**< The requested state transition could not be completed. */
00132     RADIO_CCA_IDLE,                   /**< Channel is clear, available to transmit a new frame. */
00133     RADIO_CCA_BUSY,                   /**< Channel busy. */
00134     RADIO_TRX_BUSY,                   /**< Transceiver is busy receiving or transmitting data. */
00135     RADIO_BAT_LOW,                    /**< Measured battery voltage is lower than voltage threshold. */
00136     RADIO_BAT_OK,                     /**< Measured battery voltage is above the voltage threshold. */
00137     RADIO_CRC_FAILED,                 /**< The CRC failed for the actual frame. */
00138     RADIO_CHANNEL_ACCESS_FAILURE,     /**< The channel access failed during the auto mode. */
00139     RADIO_NO_ACK,                     /**< No acknowledge frame was received. */
00140 }radio_status_t;
00141 
00142 
00143 /**
00144  * \name Transaction status codes
00145  * \{
00146  */
00147 #define TRAC_SUCCESS                0
00148 #define TRAC_SUCCESS_DATA_PENDING   1
00149 #define TRAC_SUCCESS_WAIT_FOR_ACK   2
00150 #define TRAC_CHANNEL_ACCESS_FAILURE 3
00151 #define TRAC_NO_ACK                 5
00152 #define TRAC_INVALID                7
00153 /** \} */
00154 
00155 
00156 /** \brief  This enumeration defines the possible modes available for the
00157  *          Clear Channel Assessment algorithm.
00158  *
00159  *          These constants are extracted from the datasheet.
00160  *
00161  */
00162 typedef enum{
00163 //    CCA_ED                   = 0,    /**< Use energy detection above threshold mode. */ conflicts with atmega128rfa1 mcu definition
00164     CCA_ENERGY_DETECT         = 0,    /**< Use energy detection above threshold mode. */
00165     CCA_CARRIER_SENSE         = 1,    /**< Use carrier sense mode. */
00166     CCA_CARRIER_SENSE_WITH_ED = 2     /**< Use a combination of both energy detection and carrier sense. */
00167 }radio_cca_mode_t;
00168 
00169 
00170 /** \brief  This enumeration defines the possible CLKM speeds.
00171  *
00172  *          These constants are extracted from the RF230 datasheet.
00173  *
00174  */
00175 typedef enum{
00176     CLKM_DISABLED      = 0,
00177     CLKM_1MHZ          = 1,
00178     CLKM_2MHZ          = 2,
00179     CLKM_4MHZ          = 3,
00180     CLKM_8MHZ          = 4,
00181     CLKM_16MHZ         = 5
00182 }radio_clkm_speed_t;
00183 
00184 typedef void (*radio_rx_callback) (uint16_t data);
00185 
00186 
00187 /*      Hook Documentation 
00188 **      
00189 **      Sniffing Hooks:
00190 **              RF230BB_HOOK_TX_PACKET(buffer,total_len)
00191 **              RF230BB_HOOK_RX_PACKET(buf,len)
00192 **
00193 **      RF230BB_HOOK_IS_SEND_ENABLED()
00194 **      RF230BB_HOOK_RADIO_ON()
00195 **      RF230BB_HOOK_RADIO_OFF()
00196 **      
00197 */
00198 
00199 
00200 /*============================ PROTOTYPES ====================================*/
00201 
00202 const struct radio_driver rf230_driver;
00203 
00204 int rf230_init(void);
00205 void rf230_warm_reset(void);
00206 void rf230_start_sneeze(void);
00207 //int rf230_on(void);
00208 //int rf230_off(void);
00209 void rf230_set_channel(uint8_t channel);
00210 void rf230_listen_channel(uint8_t channel);
00211 uint8_t rf230_get_channel(void);
00212 void rf230_set_pan_addr(unsigned pan,unsigned addr,const uint8_t ieee_addr[8]);
00213 void rf230_set_txpower(uint8_t power);
00214 uint8_t rf230_get_txpower(void);
00215 
00216 void rf230_set_promiscuous_mode(bool isPromiscuous);
00217 bool rf230_is_ready_to_send();
00218 
00219 extern uint8_t rf230_last_correlation,rf230_last_rssi,rf230_smallest_rssi;
00220 
00221 uint8_t rf230_get_raw_rssi(void);
00222 
00223 #define rf230_rssi      rf230_get_raw_rssi
00224 
00225 #endif
00226 /** @} */
00227 /*EOF*/

Generated on Mon Apr 11 14:23:37 2011 for Contiki 2.5 by  doxygen 1.6.1