Contiki 2.6

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