Appiko
hal_spi_rf_trxeb.h
1 /******************************************************************************
2 * Filename: hal_spi_rf_trxeb.h
3 *
4 * Description: Common header file for spi access to the different tranceiver
5 * radios. Supports CC1101/CC112X radios
6 *
7 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 *******************************************************************************/
38 
39 #ifndef HAL_SPI_RF_TRXEB_H
40 #define HAL_SPI_RF_TRXEB_H
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /******************************************************************************
47  * INCLUDES
48  */
49 #include <msp430.h>
50 #include "hal_types.h"
51 #include "hal_defs.h"
52 
53 
54 /******************************************************************************
55  * DEFINE THE TRANSCEIVER TO USE
56  */
57 #define USE_CC1101 /* use the CC110x transciever commands */
58 //#define USE_CC112X /* use the CC112x transciever commands */
59 #define RF_XTAL 26000 /* default is 26000 for CC1101 */
60  /* 32000 for CC1120 */
61  /* 40000 for CC1125 */
62 //#define ENABLE_RANGE_EXTENDER /* use external range extender */
63 
64 
65 /******************************************************************************
66  * CONSTANTS
67  */
68 
69 /* Transceiver SPI signal */
70 #define RF_PORT_SEL P3SEL
71 #define RF_PORT_OUT P3OUT
72 #define RF_PORT_DIR P3DIR
73 #define RF_PORT_IN P3IN
74 
75 #define RF_MOSI_PIN BIT1
76 #define RF_MISO_PIN BIT2
77 #define RF_SCLK_PIN BIT3
78 
79 /* Transceiver chip select signal */
80 #define RF_CS_N_PORT_SEL P3SEL
81 #define RF_CS_N_PORT_DIR P3DIR
82 #define RF_CS_N_PORT_OUT P3OUT
83 #define RF_CS_N_PIN BIT0
84 
85 /* Transciever optional reset signal */
86 #define RF_RESET_N_PORT_SEL P2SEL
87 #define RF_RESET_N_PORT_DIR P2DIR
88 #define RF_RESET_N_PORT_OUT P2OUT
89 #define RF_RESET_N_PIN BIT6
90 
91 /* CC1190 Control signals */
92 #define RF_LNA_EN_PxOUT P1OUT
93 #define RF_LNA_EN_PxDIR P1DIR
94 #define RF_LNA_EN_PIN BIT6
95 
96 #define RF_PA_EN_PxOUT P2OUT
97 #define RF_PA_EN_PxDIR P2DIR
98 #define RF_PA_EN_PIN BIT7
99 
100 /* Transceiver interrupt configuration */
101 #define RF_PORT_VECTOR PORT1_VECTOR
102 #define RF_GDO_OUT P1OUT
103 #define RF_GDO_DIR P1DIR
104 #define RF_GDO_IN P1IN
105 #define RF_GDO_SEL P1SEL
106 #define RF_GDO_PxIES P1IES
107 #define RF_GDO_PxIFG P1IFG
108 #define RF_GDO_PxIE P1IE
109 #define RF_GDO_PIN BIT3
110 
111 /* Optional button interrupt configuration */
112 #define BUTTON_VECTOR PORT2_VECTOR
113 #define BUTTON_OUT P2OUT
114 #define BUTTON_DIR P2DIR
115 #define BUTTON_IN P2IN
116 #define BUTTON_SEL P2SEL
117 #define BUTTON_PxIES P2IES
118 #define BUTTON_PxIFG P2IFG
119 #define BUTTON_PxIE P2IE
120 #define BUTTON_PIN BIT1
121 #define BUTTON_REN P2REN
122 
123 /* Macro to enable LEDs */
124 #define LED1_PxOUT P4OUT
125 #define LED1_PxDIR P4DIR
126 #define LED1_PIN BIT0
127 #define LED2_PxOUT P4OUT
128 #define LED2_PxDIR P4DIR
129 #define LED2_PIN BIT1
130 #define LED3_PxOUT P4OUT
131 #define LED3_PxDIR P4DIR
132 #define LED3_PIN BIT2
133 #define LED4_PxOUT P4OUT
134 #define LED4_PxDIR P4DIR
135 #define LED4_PIN BIT3
136 
137 #define HAL_LED1_OFF() LED1_PxOUT |= LED1_PIN
138 #define HAL_LED2_OFF() LED2_PxOUT |= LED2_PIN
139 #define HAL_LED3_OFF() LED3_PxOUT |= LED3_PIN
140 #define HAL_LED4_OFF() LED4_PxOUT |= LED4_PIN
141 
142 #define HAL_LED1_ON() LED1_PxOUT &= ~LED1_PIN
143 #define HAL_LED2_ON() LED2_PxOUT &= ~LED2_PIN
144 #define HAL_LED3_ON() LED3_PxOUT &= ~LED3_PIN
145 #define HAL_LED4_ON() LED4_PxOUT &= ~LED4_PIN
146 
147 #define HAL_LED1_TOGGLE() LED1_PxOUT ^= LED1_PIN
148 #define HAL_LED2_TOGGLE() LED2_PxOUT ^= LED2_PIN
149 #define HAL_LED3_TOGGLE() LED3_PxOUT ^= LED3_PIN
150 #define HAL_LED4_TOGGLE() LED4_PxOUT ^= LED4_PIN
151 
152 #define RADIO_BURST_ACCESS 0x40
153 #define RADIO_SINGLE_ACCESS 0x00
154 #define RADIO_READ_ACCESS 0x80
155 #define RADIO_WRITE_ACCESS 0x00
156 
157 /* Bit fields in the chip status byte */
158 #define STATUS_CHIP_RDYn_BM 0x80
159 #define STATUS_STATE_BM 0x70
160 #define STATUS_FIFO_BYTES_AVAILABLE_BM 0x0F
161 
162 /******************************************************************************
163  * MACROS
164  */
165 
166 /* Macros for Tranceivers(TRX) */
167 #define RF_SPI_BEGIN() st( RF_CS_N_PORT_OUT &= ~RF_CS_N_PIN; NOP(); )
168 #define RF_SPI_TX(x) st( UCB0IFG &= ~UCRXIFG; UCB0TXBUF= (x); )
169 #define RF_SPI_WAIT_DONE() st( while(!(UCB0IFG & UCRXIFG)); )
170 #define RF_SPI_WAIT_TX_DONE() st( while(!(UCB0IFG & UCTXIFG)); )
171 #define RF_SPI_RX() UCB0RXBUF
172 #define RF_SPI_WAIT_MISO_LOW(x) st( uint8 count = 200; \
173  while(RF_PORT_IN & RF_SPI_MISO_PIN) \
174  { \
175  __delay_cycles(5000); \
176  count--; \
177  if (count == 0) break; \
178  } \
179  if(count>0) (x) = 1; \
180  else (x) = 0; )
181 
182 #define RF_SPI_END() st( NOP(); RF_CS_N_PORT_OUT |= RF_CS_N_PIN; )
183 
184 
185 /******************************************************************************
186  * TYPEDEFS
187  */
188 
189 typedef struct
190 {
191  uint16 addr;
192  uint8 data;
193 }registerSetting_t;
194 
195 typedef uint8 rfStatus_t;
196 
197 /******************************************************************************
198  * PROTOTYPES
199  */
200 
201 void trxRfSpiInterfaceInit(uint8 prescalerValue);
202 rfStatus_t trx8BitRegAccess(uint8 accessType, uint8 addrByte, uint8 *pData, uint16 len);
203 rfStatus_t trxSpiCmdStrobe(uint8 cmd);
204 
205 /* CC112X specific prototype function */
206 rfStatus_t trx16BitRegAccess(uint8 accessType, uint8 extAddr, uint8 regAddr, uint8 *pData, uint8 len);
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif