as3993 ST25RU3993 Firmware
platform.h
Go to the documentation of this file.
1 /*
2  *****************************************************************************
3  * AS3993/ST25RU3993 Firmware tech@eleckits.com http://iot.eleckits.com *
4  * STMicroelectronics ST25RU3993 is an EPC Class 1 Gen 2 RFID reader IC *
5  * *
6  * IMPORTANT - PLEASE READ CAREFULLY BEFORE COPYING, INSTALLING OR USING *
7  * THE SOFTWARE. *
8  * *
9  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
10  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
11  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
12  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
13  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
14  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
15  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
16  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
17  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
18  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
19  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
20  *****************************************************************************
21  */
33 #ifndef PLATFORM_H_
34 #define PLATFORM_H_
35 
36 /*
37 ******************************************************************************
38 * INCLUDES
39 ******************************************************************************
40 */
41 #include <p24Fxxxx.h>
42 #include "Compiler.h"
43 #include "global.h"
44 #include "as3993_config.h"
45 
46 
47 /*
48 ******************************************************************************
49 * DEFINES
50 ******************************************************************************
51 */
53 #define STOP_NONE 0
54 
55 #define STOP_SGL 1
56 
57 #define STOP_CONT 2
58 
60 #define as3993Isr _INT1Interrupt
61 
63 #define timer3Isr _T3Interrupt
64 
66 #define timer4Isr _T4Interrupt
67 
69 #define ENEXTIRQ() _INT1IE = 1;
70 
72 #define DISEXTIRQ() _INT1IE = 0
73 
75 #define CLREXTIRQ() _INT1IF = 0
76 
77 
78 
80 #define EN(x) ENABLE=(x)
81 
83 #define EN_PA(x) EN_PAPIN(x)
84 
86 #define NCS(x) NCSPIN=(x)
87 
88 #define NCS_SELECT() NCS(0)
89 
90 #define NCS_DESELECT() NCS(1)
91 
92 #ifdef TUNER
93 #define SEN_TUNER_CIN(x) SEN_CINPIN(x)
94 #define SEN_TUNER_CLEN(x) SEN_CLENPIN(x)
95 #define SEN_TUNER_COUT(x) SEN_COUTPIN(x)
96 #endif
97 
99 #define MCULED(x) MCULEDPIN(x)
100 
102 #define NUMLEDS BOARD_NUMLEDS
103 #define LED1(x) LED1PIN(x)
104 #define LED2(x) LED2PIN(x)
105 #define LED3(x) LED3PIN(x)
106 #define LED4(x) LED4PIN(x)
107 
108 #define LEDON 0
109 #define LEDOFF 1
110 
111 // Select RX or TX in Direct Mode by setting a dedicated Pin to High or Low
112 #define DIRECT_MODE_ENABLE_SENDER() DM_SW_RX_TX(LOW)
113 #define DIRECT_MODE_ENABLE_RECEIVER() DM_SW_RX_TX(HIGH)
114 
115 
116 //definition of test points for debugging
117 #if FERMI
118 #define TP1(x) _LATB4=(x);
119 #elif FEMTO2 || FEMTO2_1
120 #define TP1(x) _LATB4=(x);
121 #elif RADON
122 /* not available :#define TP1(x) _LATF1=(x); */
123 #elif NEWTON
124 /* not available; */
125 #endif
126 
127 //definition of irq pins
128 #if FERMI
129 #define AS3993_PORT_INT _RB14
130 #elif FEMTO2 || FEMTO2_1
131 #define AS3993_PORT_INT _RB14
132 #elif RADON
133 #define AS3993_PORT_INT _RC4
134 #elif NEWTON
135 #define AS3993_PORT_INT _RB14
136 #endif
137 
138 /*
139 ******************************************************************************
140 * GLOBAL FUNCTIONS
141 ******************************************************************************
142 */
143 /*------------------------------------------------------------------------- */
148 void platformInit(void);
149 
150 /*------------------------------------------------------------------------- */
155 void spiInit(void);
156 
157 /*------------------------------------------------------------------------- */
160 void writeReadAS3993( const u8* wbuf, u8 wlen, u8* rbuf, u8 rlen, u8 stopMode, u8 doStart );
161 
164 void writeReadAS3993Isr( const u8 *wbuf, u8 wlen, u8* rbuf, u8 rlen );
165 
166 /*------------------------------------------------------------------------- */
170 void setPortDirect();
171 
172 /*------------------------------------------------------------------------- */
176 void setPortNormal();
177 
178 /*
179 ******************************************************************************
180 * INTERNAL DEFINES
181 * Not to be used directly, use the macros at the top of this file
182 ******************************************************************************
183 */
184 #if FERMI
185 
186 #define NCSPIN _LATB15
187 
190 #define ENABLE _LATB13
191 
193 #define EN_PAPIN(x) do{u8 r; r = as3993SingleRead(AS3993_REG_RFOUTPUTCONTROL); r = ((x==PA_ON)?(r|0x20):(r&~0x20)); as3993SingleWrite(AS3993_REG_RFOUTPUTCONTROL,r);}while(0)
194 
195 #define MCULEDPIN(x) _LATB9=(x)
196 
197 #define BOARD_NUMLEDS 3
198 #define LED1PIN(x) _LATB4=(x)
199 #define LED2PIN(x) _LATA4=(x)
200 #define LED3PIN(x) _LATB5=(x)
201 #define LED4PIN(x)
202 
203 #define PA_ON HIGH
204 #define PA_OFF LOW
205 
206 /* Definition for the Direct Mode Pins */
207 #define DM_TX _LATA1 // MOSI PIN
208 #define DM_RX(x) _LATA0=(x) // MISO PIN
209 #define DM_SW_RX_TX(x) _LATB3=(x) // SCLK PIN
210 #define DM_RX_CLK(x) _LATB14=(x) // IRQ PIN
211 
212 #elif FEMTO2
213 
214 #define NCSPIN _LATB15
215 
217 #define ENABLE _LATB8
218 
219 #define MCULEDPIN(x) _LATB4=(x)
220 
221 #define BOARD_NUMLEDS 2
222 #define LED1PIN(x) _LATA4=(x)
223 #define LED2PIN(x) _LATA2=(x)
224 #define LED3PIN(x)
225 #define LED4PIN(x)
226 
228 #define SWITCH_ANTENNA(x) _LATB2 = ((x)==2?SWITCH_ANT_P2:SWITCH_ANT_P1)
229 #define SWITCH_ANT_P1 0x0
230 #define SWITCH_ANT_P2 0x1
231 
232 #define SEN_CINPIN(x) _LATB5=(x)
233 #define SEN_CLENPIN(x)
234 #define SEN_COUTPIN(x) _LATB9=(x)
235 
236 #define PA_ON HIGH
237 #define PA_OFF LOW
238 
239 /* Definition for the Direct Mode Pins */
240 #define DM_TX _LATA1 // MOSI PIN
241 #define DM_RX(x) _LATA0=(x) // MISO PIN
242 #define DM_SW_RX_TX(x) _LATB3=(x) // SCLK PIN
243 #define DM_RX_CLK(x) _LATB14=(x) // IRQ PIN
244 
245 
246 #elif FEMTO2_1
247 
248 #define NCSPIN _LATB15
249 
251 #define ENABLE _LATB8
252 
253 #define MCULEDPIN(x) _LATB1=(x) //changed from V2.0 to V2.1
254 
255 #define BOARD_NUMLEDS 2
256 #define LED1PIN(x) _LATB0=(x) //changed from V2.0 to V2.1
257 #define LED2PIN(x) _LATA2=(x)
258 #define LED3PIN(x)
259 #define LED4PIN(x)
260 
262 #define SWITCH_ANTENNA(x) _LATB2 = ((x)==2?SWITCH_ANT_P2:SWITCH_ANT_P1)
263 #define SWITCH_ANT_P1 0x0
264 #define SWITCH_ANT_P2 0x1
265 
266 #define SEN_CINPIN(x) _LATB5=(x)
267 #define SEN_CLENPIN(x)
268 #define SEN_COUTPIN(x) _LATB9=(x)
269 
270 #define PA_ON HIGH
271 #define PA_OFF LOW
272 
273 /* Definition for the Direct Mode Pins */
274 #define DM_TX _LATA1 // MOSI PIN
275 #define DM_RX(x) _LATA0=(x) // MISO PIN
276 #define DM_SW_RX_TX(x) _LATB3=(x) // SCLK PIN
277 #define DM_RX_CLK(x) _LATB14=(x) // IRQ PIN
278 
279 #elif RADON
280 
281 #define NCSPIN _LATC5
282 
285 #define ENABLE _LATC3
286 
289 #define EN_PAPIN(x) do{u8 r;LED3PIN(x);r = as3993SingleRead(AS3993_REG_RFOUTPUTCONTROL); r = ((x==PA_ON)?(r|0x20):(r&~0x20)); as3993SingleWrite(AS3993_REG_RFOUTPUTCONTROL,r);}while(0)
290 
291 #define MCULEDPIN(x) LED1PIN(x)
292 #define ANT1LEDPIN(x) LED6PIN(x)
293 #define ANT2LEDPIN(x) LED5PIN(x)
294 #define RFDATARECEIVELED(x) LED4PIN(x)
295 #define REFLPOWERTOOHIGHLED(x) LED2PIN(x)
296 
297 #define BOARD_NUMLEDS 7
298 /* A1 is LED5(schematic) aka D13 */
299 #define LED1PIN(x) _LATA1=(x)
300 /* A8 is LED4(schematic) aka D8 */
301 #define LED2PIN(x) _LATA8=(x)
302 /* B4 is LED3(schematic) aka D9 */
303 #define LED3PIN(x) _LATB4=(x)
304 /* A4 is LED2(schematic) aka D10 */
305 #define LED4PIN(x) _LATA4=(x)
306 /* A9 is LED1(schematic) aka D7 */
307 #define LED5PIN(x) _LATA9=(x)
308 /* C6 is LED6(schematic) aka D11 */
309 #define LED6PIN(x) _LATC6=(x)
310 
312 #define SWITCH_ANTENNA(x) (_LATC7 = ((x)==2?SWITCH_ANT_P2:SWITCH_ANT_P1), ANT2LEDPIN((x)==2), ANT1LEDPIN((x)!=2))
313 #define SWITCH_ANT_P1 0x0
314 #define SWITCH_ANT_P2 0x1
315 
316 #define SEN_CINPIN(x) _LATC0=(x)
317 #define SEN_CLENPIN(x) _LATC1=(x)
318 #define SEN_COUTPIN(x) _LATC2=(x)
319 
320 #define SEN_ANT1_CINPIN(x) _LATB2=(x)
321 #define SEN_ANT1_COUTPIN(x) _LATB3=(x)
322 #define BUTTON _RA0
323 
324 
325 #define PA_ON LOW
326 #define PA_OFF HIGH
327 
328 /* Definition for the Direct Mode Pins */
329 #define DM_TX _LATB8 // MOSI PIN
330 #define DM_RX(x) _LATB7=(x) // MISO PIN
331 #define DM_SW_RX_TX(x) _LATB9=(x) // SCLK PIN
332 #define DM_RX_CLK(x) _LATC4=(x) // IRQ PIN
333 
334 
335 #elif NEWTON
336 
337 #define NCSPIN _LATB15
338 
341 #define ENABLE _LATB13
342 
344 #define EN_PAPIN(x) do{u8 r; r = as3993SingleRead(AS3993_REG_RFOUTPUTCONTROL); r = ((x==PA_ON)?(r|0x20):(r&~0x20)); as3993SingleWrite(AS3993_REG_RFOUTPUTCONTROL,r);}while(0)
345 
346 #define BUTTON _RB4
347 
348 #if AS3993DEBUG
349 #define BOARD_NUMLEDS 1
350 #define MCULEDPIN(x) LED1PIN(x)
351 #define LED1PIN(x) _LATA4=(x)
352 #define LED2PIN(x)
353 #define LED3PIN(x)
354 #define LED4PIN(x)
355 #else
356 #define BOARD_NUMLEDS 3
357 #define MCULEDPIN(x) LED1PIN(x)
358 #define ANT1LEDPIN(x) LED3PIN(x)
359 #define ANT2LEDPIN(x) LED2PIN(x)
360 
361 #define LED1PIN(x) _LATB0=(x)
362 #define LED2PIN(x) _LATB1=(x)
363 #define LED3PIN(x) _LATA4=(x)
364 #define LED4PIN(x)
365 #endif
366 
367 #define PA_ON HIGH
368 #define PA_OFF LOW
369 
370 /* Definition for the Direct Mode Pins */
371 #define DM_TX _LATA1 // MOSI PIN
372 #define DM_RX(x) _LATA0=(x) // MISO PIN
373 #define DM_SW_RX_TX(x) _LATB3=(x) // SCLK PIN
374 #define DM_RX_CLK(x) _LATB14=(x) // IRQ PIN
375 
376 #define SWITCH_ANT_A1 0x0 // Internal Antenna
377 #define SWITCH_ANT_P1 0x1 // External Antenna
378 #define SWITCH_ANTENNA(x) (_LATB9 = ((x)==2?SWITCH_ANT_A1:SWITCH_ANT_P1), ANT2LEDPIN((x)==2), ANT1LEDPIN((x)!=2))
379 
380 #endif
381 
382 #endif /* PLATFORM_H_ */
void setPortNormal()
Definition: platform.c:479
void platformInit(void)
Definition: platform.c:403
This file provides declarations for global helper functions.
void setPortDirect()
Definition: platform.c:474
void writeReadAS3993(const u8 *wbuf, u8 wlen, u8 *rbuf, u8 rlen, u8 stopMode, u8 doStart)
Definition: platform.c:442
void writeReadAS3993Isr(const u8 *wbuf, u8 wlen, u8 *rbuf, u8 rlen)
Definition: platform.c:458
void spiInit(void)
Definition: platform.c:427
Configuration file for all AS99x firmware.