Appiko
hal_spi_rf_exp430g2.h
1 /******************************************************************************
2  * Filename: hal_msp_exp430g2_spi.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 #ifndef HAL_SPI_EXP430G2_H
39 #define HAL_SPI_EXP430G2_H
40 
41 #ifdef __cplusplus
42 extern "C" {
43 
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 /******************************************************************************
65  * CONSTANTS
66  */
67 
68 /* Transceiver SPI signal */
69 #define RF_PORT_SEL P1SEL
70 #define RF_PORT_SEL2 P1SEL2
71 #define RF_PORT_DIR P1DIR
72 #define RF_PORT_OUT P1OUT
73 #define RF_PORT_IN P1IN
74 
75 #define RF_MOSI_PIN BIT7
76 #define RF_MISO_PIN BIT6
77 #define RF_SCLK_PIN BIT5
78 
79 /* Transceiver chip select signal */
80 #define RF_CS_N_PORT_SEL P1SEL
81 #define RF_CS_N_PORT_DIR P1DIR
82 #define RF_CS_N_PORT_OUT P1OUT
83 #define RF_CS_N_PIN BIT4
84 
85 /* Transceiver interrupt configuration */
86 #define RF_PORT_VECTOR PORT1_VECTOR
87 #define RF_GDO_OUT P1OUT
88 #define RF_GDO_DIR P1DIR
89 #define RF_GDO_IN P1IN
90 #define RF_GDO_SEL P1SEL
91 #define RF_GDO_PxIES P1IES
92 #define RF_GDO_PxIFG P1IFG
93 #define RF_GDO_PxIE P1IE
94 #define RF_GDO_PIN BIT3
95 
96 /* Transciever optional reset signal */
97 #define RF_RESET_N_PORT_SEL P2SEL
98 #define RF_RESET_N_PORT_DIR P2DIR
99 #define RF_RESET_N_PORT_OUT P2OUT
100 #define RF_RESET_N_PIN BIT6
101 
102 /* CC1190 Control signals */
103 #define RF_LNA_EN_PxOUT P1OUT
104 #define RF_LNA_EN_PxDIR P1DIR
105 #define RF_LNA_EN_PIN BIT6
106 
107 #define RF_PA_EN_PxOUT P2OUT
108 #define RF_PA_EN_PxDIR P2DIR
109 #define RF_PA_EN_PIN BIT7
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_REN P2REN
121 #define BUTTON_PIN BIT0
122 
123 
124 /* Macro to enable LEDs */
125 #define LED1_PxOUT P1OUT
126 #define LED1_PxDIR P1DIR
127 #define LED1_PIN BIT0
128 #define LED2_PxOUT P1OUT
129 #define LED2_PxDIR P1DIR
130 #define LED2_PIN BIT0
131 #define LED3_PxOUT P1OUT
132 #define LED3_PxDIR P1DIR
133 #define LED3_PIN BIT0
134 #define LED4_PxOUT P1OUT
135 #define LED4_PxDIR P1DIR
136 #define LED4_PIN BIT0
137 
138 #define HAL_LED1_ON() LED1_PxOUT |= LED1_PIN
139 #define HAL_LED2_ON() LED2_PxOUT |= LED2_PIN
140 #define HAL_LED3_ON() LED3_PxOUT |= LED3_PIN
141 #define HAL_LED4_ON() LED4_PxOUT |= LED4_PIN
142 
143 #define HAL_LED1_OFF() LED1_PxOUT &= ~LED1_PIN
144 #define HAL_LED2_OFF() LED2_PxOUT &= ~LED2_PIN
145 #define HAL_LED3_OFF() LED3_PxOUT &= ~LED3_PIN
146 #define HAL_LED4_OFF() LED4_PxOUT &= ~LED4_PIN
147 
148 #define HAL_LED1_TOGGLE() LED1_PxOUT ^= LED1_PIN
149 #define HAL_LED2_TOGGLE() LED2_PxOUT ^= LED2_PIN
150 #define HAL_LED3_TOGGLE() LED3_PxOUT ^= LED3_PIN
151 #define HAL_LED4_TOGGLE() LED4_PxOUT ^= LED4_PIN
152 
153 
154 #define RADIO_BURST_ACCESS 0x40
155 #define RADIO_SINGLE_ACCESS 0x00
156 #define RADIO_READ_ACCESS 0x80
157 #define RADIO_WRITE_ACCESS 0x00
158 
159 /* Bit fields in the chip status byte */
160 #define STATUS_CHIP_RDYn_BM 0x80
161 #define STATUS_STATE_BM 0x70
162 #define STATUS_FIFO_BYTES_AVAILABLE_BM 0x0F
163 
164 
165 /******************************************************************************
166  * MACROS
167  */
168 
169 #define RF_SPI_BEGIN() st( RF_CS_N_PORT_OUT &= ~RF_CS_N_PIN; NOP(); )
170 #define RF_SPI_TX(x) st( IFG2 &= ~UCB0RXIFG; UCB0TXBUF = (x); )
171 #define RF_SPI_WAIT_DONE() st( while(!(IFG2 & UCB0RXIFG)); )
172 #define RF_SPI_WAIT_TX_DONE() st( while(!(IFG2 & UCB0TXIFG)); )
173 #define RF_SPI_RX() UCB0RXBUF
174 #define RF_SPI_WAIT_MISO_LOW(x) st( uint8 count = 200; \
175  while(RF_PORT_IN & RF_SPI_MISO_PIN) \
176  { \
177  __delay_cycles(5000); \
178  count--; \
179  if (count == 0) break; \
180  } \
181  if(count>0) (x) = 1; \
182  else (x) = 0; )
183 #define RF_SPI_END() st( NOP(); RF_CS_N_PORT_OUT |= RF_CS_N_PIN; )
184 
185 /******************************************************************************
186  * TYPEDEFS
187  */
188 
189 typedef struct
190 {
191 
192  uint16 addr;
193  uint8 data;
194 
195 }registerSetting_t;
196 
197 typedef uint8 rfStatus_t;
198 /******************************************************************************
199  * PROTOTYPES
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 }
211 #endif
212 
213 #endif