SRD Standelone programmation box: RFIDManager.c Source File

| SRD Standelone programmation box 2.0 (16/11/15 10:00:00) Documentation of the SRD standelone programmation box

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Enumerations Enumerator Macros Pages
RFIDManager.c
Go to the documentation of this file.
1 /*############################################################################################*/
2 /*############################################################################################*/
3 /**
4 * \file RFIDManager.c
5 * \author Thibaut LALUQUE 3D-Ouest
6 * \date 25/11/2014
7 * \version 1.0
8 * \brief Source file for RFID management.
9 * \details All Right Reserved.
10 */
11 /*############################################################################################*/
12 /*############################################################################################*/
13
14
15 /*############################################################################################*/
16 /*## INCLUDES ################################################################################*/
17 /*############################################################################################*/
18 #include "RFIDManager.h"
19 /*############################################################################################*/
20 /*## END INCLUDES ############################################################################*/
21 /*############################################################################################*/
22
23
24 /*############################################################################################*/
25 /*## LOCAL DEFINES ###########################################################################*/
26 /*############################################################################################*/
27
28 /*############################################################################################*/
29 /*## END LOCAL DEFINES ######################################################################*/
30 /*############################################################################################*/
31
32
33 /*############################################################################################*/
34 /*## LOCAL FONCTIONS DECLARATION #############################################################*/
35 /*############################################################################################*/
36 void RFIDDealer (void);
37 void RFIDIntLpmStateMachine(void);
38 void RFIDExtLpmStateMachine(void);
39 void RFIDBridgeStateMachine (void);
40 void RFIDReadStateMachine (void);
41 void RFIDWriteStateMachine (void);
42 /*############################################################################################*/
43 /*## END LOCAL FONCTIONS DECLARATION #########################################################*/
44 /*############################################################################################*/
45
46
47 /*############################################################################################*/
48 /*## LOCAL VARIABLES #########################################################################*/
49 /*############################################################################################*/
50 tRFIDPowerMode RFIDInternalPowerMode = RFID_POWERED;
51 tRFIDPowerMode RFIDExternalPowerMode = RFID_POWERED;
52 /*############################################################################################*/
53 /*## END LOCAL VARIABLES #####################################################################*/
54 /*############################################################################################*/
55
56 /*############################################################################################*/
57 /*## GLOBAL VARIABLES ########################################################################*/
58 /*############################################################################################*/
59 tRFIDCtrl RFIDCtrl;
60
61 tSRDEeprom SRDEeprom;
62 /*############################################################################################*/
63 /*## END GLOBAL VARIABLES ####################################################################*/
64 /*############################################################################################*/
65
66
67 /*############################################################################################*/
68 /*## LOCAL FONCTIONS #########################################################################*/
69 /*############################################################################################*/
70
71 /*############################################################################################*/
72 /*## END LOCAL FONCTIONS #####################################################################*/
73 /*############################################################################################*/
74
75
76 /*############################################################################################*/
77 /*## EXTERNAL FONCTIONS ######################################################################*/
78 /*############################################################################################*/
79 void RFIDManagerInit (void) {
80
81 CR95HFInit();
82 RFIDInternalPowerMode = RFID_POWERED;
83 RFIDExternalPowerMode = RFID_POWERED;
84
85 RFIDCtrl.state = RFID_STATE_STANDBY;
86
87 RFIDCtrl.lpm = RFID_WORKING;
88
89 RFIDCtrl.msRef = 0;
90
91 }
92
93 void RFIDManager (void) {
94
95 /*=== Wait for RFID ready ===*/
96 if(RFIDCtrl.state == RFID_STATE_STANDBY) {
97
98 /*=== If no request for the moment ===*/
99 if(RFIDCtrl.request.all == 0) {
100
101 if(RFIDCtrl.msRef == 0) {
102
103 /*-- Try to put all device in LPM --*/
104 if(RFIDInternalPowerMode == RFID_POWERED) {
105 RFIDCtrl.state = RFID_STATE_LOW_POWER_INT;
106 RFIDCtrl.subState = RFID_State_IntLpm_Start;
107 //RFIDCtrl.result = RFID_RESULT_OK;
108
109 } else if (CR95ExtGetConnectionState() == CR95_EXT_CONNECTED) {
110 if(RFIDExternalPowerMode == RFID_POWERED) {
111 RFIDCtrl.state = RFID_STATE_LOW_POWER_EXT;
112 RFIDCtrl.subState = RFID_State_ExtLpm_Start;
113 //RFIDCtrl.result = RFID_RESULT_OK;
114 }
115 } else {
116 RFIDExternalPowerMode = RFID_HIBERNATE;
117 }
118
119 if(RFIDExternalPowerMode == RFID_HIBERNATE && RFIDInternalPowerMode == RFID_HIBERNATE) {
120 RFIDCtrl.lpm = RFID_READY_FOR_LPM;
121 }
122
123 } else {
124
125 if(TickMilliSecElapsedFrom(RFIDCtrl.msRef) > 1000) {
126 RFIDCtrl.msRef = 0;
127 }
128
129 }
130
131 /*=== Deal request ===*/
132 } else {
133
134 RFIDCtrl.lpm = RFID_WORKING;
135
136 if(RFIDCtrl.request.bits.read) {
137 RFIDCtrl.state = RFID_STATE_READ;
138 RFIDCtrl.subState = RFID_State_Read_Start;
139 RFIDCtrl.result = RFID_RESULT_OK;
140 }
141
142 else if(RFIDCtrl.request.bits.write) {
143 RFIDCtrl.state = RFID_STATE_WRITE;
144 RFIDCtrl.subState = RFID_State_Write_Start;
145 RFIDCtrl.result = RFID_RESULT_OK;
146 }
147
148 else if(RFIDCtrl.request.bits.bridge) {
149 RFIDCtrl.state = RFID_STATE_BRIDGE;
150 RFIDCtrl.subState = RFID_State_Bridge_Start;
151 RFIDCtrl.result = RFID_RESULT_OK;
152 }
153 }
154 } else {
155 RFIDCtrl.lpm = RFID_WORKING;
156 }
157
158 RFIDDealer();
159
160 /*=== Deal CR95 Manager ===*/
161 CR95HFManager();
162 }
163
164
165 void RFIDDealer (void) {
166
167 switch(RFIDCtrl.state) {
168
169 case RFID_STATE_STANDBY :
170 //Wait state -> Do nothing
171 break;
172
173 case RFID_STATE_BRIDGE :
174 RFIDBridgeStateMachine();
175 break;
176
177 case RFID_STATE_READ :
178 RFIDReadStateMachine();
179 break;
180
181 case RFID_STATE_WRITE :
182 RFIDWriteStateMachine();
183 break;
184
185 case RFID_STATE_LOW_POWER_INT :
186 RFIDIntLpmStateMachine();
187 break;
188
189 case RFID_STATE_LOW_POWER_EXT :
190 RFIDExtLpmStateMachine();
191 break;
192
193 default :
194 RFIDCtrl.request.all = 0;
195 RFIDCtrl.state = RFID_STATE_STANDBY;
196 break;
197
198 }
199 }
200
201 void RFIDIntLpmStateMachine(void) {
202
203 switch(RFIDCtrl.subState) {
204
205 case RFID_State_IntLpm_Start :
206 CR95SelectDevice(CR95_SELECT_INTERNAL);
207 RFIDCtrl.subState = RFID_State_IntLpm_Echo;
208
209 case RFID_State_IntLpm_Echo :
210 CR95HFStartEcho();
211 RFIDCtrl.subState = RFID_State_IntLpm_WaitEcho;
212 break;
213
214 case RFID_State_IntLpm_WaitEcho :
215 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
216 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
217 RFIDCtrl.subState = RFID_State_IntLpm_FieldOff;
218 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_ECHO_ERROR) {
219 RFIDCtrl.subState = RFID_State_IntLpm_FieldOff;
220 //RFIDCtrl.result = RFID_RESULT_INTLPM_ERROR;
221 }
222 }
223 break;
224
225 case RFID_State_IntLpm_FieldOff :
226 CR95HFStartFieldOff();
227 RFIDCtrl.subState = RFID_State_IntLpm_WaitFieldOff;
228 break;
229
230 case RFID_State_IntLpm_WaitFieldOff :
231 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
232 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
233 RFIDCtrl.subState = RFID_State_IntLpm_Hibernate;
234 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_FIELDOFF_ERROR) {
235 RFIDCtrl.subState = RFID_State_IntLpm_Hibernate;
236 //RFIDCtrl.result = RFID_RESULT_INTLPM_ERROR;
237 }
238 }
239 break;
240
241 case RFID_State_IntLpm_Hibernate :
242 CR95HFStartHibernate();
243 RFIDCtrl.subState = RFID_State_IntLpm_WaitHibernate;
244 break;
245
246 case RFID_State_IntLpm_WaitHibernate :
247 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
248 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
249 RFIDCtrl.subState = RFID_State_IntLpm_Finish;
250 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_HIBERNATE_ERROR) {
251 RFIDCtrl.subState = RFID_State_IntLpm_Finish;
252 //RFIDCtrl.result = RFID_RESULT_INTLPM_ERROR;
253 }
254 }
255 break;
256
257 case RFID_State_IntLpm_Finish :
258 RFIDInternalPowerMode = RFID_HIBERNATE;
259 RFIDCtrl.state = RFID_STATE_STANDBY;
260 break;
261
262 default :
263 RFIDCtrl.subState = RFID_State_IntLpm_Start;
264 break;
265 }
266 }
267
268 void RFIDExtLpmStateMachine(void) {
269
270 switch(RFIDCtrl.subState) {
271
272 case RFID_State_ExtLpm_Start :
273 CR95SelectDevice(CR95_SELECT_EXTERNAL);
274 RFIDCtrl.subState = RFID_State_ExtLpm_Echo;
275
276 case RFID_State_ExtLpm_Echo :
277 CR95HFStartEcho();
278 RFIDCtrl.subState = RFID_State_ExtLpm_WaitEcho;
279 break;
280
281 case RFID_State_ExtLpm_WaitEcho :
282 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
283 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK ) {
284 RFIDCtrl.subState = RFID_State_ExtLpm_FieldOff;
285 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_ECHO_ERROR) {
286 RFIDCtrl.subState = RFID_State_ExtLpm_FieldOff;
287 //RFIDCtrl.result = RFID_RESULT_EXTLPM_ERROR;
288 }
289 }
290 break;
291
292 case RFID_State_ExtLpm_FieldOff :
293 CR95HFStartFieldOff();
294 RFIDCtrl.subState = RFID_State_ExtLpm_WaitFieldOff;
295 break;
296
297 case RFID_State_ExtLpm_WaitFieldOff :
298 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
299 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK ) {
300 RFIDCtrl.subState = RFID_State_ExtLpm_Hibernate;
301 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_FIELDOFF_ERROR) {
302 RFIDCtrl.subState = RFID_State_ExtLpm_Hibernate;
303 //RFIDCtrl.result = RFID_RESULT_EXTLPM_ERROR;
304 }
305 }
306 break;
307
308 case RFID_State_ExtLpm_Hibernate :
309 CR95HFStartHibernate();
310 RFIDCtrl.subState = RFID_State_ExtLpm_WaitHibernate;
311 break;
312
313 case RFID_State_ExtLpm_WaitHibernate :
314 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
315 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
316 RFIDCtrl.subState = RFID_State_ExtLpm_Finish;
317 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_HIBERNATE_ERROR) {
318 RFIDCtrl.subState = RFID_State_ExtLpm_Finish;
319 //RFIDCtrl.result = RFID_RESULT_EXTLPM_ERROR;
320 }
321 }
322 break;
323
324 case RFID_State_ExtLpm_Finish :
325 RFIDExternalPowerMode = RFID_HIBERNATE;
326 RFIDCtrl.state = RFID_STATE_STANDBY;
327 break;
328
329 default :
330 RFIDCtrl.subState = RFID_State_ExtLpm_Start;
331 break;
332 }
333 }
334
335 void RFIDBridgeStateMachine(void) {
336 static unsigned long msRef = 0;
337
338 switch(RFIDCtrl.subState) {
339
340 case RFID_State_Bridge_Start :
341 RFIDCtrl.subState = RFID_State_Bridge_Antenna;
342
343 case RFID_State_Bridge_Antenna :
344 CR95SelectDevice(CR95_SELECT_EXTERNAL);
345 CR95UartDisableReceiver();
346 char data[1] = {0x55};
347 CR95UartSendData(data,1); //Try to wake up external
348 msRef = TickGetMsCounter();
349 RFIDCtrl.subState = RFID_State_Bridge_WaitAntenna;
350 break;
351
352 case RFID_State_Bridge_WaitAntenna :
353 if(TickMilliSecElapsedFrom(msRef)>10) {
354 if(CR95ExtGetConnectionState() == CR95_EXT_CONNECTED) {
355 CR95SelectDevice(CR95_SELECT_EXTERNAL);
356 RFIDExternalPowerMode = RFID_POWERED;
357 } else {
358 CR95SelectDevice(CR95_SELECT_INTERNAL);
359 RFIDInternalPowerMode = RFID_POWERED;
360 }
361 RFIDCtrl.subState = RFID_State_Bridge_Echo;
362 }
363 break;
364
365
366 case RFID_State_Bridge_Echo :
367 CR95HFStartEcho();
368 RFIDCtrl.subState = RFID_State_Bridge_WaitEcho;
369 break;
370
371 case RFID_State_Bridge_WaitEcho :
372 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
373 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK ) {
374 RFIDCtrl.subState = RFID_State_Bridge_FieldOn;
375 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_ECHO_ERROR) {
376 RFIDCtrl.subState = RFID_State_Bridge_SendError;
377 RFIDCtrl.result = RFID_RESULT_BRIDGE_ERROR;
378 }
379 }
380 break;
381
382 case RFID_State_Bridge_FieldOn :
383 CR95HFStartField15693();
384 RFIDCtrl.subState = RFID_State_Bridge_WaitFieldOn;
385 break;
386
387 case RFID_State_Bridge_WaitFieldOn :
388 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
389 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
390 RFIDCtrl.subState = RFID_State_Bridge_Transfert;
391 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_FIELD15693_ERROR) {
392 RFIDCtrl.subState = RFID_State_Bridge_SendError;
393 RFIDCtrl.result = RFID_RESULT_BRIDGE_ERROR;
394 }
395 }
396 break;
397
398 case RFID_State_Bridge_Transfert :
399 CR95HFStartBridge(RFIDCtrl.bridgeCommand, RFIDCtrl.bridgeCommandLength);
400 RFIDCtrl.subState = RFID_State_Bridge_WaitTransfert;
401 break;
402
403 case RFID_State_Bridge_WaitTransfert :
404 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
405 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
406 RFIDCtrl.subState = RFID_State_Bridge_SendResult;
407 } else {
408 RFIDCtrl.subState = RFID_State_Bridge_SendError;
409 RFIDCtrl.result = RFID_RESULT_BRIDGE_ERROR;
410 }
411 }
412 break;
413
414 case RFID_State_Bridge_SendResult :
415 UsbManagerSendCR95Result(CR95HFCtrl.receiveBuf, CR95HFCtrl.rxPos);
416 RFIDCtrl.subState = RFID_State_Bridge_Finish;
417 break;
418
419 case RFID_State_Bridge_SendError :
420 UsbManagerSendCR95Error();
421 RFIDCtrl.subState = RFID_State_Bridge_Finish;
422 break;
423
424 case RFID_State_Bridge_Finish :
425 RFIDCtrl.request.bits.bridge = 0;
426 RFIDCtrl.msRef = TickGetMsCounter();
427 RFIDCtrl.state = RFID_STATE_STANDBY;
428 break;
429
430 default :
431 RFIDCtrl.subState = RFID_State_Bridge_Start;
432 break;
433 }
434 }
435
436 void RFIDReadStateMachine(void) {
437 static unsigned short addr = 0;
438 static unsigned long msRef = 0;
439
440 switch(RFIDCtrl.subState) {
441
442 case RFID_State_Read_Start :
443 addr = 0;
444 RFIDCtrl.subState = RFID_State_Read_Antenna;
445
446 case RFID_State_Read_Antenna :
447 CR95SelectDevice(CR95_SELECT_EXTERNAL);
448 CR95UartDisableReceiver();
449 char data[1] = {0x55};
450 CR95UartSendData(data,1); //Try to wake up external
451 msRef = TickGetMsCounter();
452 RFIDCtrl.subState = RFID_State_Read_WaitAntenna;
453 break;
454
455 case RFID_State_Read_WaitAntenna :
456 if(TickMilliSecElapsedFrom(msRef)>10) {
457 if(CR95ExtGetConnectionState() == CR95_EXT_CONNECTED) {
458 CR95SelectDevice(CR95_SELECT_EXTERNAL);
459 RFIDExternalPowerMode = RFID_POWERED;
460 } else {
461 CR95SelectDevice(CR95_SELECT_INTERNAL);
462 RFIDInternalPowerMode = RFID_POWERED;
463 }
464 RFIDCtrl.subState = RFID_State_Read_Echo;
465 }
466 break;
467
468 case RFID_State_Read_Echo :
469 CR95HFStartEcho();
470 RFIDCtrl.subState = RFID_State_Read_WaitEcho;
471 break;
472
473 case RFID_State_Read_WaitEcho :
474 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
475 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
476 RFIDCtrl.subState = RFID_State_Read_FieldOn;
477 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_ECHO_ERROR) {
478 RFIDCtrl.subState = RFID_State_Read_Finish;
479 RFIDCtrl.result = RFID_RESULT_READ_ERROR;
480 }
481 }
482 break;
483
484 case RFID_State_Read_FieldOn :
485 CR95HFStartField15693();
486 RFIDCtrl.subState = RFID_State_Read_WaitFieldOn;
487 break;
488
489 case RFID_State_Read_WaitFieldOn :
490 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
491 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
492 RFIDCtrl.subState = RFID_State_Read_Read;
493 //RFIDCtrl.subState =RFID_State_Read_FieldOn;
494 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_FIELD15693_ERROR) {
495 RFIDCtrl.subState = RFID_State_Read_Finish;
496 RFIDCtrl.result = RFID_RESULT_READ_ERROR;
497 }
498 }
499 break;
500
501 case RFID_State_Read_Read :
502 CR95HFStartRead(addr);
503 RFIDCtrl.subState = RFID_State_Read_WaitRead;
504 break;
505
506 case RFID_State_Read_WaitRead :
507 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
508 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
509 *(((unsigned long*)&SRDEeprom) + addr ) = CR95HFCtrl.deviceReg;
510 if(addr < (SRD_MEMORY_NBR_BLOCK-1)) {
511 addr++;
512 RFIDCtrl.subState = RFID_State_Read_Read;
513 } else {
514 RFIDCtrl.subState = RFID_State_Read_Finish;
515 }
516 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_READ_ERROR) {
517 RFIDCtrl.subState = RFID_State_Read_Finish;
518 RFIDCtrl.result = RFID_RESULT_READ_ERROR;
519 }
520 }
521 break;
522
523
524 case RFID_State_Read_Finish :
525 if(RFIDCtrl.result != RFID_RESULT_OK && ButtonReadGetState() == BUTTON_PRESSED) {
526 RFIDCtrl.result = RFID_RESULT_OK;
527 RFIDCtrl.subState = RFID_State_Read_Echo;
528 } else {
529 RFIDCtrl.request.bits.read = 0;
530 RFIDCtrl.state = RFID_STATE_STANDBY;
531 }
532 break;
533
534 default :
535 RFIDCtrl.subState = RFID_State_Bridge_Start;
536 break;
537 }
538 }
539
540
541 void RFIDWriteStateMachine(void) {
542 static unsigned short addr = 0;
543 static unsigned long msRef = 0;
544
545 switch(RFIDCtrl.subState) {
546
547 case RFID_State_Write_Start :
548 addr = 0;
549 RFIDCtrl.subState = RFID_State_Write_Antenna;
550
551 case RFID_State_Write_Antenna :
552 CR95SelectDevice(CR95_SELECT_EXTERNAL);
553 CR95UartDisableReceiver();
554 char data[1] = {0x55};
555 CR95UartSendData(data,1); //Try to wake up external
556 msRef = TickGetMsCounter();
557 RFIDCtrl.subState = RFID_State_Write_WaitAntenna;
558 break;
559
560 case RFID_State_Write_WaitAntenna :
561 if(TickMilliSecElapsedFrom(msRef)>10) {
562 if(CR95ExtGetConnectionState() == CR95_EXT_CONNECTED) {
563 CR95SelectDevice(CR95_SELECT_EXTERNAL);
564 RFIDExternalPowerMode = RFID_POWERED;
565 } else {
566 CR95SelectDevice(CR95_SELECT_INTERNAL);
567 RFIDInternalPowerMode = RFID_POWERED;
568 }
569 RFIDCtrl.subState = RFID_State_Write_Echo;
570 }
571 break;
572
573 case RFID_State_Write_Echo :
574 CR95HFStartEcho();
575 RFIDCtrl.subState = RFID_State_Write_WaitEcho;
576 break;
577
578 case RFID_State_Write_WaitEcho :
579 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
580 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
581 RFIDCtrl.subState = RFID_State_Write_FieldOn;
582 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_ECHO_ERROR) {
583 RFIDCtrl.subState = RFID_State_Write_Finish;
584 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
585 }
586 }
587 break;
588
589 case RFID_State_Write_FieldOn :
590 CR95HFStartField15693();
591 RFIDCtrl.subState = RFID_State_Write_WaitFieldOn;
592 break;
593
594 case RFID_State_Write_WaitFieldOn :
595 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
596 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
597 RFIDCtrl.subState = RFID_State_Write_ReadSerial;
598 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_FIELD15693_ERROR) {
599 RFIDCtrl.subState = RFID_State_Write_Finish;
600 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
601 }
602 }
603 break;
604
605 case RFID_State_Write_ReadSerial :
606 CR95HFStartRead(addr);
607 RFIDCtrl.subState = RFID_State_Write_WaitReadSerial;
608 break;
609
610 case RFID_State_Write_WaitReadSerial :
611 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
612 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
613 *(((unsigned long*)&SRDEeprom) + addr ) = CR95HFCtrl.deviceReg;
614 if(addr < 7) {
615 addr++;
616 RFIDCtrl.subState = RFID_State_Write_ReadSerial;
617 } else {
618 RFIDCtrl.subState = RFID_State_Write_IsWritable;
619 }
620 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_READ_ERROR) {
621 RFIDCtrl.subState = RFID_State_Write_Finish;
622 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
623 }
624 }
625 break;
626
627 case RFID_State_Write_IsWritable :
628 if(SRDEeprom.statusModule.all != 0) {
629 RFIDCtrl.subState = RFID_State_Write_Finish;
630 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
631 } else {
632 RFIDCtrl.subState = RFID_State_Write_Lock;
633 }
634 break;
635
636 case RFID_State_Write_Lock :
637 SRDEeprom.ctrlModule.all = 0x01;
638 CR95HFStartWrite(0,*((unsigned long*)&SRDEeprom) );
639 RFIDCtrl.subState = RFID_State_Write_WaitLock;
640 break;
641
642 case RFID_State_Write_WaitLock :
643 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
644 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
645 RFIDCtrl.subState = RFID_State_Write_Write;
646 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_WRITE_ERROR) {
647 RFIDCtrl.subState = RFID_State_Write_Finish;
648 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
649 }
650 }
651 break;
652
653 case RFID_State_Write_Write :
654
655 SRDEeprom.debug = 0;
656 SRDEeprom.activationDepth = DivingParameters.depth;
657 SRDEeprom.filterMSB = DivingParameters.filterMSB;
658 SRDEeprom.filterLSB = DivingParameters.filterLSB;
659
660 unsigned short checksum = ChecksumByteOnShortCompute(&SRDEeprom.serial0,10);
661 checksum += DivingParameters.depth;
662 checksum += DivingParameters.filterMSB;
663 checksum += DivingParameters.filterLSB;
664
665 SRDEeprom.checksumGenMSB = (unsigned char)((checksum >> 8) & 0x00FF);
666 SRDEeprom.checksumGenLSB = (unsigned char)((checksum >> 0) & 0x00FF);
667
668 CR95HFStartWrite(1,*( ((unsigned long*)&SRDEeprom) + 1) );
669 RFIDCtrl.subState = RFID_State_Write_WaitWrite;
670 break;
671
672
673 case RFID_State_Write_WaitWrite :
674 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
675 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
676 RFIDCtrl.subState = RFID_State_Write_WriteChecksum;
677 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_WRITE_ERROR) {
678 RFIDCtrl.subState = RFID_State_Write_Unlock; //Make sure to unlock
679 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
680 }
681 }
682 break;
683
684 case RFID_State_Write_WriteChecksum :
685 CR95HFStartWrite(7,*( ((unsigned long*)&SRDEeprom) + 7) );
686 RFIDCtrl.subState = RFID_State_Write_WaitWriteChecksum;
687 break;
688
689 case RFID_State_Write_WaitWriteChecksum :
690 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
691 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
692 RFIDCtrl.subState = RFID_State_Write_Unlock;
693 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_WRITE_ERROR) {
694 RFIDCtrl.subState = RFID_State_Write_Unlock; //Make sure to unlock
695 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
696 }
697 }
698 break;
699
700 case RFID_State_Write_Unlock :
701 SRDEeprom.ctrlModule.all = 0x00;
702 CR95HFStartWrite(0,*((unsigned long*)&SRDEeprom) );
703 RFIDCtrl.subState = RFID_State_Write_WaitUnlock;
704 break;
705
706 case RFID_State_Write_WaitUnlock :
707 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
708 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
709 if(RFIDCtrl.result == RFID_RESULT_WRITE_ERROR) {
710 RFIDCtrl.subState = RFID_State_Write_Finish;
711 } else {
712 RFIDCtrl.subState = RFID_State_Write_Read;
713 addr = 0;
714 }
715 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_WRITE_ERROR) {
716 RFIDCtrl.subState = RFID_State_Write_Finish;
717 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
718 }
719 }
720 break;
721
722 case RFID_State_Write_Read :
723 CR95HFStartRead(addr);
724 RFIDCtrl.subState = RFID_State_Write_WaitRead;
725 break;
726
727 case RFID_State_Write_WaitRead :
728 if(CR95HFManagerIsReady() == CR95HF_IS_READY) {
729 if(CR95HFCtrl.resultCode == CR95HF_RETURN_OK) {
730 *(((unsigned long*)&SRDEeprom) + addr ) = CR95HFCtrl.deviceReg;
731 if(addr < (SRD_MEMORY_NBR_BLOCK-1)) {
732 addr++;
733 RFIDCtrl.subState = RFID_State_Write_Read;
734 } else {
735 RFIDCtrl.subState = RFID_State_Write_Finish;
736 }
737 } else if (CR95HFCtrl.resultCode == CR95HF_RETURN_READ_ERROR) {
738 RFIDCtrl.subState = RFID_State_Write_Finish;
739 RFIDCtrl.result = RFID_RESULT_WRITE_ERROR;
740 }
741 }
742 break;
743
744
745 case RFID_State_Write_Finish :
746 if(RFIDCtrl.result != RFID_RESULT_OK && ButtonWriteGetState() == BUTTON_PRESSED) {
747 RFIDCtrl.result = RFID_RESULT_OK;
748 RFIDCtrl.subState = RFID_State_Write_Echo;
749 } else {
750 RFIDCtrl.request.bits.write = 0;
751 RFIDCtrl.state = RFID_STATE_STANDBY;
752 }
753 break;
754
755 default :
756 RFIDCtrl.subState = RFID_State_Write_Start;
757 break;
758 }
759 }
760
761
762
763 signed short RFIDManagerSendBridgeCommand (char* command, unsigned short commandSize) {
764
765 //if(RFIDCtrl.state == RFID_STATE_STANDBY) {
766 unsigned short i;
767
768 for(i=0 ; i<commandSize ; i++) {
769 RFIDCtrl.bridgeCommand[i] = *(command+i);
770 }
771
772 RFIDCtrl.bridgeCommandLength = commandSize;
773
774 RFIDCtrl.request.bits.bridge = 1;
775
776 return 0;
777
778 //} else {
779 // return -1; //Error
780 //}
781 }
782
783
784 /*############################################################################################*/
785 /*## END EXTERNAL FONCTIONS ##################################################################*/
786 /*############################################################################################*/
RFID_State_Write_WaitWrite
Definition: RFIDManager.h:178
RFIDWriteStateMachine
void RFIDWriteStateMachine(void)
Definition: RFIDManager.c:541
RFID_State_Write_WaitAntenna
Definition: RFIDManager.h:167
RFID_RESULT_READ_ERROR
Definition: RFIDManager.h:199
RFID_STATE_READ
Definition: RFIDManager.h:80
RFID_State_Read_WaitAntenna
Definition: RFIDManager.h:148
RFID_State_Write_WaitEcho
Definition: RFIDManager.h:169
RFID_State_Read_Start
Definition: RFIDManager.h:146
RFID_State_Bridge_Start
Definition: RFIDManager.h:125
RFIDDealer
void RFIDDealer(void)
Definition: RFIDManager.c:165
CR95ExtGetConnectionState
tCR95ExternalConnexion CR95ExtGetConnectionState(void)
Return the connection state of the CR95HF module.
Definition: CR95UartMapper.c:174
RFID_State_Read_FieldOn
Definition: RFIDManager.h:151
RFID_State_ExtLpm_Start
Definition: RFIDManager.h:108
RFID_State_Bridge_WaitTransfert
Definition: RFIDManager.h:133
tRFIDCtrl::bridgeCommandLength
unsigned short bridgeCommandLength
Definition: RFIDManager.h:227
SRDEeprom
tSRDEeprom SRDEeprom
Definition: RFIDManager.c:61
RFID_STATE_WRITE
Definition: RFIDManager.h:79
tMemoryManagerDiving::filterLSB
unsigned char filterLSB
Definition: MemoryManager.h:90
CR95HF_RETURN_WRITE_ERROR
Definition: CR95HF.h:188
CR95HFManager
void CR95HFManager(void)
Global manager of the CR95HF module.
Definition: CR95HF.c:598
RFID_State_ExtLpm_Hibernate
Definition: RFIDManager.h:113
RFID_State_IntLpm_Start
Definition: RFIDManager.h:91
tRFIDCtrl::bits
struct tRFIDCtrl::@6::@7 bits
RFID_State_Read_Read
Definition: RFIDManager.h:153
CR95HFStartBridge
void CR95HFStartBridge(char *data, unsigned short dataLength)
Definition: CR95HF.c:699
RFID_State_Bridge_FieldOn
Definition: RFIDManager.h:130
RFID_WORKING
Definition: RFIDManager.h:55
tRFIDPowerMode
tRFIDPowerMode
Define RFID power mode.
Definition: RFIDManager.h:64
RFID_State_ExtLpm_WaitEcho
Definition: RFIDManager.h:110
tSRDEeprom::serial0
unsigned char serial0
Definition: SRDMemoryMapping.h:183
CR95HF_RETURN_FIELD15693_ERROR
Definition: CR95HF.h:185
tCR95HFCtrl::deviceReg
unsigned long deviceReg
Definition: CR95HF.h:223
CR95HFStartHibernate
void CR95HFStartHibernate(void)
Definition: CR95HF.c:666
RFID_State_Write_WaitWriteChecksum
Definition: RFIDManager.h:180
RFID_State_Write_WriteChecksum
Definition: RFIDManager.h:179
tRFIDCtrl::lpm
tRFIDLpm lpm
Definition: RFIDManager.h:223
RFID_State_Read_Antenna
Definition: RFIDManager.h:147
RFIDManager
void RFIDManager(void)
RFID manager.
Definition: RFIDManager.c:93
RFID_State_Write_WaitFieldOn
Definition: RFIDManager.h:171
RFID_State_Bridge_SendResult
Definition: RFIDManager.h:134
RFID_State_Write_WaitUnlock
Definition: RFIDManager.h:182
BUTTON_PRESSED
Definition: button.h:67
RFID_State_IntLpm_WaitEcho
Definition: RFIDManager.h:93
ChecksumByteOnShortCompute
unsigned short ChecksumByteOnShortCompute(unsigned char *data, unsigned long dataLength)
Definition: checksum.c:111
RFID_State_Write_Lock
Definition: RFIDManager.h:175
UsbManagerSendCR95Error
void UsbManagerSendCR95Error(void)
Function used to send the CR95 error on the USB.
Definition: UsbManager.c:590
CR95HFStartField15693
void CR95HFStartField15693(void)
Definition: CR95HF.c:655
RFID_HIBERNATE
Definition: RFIDManager.h:66
RFID_State_ExtLpm_Finish
Definition: RFIDManager.h:115
tSRDEeprom::checksumGenMSB
unsigned char checksumGenMSB
Definition: SRDMemoryMapping.h:193
RFID_State_ExtLpm_Echo
Definition: RFIDManager.h:109
CR95HF_RETURN_READ_ERROR
Definition: CR95HF.h:187
tRFIDCtrl::result
tRFIDResultError result
Definition: RFIDManager.h:221
UsbManagerSendCR95Result
void UsbManagerSendCR95Result(char *result, unsigned short length)
Function used to send the CR95 result of last RFID operation on the USB.
Definition: UsbManager.c:604
CR95HF_RETURN_FIELDOFF_ERROR
Definition: CR95HF.h:184
RFID_State_IntLpm_WaitFieldOff
Definition: RFIDManager.h:95
tRFIDCtrl::msRef
unsigned long msRef
Definition: RFIDManager.h:229
RFID_State_IntLpm_Finish
Definition: RFIDManager.h:98
RFID_State_Read_WaitRead
Definition: RFIDManager.h:154
RFID_State_Write_WaitRead
Definition: RFIDManager.h:184
RFID_State_Bridge_SendError
Definition: RFIDManager.h:135
CR95HFStartRead
void CR95HFStartRead(unsigned short addr)
Definition: CR95HF.c:676
CR95HFCtrl
tCR95HFCtrl CR95HFCtrl
Variable used by the state machine of the CR95HF.
Definition: CR95HF.c:67
tSRDEeprom::debug
unsigned char debug
Definition: SRDMemoryMapping.h:167
tRFIDCtrl::request
union tRFIDCtrl::@6 request
CR95_SELECT_INTERNAL
Definition: CR95UartMapper.h:55
RFID_State_ExtLpm_FieldOff
Definition: RFIDManager.h:111
RFID_State_Write_WaitReadSerial
Definition: RFIDManager.h:173
RFIDExtLpmStateMachine
void RFIDExtLpmStateMachine(void)
Definition: RFIDManager.c:268
RFID_RESULT_WRITE_ERROR
Definition: RFIDManager.h:198
RFID_State_Bridge_WaitAntenna
Definition: RFIDManager.h:127
CR95HFStartEcho
void CR95HFStartEcho(void)
Manager used to deal each specific state.
Definition: CR95HF.c:635
DivingParameters
tMemoryManagerDiving DivingParameters
Variable used to control the diving parameters.
Definition: MemoryManager.c:54
RFID_State_Bridge_Transfert
Definition: RFIDManager.h:132
tSRDEeprom::ctrlModule
union tSRDEeprom::@8 ctrlModule
RFID_State_Read_Finish
Definition: RFIDManager.h:155
tRFIDCtrl::all
unsigned short all
Definition: RFIDManager.h:217
tSRDEeprom::filterMSB
unsigned char filterMSB
Definition: SRDMemoryMapping.h:169
RFID_State_Write_FieldOn
Definition: RFIDManager.h:170
CR95UartDisableReceiver
void CR95UartDisableReceiver(void)
Definition: CR95UartMapper.c:119
RFID_State_Write_Read
Definition: RFIDManager.h:183
RFIDReadStateMachine
void RFIDReadStateMachine(void)
Definition: RFIDManager.c:436
RFID_State_IntLpm_Echo
Definition: RFIDManager.h:92
RFIDInternalPowerMode
tRFIDPowerMode RFIDInternalPowerMode
Definition: RFIDManager.c:50
CR95HF_IS_READY
Definition: CR95HF.h:236
RFIDManagerInit
void RFIDManagerInit(void)
Function used to initialize the RFID manager.
Definition: RFIDManager.c:79
RFID_STATE_BRIDGE
Definition: RFIDManager.h:81
CR95HFManagerIsReady
tCR95HFIsReady CR95HFManagerIsReady(void)
Return the current state of the CR95HF module in it's manager.
Definition: CR95HF.c:718
TickGetMsCounter
unsigned long TickGetMsCounter(void)
Get the milliseconds counter.
Definition: tick.c:137
RFID_State_Write_Unlock
Definition: RFIDManager.h:181
RFID_State_Read_Echo
Definition: RFIDManager.h:149
RFID_READY_FOR_LPM
Definition: RFIDManager.h:54
tSRDEeprom::all
unsigned char all
Definition: SRDMemoryMapping.h:141
CR95UartSendData
void CR95UartSendData(char *data, unsigned short dataLength)
Definition: CR95UartMapper.c:129
RFID_STATE_STANDBY
Definition: RFIDManager.h:78
tMemoryManagerDiving::depth
unsigned char depth
Definition: MemoryManager.h:88
CR95_EXT_CONNECTED
Definition: CR95UartMapper.h:66
tCR95HFCtrl::receiveBuf
char receiveBuf[CR95HF_RX_BUF_SIZE]
Definition: CR95HF.h:211
CR95HFStartFieldOff
void CR95HFStartFieldOff(void)
Definition: CR95HF.c:645
tSRDEeprom::filterLSB
unsigned char filterLSB
Definition: SRDMemoryMapping.h:170
CR95HF_RETURN_HIBERNATE_ERROR
Definition: CR95HF.h:186
RFID_State_IntLpm_FieldOff
Definition: RFIDManager.h:94
tSRDEeprom::statusModule
union tSRDEeprom::@9 statusModule
RFID_STATE_LOW_POWER_EXT
Definition: RFIDManager.h:77
RFIDExternalPowerMode
tRFIDPowerMode RFIDExternalPowerMode
Definition: RFIDManager.c:51
tSRDEeprom
Structure used to represent and store SRD RFID memory.
Definition: SRDMemoryMapping.h:130
RFIDManagerSendBridgeCommand
signed short RFIDManagerSendBridgeCommand(char *command, unsigned short commandSize)
function used to send a bridge command.
Definition: RFIDManager.c:763
tCR95HFCtrl::resultCode
unsigned long resultCode
Definition: CR95HF.h:221
RFID_State_Write_IsWritable
Definition: RFIDManager.h:174
CR95HFStartWrite
void CR95HFStartWrite(unsigned short addr, unsigned long data)
Definition: CR95HF.c:687
RFID_State_ExtLpm_WaitFieldOff
Definition: RFIDManager.h:112
RFID_State_Write_Write
Definition: RFIDManager.h:177
tMemoryManagerDiving::filterMSB
unsigned char filterMSB
Definition: MemoryManager.h:89
tSRDEeprom::checksumGenLSB
unsigned char checksumGenLSB
Definition: SRDMemoryMapping.h:194
RFID_State_Write_Start
Definition: RFIDManager.h:165
RFID_State_Bridge_WaitEcho
Definition: RFIDManager.h:129
tRFIDCtrl::state
tRFIDState state
Definition: RFIDManager.h:219
RFID_State_Read_WaitFieldOn
Definition: RFIDManager.h:152
RFID_State_Write_Echo
Definition: RFIDManager.h:168
tCR95HFCtrl::rxPos
unsigned short rxPos
Definition: CR95HF.h:212
RFID_STATE_LOW_POWER_INT
Definition: RFIDManager.h:76
tRFIDCtrl::subState
unsigned long subState
Definition: RFIDManager.h:220
RFID_State_IntLpm_Hibernate
Definition: RFIDManager.h:96
CR95_SELECT_EXTERNAL
Definition: CR95UartMapper.h:56
RFID_State_Write_ReadSerial
Definition: RFIDManager.h:172
CR95HF_RETURN_OK
Definition: CR95HF.h:182
RFID_State_Bridge_Finish
Definition: RFIDManager.h:136
tRFIDCtrl::bridgeCommand
unsigned char bridgeCommand[RFIDMANAGER_BRIDGE_MAX_COMMAND_LENGTH]
Definition: RFIDManager.h:225
RFID_State_Write_WaitLock
Definition: RFIDManager.h:176
RFID_State_Write_Antenna
Definition: RFIDManager.h:166
RFID_State_Bridge_WaitFieldOn
Definition: RFIDManager.h:131
RFID_State_ExtLpm_WaitHibernate
Definition: RFIDManager.h:114
tRFIDCtrl
Define a structure to control the RFID operation.
Definition: RFIDManager.h:209
CR95SelectDevice
void CR95SelectDevice(tCR95UartSelect device)
Select the antenna used to communicate with the SRD.
Definition: CR95UartMapper.c:79
RFID_POWERED
Definition: RFIDManager.h:65
TickMilliSecElapsedFrom
unsigned long TickMilliSecElapsedFrom(unsigned long refTimeMs)
Get the milliseconds counter.
Definition: tick.c:141
RFIDCtrl
tRFIDCtrl RFIDCtrl
Variable used to control the RFID manager.
Definition: RFIDManager.c:59
ButtonWriteGetState
#define ButtonWriteGetState()
Macro used to get the button status.
Definition: button.h:104
RFIDManager.h
Headerfile for RFID management.
RFID_State_Write_Finish
Definition: RFIDManager.h:185
SRD_MEMORY_NBR_BLOCK
#define SRD_MEMORY_NBR_BLOCK
Define the number of block used in the SRD RFID memory.
Definition: SRDMemoryMapping.h:114
RFIDIntLpmStateMachine
void RFIDIntLpmStateMachine(void)
Definition: RFIDManager.c:201
RFID_State_Read_WaitEcho
Definition: RFIDManager.h:150
RFIDBridgeStateMachine
void RFIDBridgeStateMachine(void)
Definition: RFIDManager.c:335
tSRDEeprom::activationDepth
unsigned char activationDepth
Definition: SRDMemoryMapping.h:168
RFID_State_Bridge_Antenna
Definition: RFIDManager.h:126
RFID_RESULT_OK
Definition: RFIDManager.h:195
ButtonReadGetState
#define ButtonReadGetState()
Macro used to get the button status.
Definition: button.h:103
RFID_State_IntLpm_WaitHibernate
Definition: RFIDManager.h:97
CR95HF_RETURN_ECHO_ERROR
Definition: CR95HF.h:183
RFID_RESULT_BRIDGE_ERROR
Definition: RFIDManager.h:200
CR95HFInit
void CR95HFInit(void)
Function used to initialize the CR95HF global manager.
Definition: CR95HF.c:585
RFID_State_Bridge_Echo
Definition: RFIDManager.h:128