A Atmel RF2xx Radio Library for Mbed

Dependents:   xBedRadio MxSniffer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MxRadio_trx_rf230_frame.cpp Source File

MxRadio_trx_rf230_frame.cpp

Go to the documentation of this file.
00001 /* Copyright (c) 2007 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 /*
00030  * ===========================================================================
00031  * This file contains refactored code from hif_rf230.c,
00032  * which is part of Atmels software package "IEEE 802.15.4 MAC for AVR Z-Link"
00033  * ===========================================================================
00034  */
00035 /*
00036  * Copyright (c) 2006, Atmel Corporation All rights reserved.
00037  *
00038  * Redistribution and use in source and binary forms, with or without
00039  * modification, are permitted provided that the following conditions are met:
00040  *
00041  * 1. Redistributions of source code must retain the above copyright notice,
00042  * this list of conditions and the following disclaimer.
00043  *
00044  * 2. Redistributions in binary form must reproduce the above copyright notice,
00045  * this list of conditions and the following disclaimer in the documentation
00046  * and/or other materials provided with the distribution.
00047  *
00048  * 3. The name of ATMEL may not be used to endorse or promote products derived
00049  * from this software without specific prior written permission.
00050  *
00051  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00052  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00053  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00054  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00055  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00056  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00057  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00058  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00059  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00060  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00061  */
00062 
00063 
00064 /* $Id$ */
00065 /**
00066  * @file
00067  * @brief ....
00068  * @addtogroup grpApp...
00069  */
00070 
00071 
00072 /* === includes ========================================== */
00073 
00074 #include <MxRadio.h>
00075 
00076 /* === functions ========================================= */
00077 
00078 void cMxRadio::trx_frame_write(uint8_t length, uint8_t *data)
00079 {
00080 
00081     // Select transceiver
00082     m_cs=0;//SPI_SELN_LOW();
00083 
00084     m_spi.write(TRX_CMD_FW);//SPI_DATA_REG = TRX_CMD_FW;
00085     //SPI_WAITFOR();
00086     m_spi.write(length);//SPI_DATA_REG = length;
00087 
00088     do
00089     {
00090         //SPI_WAITFOR();
00091         m_spi.write(*data++);//SPI_DATA_REG = *data++;
00092     }
00093     while (--length > 0);
00094 
00095     //SPI_WAITFOR(); /* wait here until last byte is out otherwise underrun irq */
00096 
00097     // Deselect Slave
00098     m_cs=1;//SPI_SELN_HIGH();
00099 }
00100 
00101 uint8_t cMxRadio::trx_frame_read(uint8_t *data, uint8_t datasz, uint8_t *lqi)
00102 {
00103     uint8_t length = 0;
00104     uint8_t i;
00105 
00106     /* Select transceiver */
00107     m_cs=0;//SPI_SELN_LOW();
00108 
00109     /* start frame read */
00110     m_spi.write(TRX_CMD_FR);//SPI_DATA_REG = TRX_CMD_FR;
00111     //SPI_WAITFOR();
00112 
00113     /* read length */
00114     length= m_spi.write(0);//SPI_DATA_REG = 0;
00115     //SPI_WAITFOR();
00116     //length = SPI_DATA_REG;
00117 
00118     if (length <= datasz)
00119     {
00120         i = length;
00121         do
00122         {
00123             //SPI_DATA_REG = 0;   /* dummy out */
00124             //SPI_WAITFOR();
00125             *data++ = m_spi.write(0);//SPI_DATA_REG;
00126         }
00127         while(--i);
00128 
00129         if (lqi!= NULL)
00130         {
00131             //SPI_DATA_REG = 0;   /* dummy out */
00132             //SPI_WAITFOR();
00133             *lqi = m_spi.write(0);//SPI_DATA_REG;
00134         }
00135     }
00136     else
00137     {
00138         /* we drop the frame */
00139         length = 0x80 | length;
00140     }
00141     m_cs=1;//SPI_SELN_HIGH();
00142     return length;
00143 }
00144 
00145 /* EOF */