Contiki 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_CHANNEL_SET_ERROR -1
60 #define CC2538_RF_MAX_PACKET_LEN 127
61 #define CC2538_RF_MIN_PACKET_LEN 4
62 #define CC2538_RF_CCA_CLEAR 1
63 #define CC2538_RF_CCA_BUSY 0
64 /*---------------------------------------------------------------------------*/
65 #ifdef CC2538_RF_CONF_TX_POWER
66 #define CC2538_RF_TX_POWER CC2538_RF_CONF_TX_POWER
67 #else
68 #define CC2538_RF_TX_POWER CC2538_RF_TX_POWER_RECOMMENDED
69 #endif /* CC2538_RF_CONF_TX_POWER */
70 
71 #ifdef CC2538_RF_CONF_CCA_THRES
72 #define CC2538_RF_CCA_THRES CC2538_RF_CONF_CCA_THRES
73 #else
74 #define CC2538_RF_CCA_THRES CCA_THRES_USER_GUIDE /** User guide recommendation */
75 #endif /* CC2538_RF_CONF_CCA_THRES */
76 
77 #ifdef CC2538_RF_CONF_CHANNEL
78 #define CC2538_RF_CHANNEL CC2538_RF_CONF_CHANNEL
79 #else
80 #define CC2538_RF_CHANNEL 18
81 #endif /* CC2538_RF_CONF_CHANNEL */
82 
83 #ifdef CC2538_RF_CONF_AUTOACK
84 #define CC2538_RF_AUTOACK CC2538_RF_CONF_AUTOACK
85 #else
86 #define CC2538_RF_AUTOACK 1
87 #endif /* CC2538_RF_CONF_AUTOACK */
88 /*---------------------------------------------------------------------------
89  * Command Strobe Processor
90  *---------------------------------------------------------------------------*/
91 /* OPCODES */
92 #define CC2538_RF_CSP_OP_ISRXON 0xE3
93 #define CC2538_RF_CSP_OP_ISTXON 0xE9
94 #define CC2538_RF_CSP_OP_ISTXONCCA 0xEA
95 #define CC2538_RF_CSP_OP_ISRFOFF 0xEF
96 #define CC2538_RF_CSP_OP_ISFLUSHRX 0xED
97 #define CC2538_RF_CSP_OP_ISFLUSHTX 0xEE
98 
99 /**
100  * \brief Send an RX ON command strobe to the CSP
101  */
102 #define CC2538_RF_CSP_ISRXON() \
103  do { REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISRXON; } while(0)
104 
105 /**
106  * \brief Send a TX ON command strobe to the CSP
107  */
108 #define CC2538_RF_CSP_ISTXON() \
109  do { REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISTXON; } while(0)
110 
111 /**
112  * \brief Send a RF OFF command strobe to the CSP
113  */
114 #define CC2538_RF_CSP_ISRFOFF() \
115  do { REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISRFOFF; } while(0)
116 
117 /**
118  * \brief Flush the RX FIFO
119  */
120 #define CC2538_RF_CSP_ISFLUSHRX() do { \
121  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX; \
122  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX; \
123 } while(0)
124 
125 /**
126  * \brief Flush the TX FIFO
127  */
128 #define CC2538_RF_CSP_ISFLUSHTX() do { \
129  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \
130  REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \
131 } while(0)
132 /*---------------------------------------------------------------------------*/
133 /** The NETSTACK data structure for the cc2538 RF driver */
134 extern const struct radio_driver cc2538_rf_driver;
135 /*---------------------------------------------------------------------------*/
136 /**
137  * \brief Sets addresses and PAN identifier to the relevant RF hardware
138  * registers
139  * \param pan The PAN Identifier
140  *
141  * Values for short and extended addresses are not needed as parameters
142  * since they exist in the linkaddr buffer in the contiki core. They
143  * are thus simply copied over from there.
144  */
145 void cc2538_rf_set_addr(uint16_t pan);
146 
147 /**
148  * \brief Turn promiscous mode on or off
149  * \param p If promiscous mode should be on (1) or off (0)
150  *
151  * This function turns promiscous mode on or off. In promiscous mode,
152  * every received frame is returned from the RF core. In
153  * non-promiscous mode, only broadcast frames or frames with our
154  * address as the receive address are returned from the RF core.
155  */
156 void cc2538_rf_set_promiscous_mode(char p);
157 /*---------------------------------------------------------------------------*/
158 #endif /* CC2538_RF_H__ */
159 
160 /**
161  * @}
162  * @}
163  */
Header file for the radio API
void cc2538_rf_set_promiscous_mode(char p)
Turn promiscous mode on or off.
Definition: cc2538-rf.c:1020
The structure of a device driver for a radio in Contiki.
Definition: radio.h:225
struct radio_driver cc2538_rf_driver
The NETSTACK data structure for the cc2538 RF driver.
Definition: cc2538-rf.c:908
Header file with register manipulation macro definitions.
Top-level header file for cc2538 RF Core registers.
void cc2538_rf_set_addr(uint16_t pan)
Sets addresses and PAN identifier to the relevant RF hardware registers.