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