Contiki-Inga 3.x
cc2538-rf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  */
31 /**
32  * \addtogroup cc2538
33  * @{
34  *
35  * \defgroup cc2538-rf cc2538 RF Driver
36  *
37  * Driver implementation for the cc2538 RF transceiver
38  * @{
39  *
40  * \file
41  * Header file for the cc2538 RF driver
42  */
43 #ifndef CC2538_RF_H__
44 #define CC2538_RF_H__
45 
46 #include "contiki.h"
47 #include "dev/radio.h"
48 #include "dev/rfcore.h"
49 #include "reg.h"
50 /*---------------------------------------------------------------------------
51  * RF Config
52  *---------------------------------------------------------------------------*/
53 /* Constants */
54 #define CC2538_RF_CCA_THRES_USER_GUIDE 0xF8
55 #define CC2538_RF_TX_POWER_RECOMMENDED 0xD5 /* ToDo: Determine value */
56 #define CC2538_RF_CHANNEL_MIN 11
57 #define CC2538_RF_CHANNEL_MAX 26
58 #define CC2538_RF_CHANNEL_SPACING 5
59 #define CC2538_RF_MAX_PACKET_LEN 127
60 #define CC2538_RF_MIN_PACKET_LEN 4
61 #define CC2538_RF_CCA_CLEAR 1
62 #define CC2538_RF_CCA_BUSY 0
63 /*---------------------------------------------------------------------------*/
64 #ifdef CC2538_RF_CONF_TX_POWER
65 #define CC2538_RF_TX_POWER CC2538_RF_CONF_TX_POWER
66 #else
67 #define CC2538_RF_TX_POWER CC2538_RF_TX_POWER_RECOMMENDED
68 #endif /* CC2538_RF_CONF_TX_POWER */
69 
70 #ifdef CC2538_RF_CONF_CCA_THRES
71 #define CC2538_RF_CCA_THRES CC2538_RF_CONF_CCA_THRES
72 #else
73 #define CC2538_RF_CCA_THRES CCA_THRES_USER_GUIDE /** User guide recommendation */
74 #endif /* CC2538_RF_CONF_CCA_THRES */
75 
76 #ifdef CC2538_RF_CONF_CHANNEL
77 #define CC2538_RF_CHANNEL CC2538_RF_CONF_CHANNEL
78 #else
79 #define CC2538_RF_CHANNEL 18
80 #endif /* CC2538_RF_CONF_CHANNEL */
81 
82 #ifdef CC2538_RF_CONF_AUTOACK
83 #define CC2538_RF_AUTOACK CC2538_RF_CONF_AUTOACK
84 #else
85 #define CC2538_RF_AUTOACK 1
86 #endif /* CC2538_RF_CONF_AUTOACK */
87 /*---------------------------------------------------------------------------
88  * Command Strobe Processor
89  *---------------------------------------------------------------------------*/
90 /* OPCODES */
91 #define CC2538_RF_CSP_OP_ISRXON 0xE3
92 #define CC2538_RF_CSP_OP_ISTXON 0xE9
93 #define CC2538_RF_CSP_OP_ISTXONCCA 0xEA
94 #define CC2538_RF_CSP_OP_ISRFOFF 0xEF
95 #define CC2538_RF_CSP_OP_ISFLUSHRX 0xED
96 #define CC2538_RF_CSP_OP_ISFLUSHTX 0xEE
97 
98 /**
99  * \brief Send an RX ON command strobe to the CSP
100  */
101 #define CC2538_RF_CSP_ISRXON() \
102  do { REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISRXON; } while(0)
103 
104 /**
105  * \brief Send a TX ON command strobe to the CSP
106  */
107 #define CC2538_RF_CSP_ISTXON() \
108  do { REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISTXON; } while(0)
109 
110 /**
111  * \brief Send a RF OFF command strobe to the CSP
112  */
113 #define CC2538_RF_CSP_ISRFOFF() \
114  do { REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISRFOFF; } while(0)
115 
116 /**
117  * \brief Flush the RX FIFO
118  */
119 #define CC2538_RF_CSP_ISFLUSHRX() do { \
120  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX; \
121  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX; \
122 } while(0)
123 
124 /**
125  * \brief Flush the TX FIFO
126  */
127 #define CC2538_RF_CSP_ISFLUSHTX() do { \
128  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \
129  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \
130 } while(0)
131 /*---------------------------------------------------------------------------*/
132 /** The NETSTACK data structure for the cc2538 RF driver */
133 extern const struct radio_driver cc2538_rf_driver;
134 /*---------------------------------------------------------------------------*/
135 /**
136  * \brief Set the current operating channel
137  * \param channel The desired channel as a value in [11,26]
138  * \return Returns a value in [11,26] representing the current channel
139  * or a negative value if \e channel was out of bounds
140  */
141 int8_t cc2538_rf_channel_set(uint8_t channel);
142 
143 /**
144  * \brief Get the current operating channel
145  * \return Returns a value in [11,26] representing the current channel
146  */
147 uint8_t cc2538_rf_channel_get(void);
148 
149 /**
150  * \brief Sets RF TX power
151  * \param new_power The desired power level
152  * \return The power level in use after the adjustment
153  *
154  * The value specified in \e new_power will be written directly to the
155  * RFCORE_XREG_TXPOWER register. See the datasheet for more details on
156  * possible values.
157  */
158 uint8_t cc2538_rf_power_set(uint8_t new_power);
159 
160 /**
161  * \brief Sets addresses and PAN identifier to the relevant RF hardware
162  * registers
163  * \param pan The PAN Identifier
164  *
165  * Values for short and extended addresses are not needed as parameters
166  * since they exist in the linkaddr buffer in the contiki core. They
167  * are thus simply copied over from there.
168  */
169 void cc2538_rf_set_addr(uint16_t pan);
170 
171 /**
172  * \brief Reads the current signal strength (RSSI)
173  * \return The current RSSI
174  *
175  * This function reads the current RSSI on the currently configured
176  * channel.
177  */
178 int cc2538_rf_read_rssi(void);
179 
180 /**
181  * \brief Turn promiscous mode on or off
182  * \param p If promiscous mode should be on (1) or off (0)
183  *
184  * This function turns promiscous mode on or off. In promiscous mode,
185  * every received frame is returned from the RF core. In
186  * non-promiscous mode, only broadcast frames or frames with our
187  * address as the receive address are returned from the RF core.
188  */
189 void cc2538_rf_set_promiscous_mode(char p);
190 
191 /*---------------------------------------------------------------------------*/
192 #endif /* CC2538_RF_H__ */
193 
194 /**
195  * @}
196  * @}
197  */