Contiki 2.6

cc2530-rf.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. 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  * 3. Neither the name of the Institute 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 INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * 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 INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  */
00031 
00032 /**
00033  * \file
00034  *         Implementation of the cc2530 RF driver
00035  *
00036  * \author
00037  *         George Oikonomou - <oikonomou@users.sourceforge.net>
00038  */
00039 #ifndef __CC2530_RF_H__
00040 #define __CC2530_RF_H__
00041 
00042 #include "contiki.h"
00043 #include "dev/radio.h"
00044 #include "cc253x.h"
00045 /*---------------------------------------------------------------------------
00046  * RF Config
00047  *---------------------------------------------------------------------------*/
00048 #define CC2530_RF_TX_POWER_RECOMMENDED 0xD5
00049 #ifdef CC2530_RF_CONF_TX_POWER
00050 #define CC2530_RF_TX_POWER CC2530_RF_CONF_TX_POWER
00051 #else
00052 #define CC2530_RF_TX_POWER CC2530_RF_TX_POWER_RECOMMENDED
00053 #endif /* CC2530_RF_CONF_TX_POWER */
00054 
00055 #ifdef CC2530_RF_CONF_CCA_THRES
00056 #define CC2530_RF_CCA_THRES CC2530_RF_CONF_CCA_THRES
00057 #else
00058 #define CC2530_RF_CCA_THRES CCA_THRES_USER_GUIDE /* User guide recommendation */
00059 #endif /* CC2530_RF_CONF_CCA_THRES */
00060 
00061 #ifdef CC2530_RF_CONF_CHANNEL
00062 #define CC2530_RF_CHANNEL CC2530_RF_CONF_CHANNEL
00063 #else
00064 #define CC2530_RF_CHANNEL 18
00065 #endif /* CC2530_RF_CONF_CHANNEL */
00066 #define CC2530_RF_CHANNEL_MIN     11
00067 #define CC2530_RF_CHANNEL_MAX     26
00068 #define CC2530_RF_CHANNEL_SPACING  5
00069 
00070 #ifdef CC2530_RF_CONF_AUTOACK
00071 #define CC2530_RF_AUTOACK CC2530_RF_CONF_AUTOACK
00072 #else
00073 #define CC2530_RF_AUTOACK 1
00074 #endif /* CC2530_RF_CONF_AUTOACK */
00075 
00076 #ifdef CC2530_RF_CONF_LOW_POWER_RX
00077 #define CC2530_RF_LOW_POWER_RX CC2530_RF_CONF_LOW_POWER_RX
00078 #else
00079 #define CC2530_RF_LOW_POWER_RX 0
00080 #endif /* CC2530_RF_CONF_LOW_POWER_RX */
00081 /*---------------------------------------------------------------------------*/
00082 #define CCA_THRES_USER_GUIDE          0xF8
00083 #define CCA_THRES_ALONE               0xFC   /* -4-76=-80dBm when CC2530 operated alone or with CC2591 in LGM */
00084 #define CCA_THR_HGM                   0x06   /* 6-76=-70dBm when CC2530 operated with CC2591 in HGM */
00085 #define CORR_THR                      0x14
00086 /*---------------------------------------------------------------------------*/
00087 #define CC2530_RF_MAX_PACKET_LEN      127
00088 #define CC2530_RF_MIN_PACKET_LEN        4
00089 /*---------------------------------------------------------------------------*/
00090 #define CC2530_RF_CCA_CLEAR             1
00091 #define CC2530_RF_CCA_BUSY              0
00092 
00093 /* Wait for RSSI to be valid. */
00094 #define CC2530_RF_CCA_VALID_WAIT()  while(!(RSSISTAT & RSSIST))
00095 /*---------------------------------------------------------------------------
00096  * Command Strobe Processor
00097  *---------------------------------------------------------------------------*/
00098 /* OPCODES */
00099 #define CSP_OP_ISRXON                0xE3
00100 #define CSP_OP_ISTXON                0xE9
00101 #define CSP_OP_ISTXONCCA             0xEA
00102 #define CSP_OP_ISRFOFF               0xEF
00103 #define CSP_OP_ISFLUSHRX             0xED
00104 #define CSP_OP_ISFLUSHTX             0xEE
00105 
00106 #define CC2530_CSP_ISRXON()    do { RFST = CSP_OP_ISRXON; } while(0)
00107 #define CC2530_CSP_ISTXON()    do { RFST = CSP_OP_ISTXON; } while(0)
00108 #define CC2530_CSP_ISTXONCCA() do { RFST = CSP_OP_ISTXONCCA; } while(0)
00109 #define CC2530_CSP_ISRFOFF()   do { RFST = CSP_OP_ISRFOFF; } while(0)
00110 
00111 /* OP x 2 for flushes */
00112 #define CC2530_CSP_ISFLUSHRX()  do { \
00113   RFST = CSP_OP_ISFLUSHRX; \
00114   RFST = CSP_OP_ISFLUSHRX; \
00115 } while(0)
00116 #define CC2530_CSP_ISFLUSHTX()  do { \
00117   RFST = CSP_OP_ISFLUSHTX; \
00118   RFST = CSP_OP_ISFLUSHTX; \
00119 } while(0)
00120 /*---------------------------------------------------------------------------*/
00121 extern const struct radio_driver cc2530_rf_driver;
00122 /*---------------------------------------------------------------------------*/
00123 int8_t cc2530_rf_channel_set(uint8_t channel);
00124 #define cc2530_rf_channel_get() ((uint8_t)((FREQCTRL + 44) / 5))
00125 uint8_t cc2530_rf_power_set(uint8_t new_power);
00126 void cc2530_rf_set_addr(uint16_t pan);
00127 /*---------------------------------------------------------------------------*/
00128 #endif /* __CC2530_RF_H__ */