Appiko
hal_spi_rf_exp5529.h
1 /******************************************************************************
2 * Filename: hal_spi_rf_exp5529.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  * DEFINE THE TRANSCEIVER TO USE
55  */
56 #define USE_CC1101 /* use the CC110x transciever commands */
57 //#define USE_CC112X /* use the CC112x transciever commands */
58 #define RF_XTAL 26000 /* default is 26000 for CC1101 */
59  /* 32000 for CC1120 */
60  /* 40000 for CC1125 */
61 //#define ENABLE_RANGE_EXTENDER /* use external range extender */
62 
63 /******************************************************************************
64  * CONSTANTS
65  */
66 
67 /* Transceiver SPI signal */
68 #define RF_PORT_SEL P3SEL
69 #define RF_PORT_OUT P3OUT
70 #define RF_PORT_DIR P3DIR
71 #define RF_PORT_IN P3IN
72 
73 #define RF_MOSI_PIN BIT0
74 #define RF_MISO_PIN BIT1
75 #define RF_SCLK_PIN BIT2
76 
77 /* Transceiver chip select signal */
78 #define RF_CS_N_PORT_SEL P2SEL
79 #define RF_CS_N_PORT_DIR P2DIR
80 #define RF_CS_N_PORT_OUT P2OUT
81 #define RF_CS_N_PIN BIT2
82 
83 /* Transciever optional reset signal */
84 #define RF_RESET_N_PORT_SEL P2SEL
85 #define RF_RESET_N_PORT_DIR P2DIR
86 #define RF_RESET_N_PORT_OUT P2OUT
87 #define RF_RESET_N_PIN BIT6
88 
89 /* CC1190 Control signals */
90 #define RF_LNA_EN_PxOUT P1OUT
91 #define RF_LNA_EN_PxDIR P1DIR
92 #define RF_LNA_EN_PIN BIT6
93 
94 #define RF_PA_EN_PxOUT P2OUT
95 #define RF_PA_EN_PxDIR P2DIR
96 #define RF_PA_EN_PIN BIT7
97 
98 /* Transceiver interrupt configuration */
99 #define RF_PORT_VECTOR PORT2_VECTOR
100 #define RF_GDO_OUT P2OUT
101 #define RF_GDO_DIR P2DIR
102 #define RF_GDO_IN P2IN
103 #define RF_GDO_SEL P2SEL
104 #define RF_GDO_PxIES P2IES
105 #define RF_GDO_PxIFG P2IFG
106 #define RF_GDO_PxIE P2IE
107 #define RF_GDO_PIN BIT0
108 
109 /* Optional button interrupt configuration */
110 #define BUTTON_VECTOR PORT1_VECTOR
111 #define BUTTON_OUT P1OUT
112 #define BUTTON_DIR P1DIR
113 #define BUTTON_IN P1IN
114 #define BUTTON_SEL P1SEL
115 #define BUTTON_PxIES P1IES
116 #define BUTTON_PxIFG P1IFG
117 #define BUTTON_PxIE P1IE
118 #define BUTTON_PIN BIT1
119 #define BUTTON_REN P1REN
120 
121 /* Macro to enable LEDs */
122 #define LED1_PxOUT P1OUT
123 #define LED1_PxDIR P1DIR
124 #define LED1_PIN BIT0
125 #define LED2_PxOUT P4OUT
126 #define LED2_PxDIR P4DIR
127 #define LED2_PIN BIT7
128 #define LED3_PxOUT P1OUT
129 #define LED3_PxDIR P1DIR
130 #define LED3_PIN BIT0
131 #define LED4_PxOUT P4OUT
132 #define LED4_PxDIR P4DIR
133 #define LED4_PIN BIT7
134 
135 #define HAL_LED1_ON() LED1_PxOUT |= LED1_PIN
136 #define HAL_LED2_ON() LED2_PxOUT |= LED2_PIN
137 #define HAL_LED3_ON() LED3_PxOUT |= LED3_PIN
138 #define HAL_LED4_ON() LED4_PxOUT |= LED4_PIN
139 
140 #define HAL_LED1_OFF() LED1_PxOUT &= ~LED1_PIN
141 #define HAL_LED2_OFF() LED2_PxOUT &= ~LED2_PIN
142 #define HAL_LED3_OFF() LED3_PxOUT &= ~LED3_PIN
143 #define HAL_LED4_OFF() LED4_PxOUT &= ~LED4_PIN
144 
145 #define HAL_LED1_TOGGLE() LED1_PxOUT ^= LED1_PIN
146 #define HAL_LED2_TOGGLE() LED2_PxOUT ^= LED2_PIN
147 #define HAL_LED3_TOGGLE() LED3_PxOUT ^= LED3_PIN
148 #define HAL_LED4_TOGGLE() LED4_PxOUT ^= LED4_PIN
149 
150 #define RADIO_BURST_ACCESS 0x40
151 #define RADIO_SINGLE_ACCESS 0x00
152 #define RADIO_READ_ACCESS 0x80
153 #define RADIO_WRITE_ACCESS 0x00
154 
155 /* Bit fields in the chip status byte */
156 #define STATUS_CHIP_RDYn_BM 0x80
157 #define STATUS_STATE_BM 0x70
158 #define STATUS_FIFO_BYTES_AVAILABLE_BM 0x0F
159 
160 /******************************************************************************
161  * Macros for Tranceivers(TRX)
162  */
163 
164 #define RF_SPI_BEGIN() st( RF_CS_N_PORT_OUT &= ~RF_CS_N_PIN; NOP(); )
165 #define RF_SPI_TX(x) st( UCB0IFG &= ~UCRXIFG; UCB0TXBUF= (x); )
166 #define RF_SPI_WAIT_DONE() st( while(!(UCB0IFG & UCRXIFG)); )
167 #define RF_SPI_WAIT_TX_DONE() st( while(!(UCB0IFG & UCTXIFG)); )
168 #define RF_SPI_RX() UCB0RXBUF
169 #define RF_SPI_WAIT_MISO_LOW(x) st( uint8 count = 200; \
170  while(RF_PORT_IN & RF_SPI_MISO_PIN) \
171  { \
172  __delay_cycles(5000); \
173  count--; \
174  if (count == 0) break; \
175  } \
176  if(count>0) (x) = 1; \
177  else (x) = 0; )
178 
179 #define RF_SPI_END() st( NOP(); RF_CS_N_PORT_OUT |= RF_CS_N_PIN; )
180 
181 /******************************************************************************
182  * TYPEDEFS
183  */
184 
185 typedef struct
186 {
187  uint16 addr;
188  uint8 data;
189 }registerSetting_t;
190 
191 typedef uint8 rfStatus_t;
192 
193 /******************************************************************************
194  * PROTOTYPES
195  */
196 
197 void trxRfSpiInterfaceInit(uint8 prescalerValue);
198 rfStatus_t trx8BitRegAccess(uint8 accessType, uint8 addrByte, uint8 *pData, uint16 len);
199 rfStatus_t trxSpiCmdStrobe(uint8 cmd);
200 
201 /* CC112X specific prototype function */
202 rfStatus_t trx16BitRegAccess(uint8 accessType, uint8 extAddr, uint8 regAddr, uint8 *pData, uint8 len);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif