A Atmel RF2xx Radio Library for Mbed

Dependents:   xBedRadio MxSniffer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MxRadio_trx_datarate.cpp Source File

MxRadio_trx_datarate.cpp

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Axel Wachtler
00002    All rights reserved.
00003 
00004    Redistribution and use in source and binary forms, with or without
00005    modification, are permitted provided that the following conditions
00006    are met:
00007 
00008    * Redistributions of source code must retain the above copyright
00009      notice, this list of conditions and the following disclaimer.
00010    * Redistributions in binary form must reproduce the above copyright
00011      notice, this list of conditions and the following disclaimer in the
00012      documentation and/or other materials provided with the distribution.
00013    * Neither the name of the authors nor the names of its contributors
00014      may be used to endorse or promote products derived from this software
00015      without specific prior written permission.
00016 
00017    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027    POSSIBILITY OF SUCH DAMAGE. */
00028 
00029 /* $Id$ */
00030 /**
00031  * @file
00032  * @brief Chip dependent implementation of functions for setting and getting
00033  * the data rate of the transceiver.
00034  * @_addtogroup grpApp
00035  */
00036 
00037 
00038 /* === includes ============================================================ */
00039 
00040 
00041 #include <MxRadio.h>
00042 
00043 /* === functions =========================================================== */
00044 #if RADIO_TYPE ==  RADIO_AT86RF212
00045 uint8_t cMxRadio::trx_set_datarate(uint8_t rate_type)
00046 {
00047 trx_regval_t regval = TRX_NONE;
00048 
00049     switch(rate_type)
00050     {
00051         case BPSK20: regval = TRX_BPSK20; break;
00052         case BPSK40: regval = TRX_BPSK40; break;
00053         case OQPSK100: regval = TRX_OQPSK100; break;
00054         case OQPSK200: regval = TRX_OQPSK200; break;
00055         case OQPSK250: regval = TRX_OQPSK250; break;
00056         case OQPSK400: regval = TRX_OQPSK400; break;
00057         case OQPSK500: regval = TRX_OQPSK500; break;
00058         case OQPSK1000: regval = TRX_OQPSK1000; break;
00059         default: break;
00060     }
00061     if (regval != TRX_NONE)
00062     {
00063         trx_reg_write(RG_TRX_STATE, CMD_FORCE_TRX_OFF);
00064         regval |=  trx_reg_read(RG_TRX_CTRL_2) & 0xf0 ;
00065         trx_reg_write(RG_TRX_CTRL_2, regval);
00066 
00067     }
00068     else
00069     {
00070         rate_type = TRX_NONE;
00071     }
00072     return rate_type;
00073 }
00074 
00075 uint8_t cMxRadio::trx_get_datarate(void)
00076 {
00077     uint8_t rate_type, rate_code;
00078 #ifdef CHINABAND
00079     rate_code = trx_reg_read(RG_TRX_CTRL_2) & 0x1f;
00080 #else
00081     rate_code = trx_reg_read(RG_TRX_CTRL_2) & 0x0f;
00082 #endif
00083     switch(rate_code)
00084     {
00085         case TRX_BPSK20: rate_type = BPSK20; break;
00086         case TRX_BPSK40: rate_type = BPSK40; break;
00087         case TRX_OQPSK100: rate_type = OQPSK100; break;
00088         case TRX_OQPSK200: rate_type = OQPSK200; break;
00089         case TRX_OQPSK250: rate_type = OQPSK250; break;
00090         case TRX_OQPSK400: /* fall through */
00091         case TRX_OQPSK400_1: rate_type = OQPSK400; break;
00092         case TRX_OQPSK500: rate_type = OQPSK500; break;
00093         case TRX_OQPSK1000: /* fall through */
00094         case TRX_OQPSK1000_1: rate_type = OQPSK1000; break;
00095         default: rate_type = RATE_NONE; break;
00096     }
00097     return rate_type;
00098 }
00099 
00100 #elif RADIO_TYPE == RADIO_AT86RF231
00101 
00102 uint8_t cMxRadio::trx_set_datarate(uint8_t rate_type)
00103 {
00104 trx_regval_t regval = TRX_NONE;
00105 
00106     switch(rate_type)
00107     {
00108         case OQPSK250: regval = TRX_OQPSK250; break;
00109         case OQPSK500: regval = TRX_OQPSK500; break;
00110         case OQPSK1000: regval = TRX_OQPSK1000; break;
00111         case OQPSK2000: regval = TRX_OQPSK2000; break;
00112         default: break;
00113     }
00114     if (regval != TRX_NONE)
00115     {
00116         trx_reg_write(RG_TRX_STATE, CMD_FORCE_TRX_OFF);
00117         regval |=  trx_reg_read(RG_TRX_CTRL_2) & 0xfc ;
00118         trx_reg_write(RG_TRX_CTRL_2, regval);
00119     }
00120     else
00121     {
00122         rate_type = TRX_NONE;
00123     }
00124     return rate_type;
00125 }
00126 
00127 uint8_t cMxRadio::trx_get_datarate(void)
00128 {
00129 uint8_t rate_type, rate_code;
00130 
00131     rate_code = trx_reg_read(RG_TRX_CTRL_2) & 0x03;
00132 
00133     switch(rate_code)
00134     {
00135         case TRX_OQPSK250: rate_type = OQPSK250; break;
00136         case TRX_OQPSK500: rate_type = OQPSK500; break;
00137         case TRX_OQPSK1000: rate_type = OQPSK1000; break;
00138         case TRX_OQPSK2000: rate_type = OQPSK2000; break;
00139         default: rate_type = RATE_NONE; break;
00140     }
00141     return rate_type;
00142 }
00143 
00144 #else
00145 
00146 uint8_t cMxRadio::trx_set_datarate(uint8_t rate_type)
00147 {
00148 
00149     if(rate_type != OQPSK250)
00150     {
00151         rate_type = TRX_NONE;
00152     }
00153     return rate_type;
00154 }
00155 
00156 uint8_t cMxRadio::trx_get_datarate(void)
00157 {
00158     return OQPSK250;
00159 }
00160 
00161 
00162 #endif /* RADIO_TYPE == AT86RF212 */