SRD Standelone programmation box: CR95HF.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
CR95HF.c
Go to the documentation of this file.
1 /*############################################################################################*/
2 /*############################################################################################*/
3 /**
4 * \file CR95HF.c
5 * \author Thibaut LALUQUE 3D-Ouest
6 * \date 25/11/2014
7 * \version 1.0
8 * \brief Source file for CR95HF Driver.
9 * \details All Right Reserved.
10 */
11 /*############################################################################################*/
12 /*############################################################################################*/
13
14
15 /*############################################################################################*/
16 /*## INCLUDES ################################################################################*/
17 /*############################################################################################*/
18 #include "CR95HF.h"
19 /*############################################################################################*/
20 /*## END INCLUDES ############################################################################*/
21 /*############################################################################################*/
22
23
24 /*############################################################################################*/
25 /*## LOCAL DEFINES ###########################################################################*/
26 /*############################################################################################*/
27 #define CR95HF_FRAME_CMD_ECHO ({0x55})
28 #define CR95HF_FRAME_CMD_ECHO_SIZE (1)
29 #define CR95HF_FRAME_ANS_ECHO ({0x55})
30 #define CR95HF_FRAME_ANS_ECHO_SIZE (1)
31 /*############################################################################################*/
32 /*## END LOCAL DEFINES ######################################################################*/
33 /*############################################################################################*/
34
35
36 /*############################################################################################*/
37 /*## LOCAL FONCTIONS DECLARATION #############################################################*/
38 /*############################################################################################*/
39 void CR95HFWriteCommand(char* command, unsigned short commandSize, char* answerExpected, unsigned short answerSize, unsigned short timeoutMs, unsigned short completionTimeMs, unsigned short waitForNbrRx);
40 void CR95HFReadAnswer (void);
41 signed short CR95HFBufCompare (char* dataBuf, unsigned short dataBufSize, char* dataBufRef, unsigned short dataBufRefSize);
42 void CR95HFCommandManager (void);
43
44 void CR95HFEchoStateMachine (void);
45 void CR95HFFieldOffStateMachine (void);
46 void CR95HFField15693StateMachine (void);
47 void CR95HFHibernateStateMachine (void);
48 void CR95HFReadStateMachine (void);
49 void CR95HFWriteStateMachine (void);
50 void CR95HFBridgeStateMachine (void);
51 /*############################################################################################*/
52 /*## END LOCAL FONCTIONS DECLARATION #########################################################*/
53 /*############################################################################################*/
54
55
56 /*############################################################################################*/
57 /*## LOCAL VARIABLES #########################################################################*/
58 /*############################################################################################*/
59
60 /*############################################################################################*/
61 /*## END LOCAL VARIABLES #####################################################################*/
62 /*############################################################################################*/
63
64 /*############################################################################################*/
65 /*## GLOBAL VARIABLES ########################################################################*/
66 /*############################################################################################*/
67 tCR95HFCtrl CR95HFCtrl;
68 /*############################################################################################*/
69 /*## END GLOBAL VARIABLES ####################################################################*/
70 /*############################################################################################*/
71
72
73 /*############################################################################################*/
74 /*## LOCAL FONCTIONS #########################################################################*/
75 /*############################################################################################*/
76 void CR95HFWriteCommand(char* command, unsigned short commandSize, char* answerExpected, unsigned short answerSize, unsigned short timeoutMs, unsigned short completionTimeMs, unsigned short waitForNbrRx) {
77
78 /*=== Copy answer expected into working buffer ===*/
79 unsigned short i;
80 for(i=0 ; i<answerSize ; i++) {
81 CR95HFCtrl.answerKeyWord[i] = *(answerExpected+i);
82 }
83 CR95HFCtrl.answerSize = answerSize;
84
85 /*=== set completion time ===*/
86 CR95HFCtrl.completionTimeMs = completionTimeMs;
87
88 /*=== Set timeout ===*/
89 CR95HFCtrl.timeoutMs = timeoutMs;
90
91
92 /*=== Clear Rx receiver ===*/
93 CR95UartDisableReceiver();
94 CR95UartResetReceiver();
95 StrTool_ClearString(CR95HFCtrl.receiveBuf, CR95HF_RX_BUF_SIZE);
96 CR95HFCtrl.rxPos = 0;
97
98 /*=== Set nbr Rx Byte ===*/
99 CR95HFCtrl.waitForNbrRx = waitForNbrRx;
100
101 /*=== Get time (ms) ref ===*/
102 CR95HFCtrl.refMs = TickGetMsCounter();
103
104 /*=== Set Working flag ===*/
105 CR95HFCtrl.flags.bits.isWorking =1;
106 CR95HFCtrl.flags.bits.timeout = 0;
107 CR95HFCtrl.flags.bits.anwserReceived = 0;
108 CR95HFCtrl.flags.bits.sizeReceive = 0;
109
110 CR95UartEnableReceiver();
111
112 CR95UartSendData(command, commandSize);
113 }
114
115 void CR95HFReadAnswer (void) {
116
117 char read;
118 tUartCtrl* CR95HFUartCtrl;
119
120 CR95HFUartCtrl = CR95UartGetUartStructCtrl();
121
122 while(CR95HFUartCtrl->rx.nbrChar != 0) {
123 read = CR95UartReadChar();
124 CR95HFCtrl.receiveBuf[CR95HFCtrl.rxPos++] = read;
125 }
126 }
127
128
129 signed short CR95HFBufCompare (char* dataBuf, unsigned short dataBufSize, char* dataBufRef, unsigned short dataBufRefSize) {
130
131 unsigned short findId = 0;
132 unsigned short id = 0;
133 unsigned short eqId = 0xFFFF;
134
135 while( id < dataBufSize) {
136
137 if(findId < dataBufRefSize) {
138
139 if(*(dataBufRef+findId) == *(dataBuf+id)) {
140 findId++;
141 if(eqId == 0xFFFF){
142 eqId = id;
143 }
144 } else {
145 eqId = 0xFFFF;
146 findId = 0;
147 }
148 } else {
149 return eqId;
150 }
151 id++;
152 }
153 if(findId == dataBufRefSize) {
154 return eqId;
155 } else {
156 return -1;
157 }
158 }
159
160
161 void CR95HFCommandManager (void) {
162
163 switch(CR95HFCtrl.command) {
164
165 case CR95HF_COMMAND_NONE :
166 //Wait State -> Do nothing
167 break;
168
169 case CR95HF_COMMAND_ECHO :
170 CR95HFEchoStateMachine();
171 break;
172
173 case CR95HF_COMMAND_FIELDOFF :
174 CR95HFFieldOffStateMachine();
175 break;
176
177 case CR95HF_COMMAND_FIELD15693 :
178 CR95HFField15693StateMachine();
179 break;
180
181 case CR95HF_COMMAND_HIBERNATE :
182 CR95HFHibernateStateMachine();
183 break;
184
185 case CR95HF_COMMAND_READ :
186 CR95HFReadStateMachine();
187 break;
188
189 case CR95HF_COMMAND_WRITE :
190 CR95HFWriteStateMachine();
191 break;
192
193 case CR95HF_COMMAND_BRIDGE :
194 CR95HFBridgeStateMachine();
195 break;
196
197 default :
198 CR95HFCtrl.flags.all = 0;
199 CR95HFCtrl.rxPos = 0;
200 CR95HFCtrl.refMs = 0;
201 CR95HFCtrl.timeoutMs = 0;
202 CR95HFCtrl.completionTimeMs = 0;
203 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
204 CR95HFCtrl.commandState = 0;
205 break;
206
207 }
208 }
209
210 void CR95HFEchoStateMachine (void) {
211 static unsigned char tryCounter = 0;
212 char data[1];
213
214 switch(CR95HFCtrl.commandState) {
215
216 case CR95HF_EchoState_Start:
217 tryCounter = 0;
218 CR95HFCtrl.commandState = CR95HF_EchoState_Send;
219 // No break;
220
221 case CR95HF_EchoState_Send:
222 data[0] = 0x55;
223 CR95HFWriteCommand(data,1,data,1,50,0,0);
224 CR95HFCtrl.commandState = CR95HF_EchoState_WaitAnswer;
225 break;
226
227 case CR95HF_EchoState_WaitAnswer:
228 if(CR95HFCtrl.flags.bits.timeout) {
229 tryCounter++;
230 if(tryCounter < CR95HF_ECHO_MAX_TRY) {
231 CR95HFCtrl.commandState = CR95HF_EchoState_Send;
232 } else {
233 CR95HFCtrl.resultCode = CR95HF_RETURN_ECHO_ERROR;
234 CR95HFCtrl.commandState = CR95HF_EchoState_Finish;
235 }
236 } else { //Answer receive
237 CR95HFCtrl.resultCode = CR95HF_RETURN_OK;
238 CR95HFCtrl.commandState = CR95HF_EchoState_Finish;
239 }
240 break;
241
242 case CR95HF_EchoState_Finish:
243 CR95HFCtrl.commandState = 0;
244 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
245 CR95HFCtrl.flags.all = 0;
246 break;
247
248 default: //ERROR
249 CR95HFCtrl.flags.all = 0;
250 CR95HFCtrl.rxPos = 0;
251 CR95HFCtrl.refMs = 0;
252 CR95HFCtrl.timeoutMs = 0;
253 CR95HFCtrl.completionTimeMs = 0;
254 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
255 CR95HFCtrl.commandState = 0;
256 CR95HFCtrl.resultCode = CR95HF_RETURN_STATEMACHINE_ERROR;
257 break;
258 }
259 }
260
261 void CR95HFFieldOffStateMachine (void) {
262 char data[4];
263 char dataResult[2];
264
265 switch(CR95HFCtrl.commandState) {
266
267 case CR95HF_FieldOffState_Start:
268 CR95HFCtrl.commandState = CR95HF_FieldOffState_Send;
269 // No break;
270
271 case CR95HF_FieldOffState_Send:
272 data[0] = 0x02;
273 data[1] = 0x02;
274 data[2] = 0x00;
275 data[3] = 0x00;
276 dataResult[0] = 0x00;
277 dataResult[1] = 0x00;
278 CR95HFWriteCommand(data,4,dataResult,2,500,0,0);
279 CR95HFCtrl.commandState = CR95HF_FieldOffState_WaitAnswer;
280 break;
281
282 case CR95HF_FieldOffState_WaitAnswer:
283 CR95HFCtrl.commandState = CR95HF_EchoState_Finish;
284 if(CR95HFCtrl.flags.bits.timeout) {
285 CR95HFCtrl.resultCode = CR95HF_RETURN_FIELDOFF_ERROR;
286 } else { //Answer receive
287 CR95HFCtrl.resultCode = CR95HF_RETURN_OK;
288 }
289 break;
290
291 case CR95HF_FieldOffState_Finish:
292 CR95HFCtrl.commandState = 0;
293 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
294 CR95HFCtrl.flags.all = 0;
295 break;
296
297 default: //ERROR
298 CR95HFCtrl.flags.all = 0;
299 CR95HFCtrl.rxPos = 0;
300 CR95HFCtrl.refMs = 0;
301 CR95HFCtrl.timeoutMs = 0;
302 CR95HFCtrl.completionTimeMs = 0;
303 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
304 CR95HFCtrl.commandState = 0;
305 CR95HFCtrl.resultCode = CR95HF_RETURN_STATEMACHINE_ERROR;
306 break;
307 }
308 }
309
310
311 void CR95HFField15693StateMachine (void) {
312 char data[4];
313 char dataResult[2];
314
315 switch(CR95HFCtrl.commandState) {
316
317 case CR95HF_Field15693State_Start:
318 CR95HFCtrl.commandState = CR95HF_Field15693State_Send;
319 // No break;
320
321 case CR95HF_Field15693State_Send:
322 data[0] = 0x02;
323 data[1] = 0x02;
324 data[2] = 0x01;
325 data[3] = 0x0D;
326 dataResult[0] = 0x00;
327 dataResult[1] = 0x00;
328 CR95HFWriteCommand(data,4,dataResult,2,500,0,0);
329 CR95HFCtrl.commandState = CR95HF_Field15693State_WaitAnswer;
330 break;
331
332 case CR95HF_Field15693State_WaitAnswer:
333 CR95HFCtrl.commandState = CR95HF_Field15693State_Finish;
334 if(CR95HFCtrl.flags.bits.timeout) {
335 CR95HFCtrl.resultCode = CR95HF_RETURN_FIELD15693_ERROR;
336 } else { //Answer receive
337 CR95HFCtrl.resultCode = CR95HF_RETURN_OK;
338 }
339 break;
340
341 case CR95HF_Field15693State_Finish:
342 CR95HFCtrl.commandState = 0;
343 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
344 CR95HFCtrl.flags.all = 0;
345 break;
346
347 default: //ERROR
348 CR95HFCtrl.flags.all = 0;
349 CR95HFCtrl.rxPos = 0;
350 CR95HFCtrl.refMs = 0;
351 CR95HFCtrl.timeoutMs = 0;
352 CR95HFCtrl.completionTimeMs = 0;
353 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
354 CR95HFCtrl.commandState = 0;
355 CR95HFCtrl.resultCode = CR95HF_RETURN_STATEMACHINE_ERROR;
356 break;
357 }
358 }
359
360 void CR95HFHibernateStateMachine (void) {
361 char data[16];
362
363 switch(CR95HFCtrl.commandState) {
364
365 case CR95HF_HibernateState_Start:
366 CR95HFCtrl.commandState = CR95HF_HibernateState_Send;
367 // No break;
368
369 case CR95HF_HibernateState_Send:
370 data[0] = 0x07;
371 data[1] = 0x0E;
372 data[2] = 0x08;
373 data[3] = 0x04;
374 data[4] = 0x00;
375 data[5] = 0x04;
376 data[6] = 0x00;
377 data[7] = 0x18;
378 data[8] = 0x00;
379 data[9] = 0x00;
380 data[10] = 0x00;
381 data[11] = 0x00;
382 data[12] = 0x00;
383 data[13] = 0x00;
384 data[14] = 0x00;
385 data[15] = 0x00;
386 CR95HFWriteCommand(data,16,data,0,50,150,0); //End with timeout
387 CR95UartDisableReceiver(); //Disable Uart to rpevent loop interrupt
388 CR95HFCtrl.commandState = CR95HF_HibernateState_WaitAnswer;
389 break;
390
391 case CR95HF_HibernateState_WaitAnswer:
392 CR95HFCtrl.commandState = CR95HF_HibernateState_Finish;
393 CR95HFCtrl.resultCode = CR95HF_RETURN_OK;
394 break;
395
396 case CR95HF_HibernateState_Finish:
397 CR95HFCtrl.commandState = 0;
398 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
399 CR95HFCtrl.flags.all = 0;
400 break;
401
402 default: //ERROR
403 CR95HFCtrl.flags.all = 0;
404 CR95HFCtrl.rxPos = 0;
405 CR95HFCtrl.refMs = 0;
406 CR95HFCtrl.timeoutMs = 0;
407 CR95HFCtrl.completionTimeMs = 0;
408 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
409 CR95HFCtrl.commandState = 0;
410 CR95HFCtrl.resultCode = CR95HF_RETURN_STATEMACHINE_ERROR;
411 break;
412 }
413 }
414
415
416 void CR95HFReadStateMachine (void) {
417 char data[6];
418
419 switch(CR95HFCtrl.commandState) {
420
421 case CR95HF_ReadState_Start:
422 CR95HFCtrl.commandState = CR95HF_ReadState_Send;
423 // No break;
424
425 case CR95HF_ReadState_Send:
426 data[0] = 0x04;
427 data[1] = 0x04;
428 data[2] = 0x0A;
429 data[3] = 0x20;
430 data[4] = (char)((CR95HFCtrl.deviceRegAddr >> 0) & 0xFF);
431 data[5] = (char)((CR95HFCtrl.deviceRegAddr >> 8) & 0xFF);
432
433 CR95HFWriteCommand(data,6,data,0,200,25,10); //End with nbr Rx
434
435 CR95HFCtrl.commandState = CR95HF_ReadState_WaitAnswer;
436 break;
437
438 case CR95HF_ReadState_WaitAnswer:
439 if(CR95HFCtrl.flags.bits.sizeReceive) {
440 CR95HFCtrl.deviceReg = ((((unsigned long)CR95HFCtrl.receiveBuf[3]) << 0) & 0x000000FF) |
441 ((((unsigned long)CR95HFCtrl.receiveBuf[4]) << 8) & 0x0000FF00) |
442 ((((unsigned long)CR95HFCtrl.receiveBuf[5]) << 16) & 0x00FF0000) |
443 ((((unsigned long)CR95HFCtrl.receiveBuf[6]) << 24) & 0xFF000000);
444 CR95HFCtrl.commandState = CR95HF_ReadState_Finish;
445 CR95HFCtrl.resultCode = CR95HF_RETURN_OK;
446 } else {
447 CR95HFCtrl.commandState = CR95HF_ReadState_Finish;
448 CR95HFCtrl.resultCode = CR95HF_RETURN_READ_ERROR;
449 }
450 break;
451
452 case CR95HF_ReadState_Finish:
453 CR95HFCtrl.commandState = 0;
454 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
455 CR95HFCtrl.flags.all = 0;
456 break;
457
458 default: //ERROR
459 CR95HFCtrl.flags.all = 0;
460 CR95HFCtrl.rxPos = 0;
461 CR95HFCtrl.refMs = 0;
462 CR95HFCtrl.timeoutMs = 0;
463 CR95HFCtrl.completionTimeMs = 0;
464 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
465 CR95HFCtrl.commandState = 0;
466 CR95HFCtrl.resultCode = CR95HF_RETURN_STATEMACHINE_ERROR;
467 break;
468 }
469 }
470
471 void CR95HFWriteStateMachine (void) {
472 char data[10];
473 char dataResult[6];
474
475 switch(CR95HFCtrl.commandState) {
476
477 case CR95HF_WriteState_Start:
478 CR95HFCtrl.commandState = CR95HF_WriteState_Send;
479 // No break;
480
481 case CR95HF_WriteState_Send:
482 data[0] = 0x04;
483 data[1] = 0x08;
484 data[2] = 0x0A;
485 data[3] = 0x21;
486 data[4] = (char)((CR95HFCtrl.deviceRegAddr >> 0) & 0xFF);
487 data[5] = (char)((CR95HFCtrl.deviceRegAddr >> 8) & 0xFF);
488 data[6] = (char)((CR95HFCtrl.deviceReg >> 0) & 0xFF);
489 data[7] = (char)((CR95HFCtrl.deviceReg >> 8) & 0xFF);
490 data[8] = (char)((CR95HFCtrl.deviceReg >> 16) & 0xFF);
491 data[9] = (char)((CR95HFCtrl.deviceReg >> 24) & 0xFF);
492
493 dataResult[0] = 0x80;
494 dataResult[1] = 0x04;
495 dataResult[2] = 0x00;
496 dataResult[3] = 0x78;
497 dataResult[4] = 0xF0;
498 dataResult[5] = 0x00;
499
500 CR95HFWriteCommand(data,10,dataResult,6,200,25,0); //End with nbr Rx
501
502 CR95HFCtrl.commandState = CR95HF_WriteState_WaitAnswer;
503 break;
504
505 case CR95HF_WriteState_WaitAnswer:
506 if(CR95HFCtrl.flags.bits.timeout) {
507 CR95HFCtrl.commandState = CR95HF_WriteState_Finish;
508 CR95HFCtrl.resultCode = CR95HF_RETURN_WRITE_ERROR;
509 } else {
510 CR95HFCtrl.commandState = CR95HF_WriteState_Finish;
511 CR95HFCtrl.resultCode = CR95HF_RETURN_OK;
512 }
513 break;
514
515 case CR95HF_WriteState_Finish:
516 CR95HFCtrl.commandState = 0;
517 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
518 CR95HFCtrl.flags.all = 0;
519 break;
520
521 default: //ERROR
522 CR95HFCtrl.flags.all = 0;
523 CR95HFCtrl.rxPos = 0;
524 CR95HFCtrl.refMs = 0;
525 CR95HFCtrl.timeoutMs = 0;
526 CR95HFCtrl.completionTimeMs = 0;
527 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
528 CR95HFCtrl.commandState = 0;
529 CR95HFCtrl.resultCode = CR95HF_RETURN_STATEMACHINE_ERROR;
530 break;
531 }
532 }
533
534
535 void CR95HFBridgeStateMachine (void) {
536 char dataResult[2];
537
538 switch(CR95HFCtrl.commandState) {
539
540 case CR95HF_BridgeState_Start:
541 CR95HFCtrl.commandState = CR95HF_BridgeState_Send;
542 // No break;
543
544 case CR95HF_BridgeState_Send:
545
546 dataResult[0] = 0x87;
547 dataResult[1] = 0x00;
548
549 CR95HFWriteCommand(CR95HFCtrl.bridgeCommand,CR95HFCtrl.bridgeCommandLength,dataResult,2,50,25,0);
550
551 CR95HFCtrl.commandState = CR95HF_BridgeState_WaitAnswer;
552 break;
553
554 case CR95HF_BridgeState_WaitAnswer:
555 CR95HFCtrl.commandState = CR95HF_BridgeState_Finish;
556 CR95HFCtrl.resultCode = CR95HF_RETURN_OK;
557 break;
558
559 case CR95HF_BridgeState_Finish:
560 CR95HFCtrl.commandState = 0;
561 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
562 CR95HFCtrl.flags.all = 0;
563 break;
564
565 default: //ERROR
566 CR95HFCtrl.flags.all = 0;
567 CR95HFCtrl.rxPos = 0;
568 CR95HFCtrl.refMs = 0;
569 CR95HFCtrl.timeoutMs = 0;
570 CR95HFCtrl.completionTimeMs = 0;
571 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
572 CR95HFCtrl.commandState = 0;
573 CR95HFCtrl.resultCode = CR95HF_RETURN_STATEMACHINE_ERROR;
574 break;
575 }
576 }
577 /*############################################################################################*/
578 /*## END LOCAL FONCTIONS #####################################################################*/
579 /*############################################################################################*/
580
581
582 /*############################################################################################*/
583 /*## EXTERNAL FONCTIONS ######################################################################*/
584 /*############################################################################################*/
585 void CR95HFInit (void) {
586 CR95UartInit(CR95HF_UART_BAUDRATE);
587
588 CR95HFCtrl.flags.all = 0;
589 CR95HFCtrl.rxPos = 0;
590 CR95HFCtrl.refMs = 0;
591 CR95HFCtrl.timeoutMs = 0;
592 CR95HFCtrl.completionTimeMs = 0;
593 CR95HFCtrl.command = CR95HF_COMMAND_NONE;
594 CR95HFCtrl.commandState = 0;
595 }
596
597
598 void CR95HFManager (void) {
599
600 unsigned long timeElapsed = 0;
601
602 if(CR95HFCtrl.flags.bits.isWorking) {
603 timeElapsed = TickMilliSecElapsedFrom(CR95HFCtrl.refMs);
604
605 if(timeElapsed > CR95HFCtrl.timeoutMs) {
606 CR95HFCtrl.flags.bits.timeout = 1;
607 }
608 }
609
610 if(CR95HFCtrl.flags.all == 0x0001) { //Only working flag
611
612 if(timeElapsed >= CR95HFCtrl.completionTimeMs) {
613
614 CR95HFReadAnswer();
615
616 if(CR95HFCtrl.waitForNbrRx == 0) {
617
618 if(CR95HFBufCompare(CR95HFCtrl.receiveBuf, CR95HFCtrl.rxPos, CR95HFCtrl.answerKeyWord, CR95HFCtrl.answerSize) != -1) {
619 CR95HFCtrl.flags.bits.anwserReceived = 1;
620 }
621 } else {
622
623 if((CR95HFCtrl.rxPos + 1) > CR95HFCtrl.waitForNbrRx) {
624 CR95HFCtrl.flags.bits.sizeReceive = 1;
625 }
626 }
627 }
628 } else {
629 CR95HFCommandManager();
630 }
631 }
632
633
634
635 void CR95HFStartEcho (void) {
636
637 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
638 CR95HFCtrl.resultCode = CR95HF_RETURN_WORKING;
639 CR95HFCtrl.command = CR95HF_COMMAND_ECHO;
640 CR95HFCtrl.commandState = CR95HF_EchoState_Start;
641 CR95HFCtrl.flags.all = 0;
642 }
643 }
644
645 void CR95HFStartFieldOff (void) {
646
647 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
648 CR95HFCtrl.resultCode = CR95HF_RETURN_WORKING;
649 CR95HFCtrl.command = CR95HF_COMMAND_FIELDOFF;
650 CR95HFCtrl.commandState = CR95HF_FieldOffState_Start;
651 CR95HFCtrl.flags.all = 0;
652 }
653 }
654
655 void CR95HFStartField15693 (void) {
656
657 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
658 CR95HFCtrl.resultCode = CR95HF_RETURN_WORKING;
659 CR95HFCtrl.command = CR95HF_COMMAND_FIELD15693;
660 CR95HFCtrl.commandState = CR95HF_Field15693State_Start;
661 CR95HFCtrl.flags.all = 0;
662 }
663 }
664
665
666 void CR95HFStartHibernate (void) {
667
668 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
669 CR95HFCtrl.resultCode = CR95HF_RETURN_WORKING;
670 CR95HFCtrl.command = CR95HF_COMMAND_HIBERNATE;
671 CR95HFCtrl.commandState = CR95HF_HibernateState_Start;
672 CR95HFCtrl.flags.all = 0;
673 }
674 }
675
676 void CR95HFStartRead (unsigned short addr) {
677
678 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
679 CR95HFCtrl.deviceRegAddr = addr;
680 CR95HFCtrl.resultCode = CR95HF_RETURN_WORKING;
681 CR95HFCtrl.command = CR95HF_COMMAND_READ;
682 CR95HFCtrl.commandState = CR95HF_ReadState_Start;
683 CR95HFCtrl.flags.all = 0;
684 }
685 }
686
687 void CR95HFStartWrite (unsigned short addr, unsigned long data) {
688
689 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
690 CR95HFCtrl.deviceRegAddr = addr;
691 CR95HFCtrl.deviceReg = data;
692 CR95HFCtrl.resultCode = CR95HF_RETURN_WORKING;
693 CR95HFCtrl.command = CR95HF_COMMAND_WRITE;
694 CR95HFCtrl.commandState = CR95HF_WriteState_Start;
695 CR95HFCtrl.flags.all = 0;
696 }
697 }
698
699 void CR95HFStartBridge (char* data, unsigned short dataLength) {
700
701 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
702
703 unsigned char i;
704
705 for(i=0 ; i<dataLength ; i++) {
706 CR95HFCtrl.bridgeCommand[i] = *(data+i);
707 }
708
709 CR95HFCtrl.bridgeCommandLength = dataLength;
710
711 CR95HFCtrl.resultCode = CR95HF_RETURN_WORKING;
712 CR95HFCtrl.command = CR95HF_COMMAND_BRIDGE;
713 CR95HFCtrl.commandState = CR95HF_BridgeState_Start;
714 CR95HFCtrl.flags.all = 0;
715 }
716 }
717
718 tCR95HFIsReady CR95HFManagerIsReady (void) {
719 if(CR95HFCtrl.command == CR95HF_COMMAND_NONE) {
720 return CR95HF_IS_READY;
721 } else {
722 return CR95HF_IS_BUSY;
723 }
724 }
725 /*############################################################################################*/
726 /*## END EXTERNAL FONCTIONS ##################################################################*/
727 /*############################################################################################*/
CR95HFBufCompare
signed short CR95HFBufCompare(char *dataBuf, unsigned short dataBufSize, char *dataBufRef, unsigned short dataBufRefSize)
Definition: CR95HF.c:129
tCR95HFCtrl::completionTimeMs
unsigned short completionTimeMs
Definition: CR95HF.h:218
tCR95HFCtrl::waitForNbrRx
unsigned short waitForNbrRx
Definition: CR95HF.h:215
CR95HF_FieldOffState_Finish
Definition: CR95HF.h:105
CR95HFField15693StateMachine
void CR95HFField15693StateMachine(void)
Definition: CR95HF.c:311
CR95HFReadStateMachine
void CR95HFReadStateMachine(void)
Definition: CR95HF.c:416
CR95HF_WriteState_WaitAnswer
Definition: CR95HF.h:156
CR95HF_FieldOffState_WaitAnswer
Definition: CR95HF.h:104
tCR95HFCtrl::bridgeCommand
char bridgeCommand[CR95HF_ANSWER_BUF_SIZE]
Definition: CR95HF.h:224
CR95HF_RETURN_WRITE_ERROR
Definition: CR95HF.h:188
CR95HFManager
void CR95HFManager(void)
Global manager of the CR95HF module.
Definition: CR95HF.c:598
CR95HFHibernateStateMachine
void CR95HFHibernateStateMachine(void)
Definition: CR95HF.c:360
CR95HFStartBridge
void CR95HFStartBridge(char *data, unsigned short dataLength)
Definition: CR95HF.c:699
tUartCtrl::rx
tUartFifo rx
Definition: uart_common.h:77
tCR95HFCtrl::refMs
unsigned long refMs
Definition: CR95HF.h:216
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
tCR95HFCtrl::deviceRegAddr
unsigned short deviceRegAddr
Definition: CR95HF.h:222
tCR95HFCtrl::all
unsigned short all
Definition: CR95HF.h:208
CR95HF_COMMAND_WRITE
Definition: CR95HF.h:78
CR95HFReadAnswer
void CR95HFReadAnswer(void)
Definition: CR95HF.c:115
CR95HF_WriteState_Start
Definition: CR95HF.h:154
CR95HF_HibernateState_Finish
Definition: CR95HF.h:131
CR95HF_COMMAND_READ
Definition: CR95HF.h:77
tCR95HFCtrl::flags
union tCR95HFCtrl::@17 flags
CR95HFStartField15693
void CR95HFStartField15693(void)
Definition: CR95HF.c:655
CR95HF_RETURN_READ_ERROR
Definition: CR95HF.h:187
tCR95HFCtrl
Define the structure used to control the CR95HF module.
Definition: CR95HF.h:199
CR95HF_IS_BUSY
Definition: CR95HF.h:235
CR95HF_RETURN_FIELDOFF_ERROR
Definition: CR95HF.h:184
CR95HF_HibernateState_Start
Definition: CR95HF.h:128
CR95HF_EchoState_Finish
Definition: CR95HF.h:92
tCR95HFIsReady
tCR95HFIsReady
Define constant to indicate if module is used or not.
Definition: CR95HF.h:234
CR95HF_BridgeState_Send
Definition: CR95HF.h:168
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
CR95HF_Field15693State_Start
Definition: CR95HF.h:115
CR95HF_ReadState_Finish
Definition: CR95HF.h:144
CR95HF_RETURN_WORKING
Definition: CR95HF.h:181
CR95HF_UART_BAUDRATE
#define CR95HF_UART_BAUDRATE
Define the baudrate of the interface used to communicate with the CR95HF.
Definition: CR95HF.h:36
CR95HF_BridgeState_WaitAnswer
Definition: CR95HF.h:169
tCR95HFCtrl::answerSize
unsigned short answerSize
Definition: CR95HF.h:214
CR95HFStartEcho
void CR95HFStartEcho(void)
Manager used to deal each specific state.
Definition: CR95HF.c:635
CR95HF_Field15693State_Send
Definition: CR95HF.h:116
CR95HF_RETURN_STATEMACHINE_ERROR
Definition: CR95HF.h:189
CR95UartDisableReceiver
void CR95UartDisableReceiver(void)
Definition: CR95UartMapper.c:119
CR95HF_ReadState_Start
Definition: CR95HF.h:141
CR95HF_COMMAND_FIELD15693
Definition: CR95HF.h:75
CR95HF_IS_READY
Definition: CR95HF.h:236
CR95UartEnableReceiver
void CR95UartEnableReceiver(void)
Definition: CR95UartMapper.c:111
CR95HFManagerIsReady
tCR95HFIsReady CR95HFManagerIsReady(void)
Return the current state of the CR95HF module in it's manager.
Definition: CR95HF.c:718
CR95HF_ReadState_WaitAnswer
Definition: CR95HF.h:143
TickGetMsCounter
unsigned long TickGetMsCounter(void)
Get the milliseconds counter.
Definition: tick.c:137
CR95HFBridgeStateMachine
void CR95HFBridgeStateMachine(void)
Definition: CR95HF.c:535
CR95HFFieldOffStateMachine
void CR95HFFieldOffStateMachine(void)
Definition: CR95HF.c:261
CR95UartSendData
void CR95UartSendData(char *data, unsigned short dataLength)
Definition: CR95UartMapper.c:129
tCR95HFCtrl::receiveBuf
char receiveBuf[CR95HF_RX_BUF_SIZE]
Definition: CR95HF.h:211
CR95HFWriteCommand
void CR95HFWriteCommand(char *command, unsigned short commandSize, char *answerExpected, unsigned short answerSize, unsigned short timeoutMs, unsigned short completionTimeMs, unsigned short waitForNbrRx)
Definition: CR95HF.c:76
CR95HFStartFieldOff
void CR95HFStartFieldOff(void)
Definition: CR95HF.c:645
tCR95HFCtrl::bits
struct tCR95HFCtrl::@17::@18 bits
tCR95HFCtrl::resultCode
unsigned long resultCode
Definition: CR95HF.h:221
CR95UartInit
void CR95UartInit(unsigned long baudrate)
CR95HF Uart interface.
Definition: CR95UartMapper.c:84
CR95HF_EchoState_Send
Definition: CR95HF.h:90
CR95UartReadChar
char CR95UartReadChar(void)
Definition: CR95UartMapper.c:145
CR95HF_Field15693State_WaitAnswer
Definition: CR95HF.h:117
CR95HFStartWrite
void CR95HFStartWrite(unsigned short addr, unsigned long data)
Definition: CR95HF.c:687
CR95UartGetUartStructCtrl
tUartCtrl * CR95UartGetUartStructCtrl(void)
Return the structure control of the CR95HF uart.
Definition: CR95UartMapper.c:166
tCR95HFCtrl::bridgeCommandLength
unsigned short bridgeCommandLength
Definition: CR95HF.h:225
StrTool_ClearString
void StrTool_ClearString(char *str, unsigned short strLength)
Clear a string (reset all char to '\0').
Definition: StringTools.c:66
CR95HF_COMMAND_NONE
Definition: CR95HF.h:72
CR95HF_ReadState_Send
Definition: CR95HF.h:142
CR95HF_RX_BUF_SIZE
#define CR95HF_RX_BUF_SIZE
Define the buffer size.
Definition: CR95HF.h:44
CR95HF_COMMAND_HIBERNATE
Definition: CR95HF.h:76
CR95HF_HibernateState_Send
Definition: CR95HF.h:129
tUartCtrl
Define the Uart control structure.
Definition: uart_common.h:76
CR95HF_WriteState_Send
Definition: CR95HF.h:155
CR95HF_ECHO_MAX_TRY
#define CR95HF_ECHO_MAX_TRY
Define the maximum number of echo sended to try to establish a communication with the CR95HF...
Definition: CR95HF.h:54
CR95HF.h
Headerfile for CR95HF driver.
CR95HF_BridgeState_Finish
Definition: CR95HF.h:170
tCR95HFCtrl::rxPos
unsigned short rxPos
Definition: CR95HF.h:212
tCR95HFCtrl::commandState
unsigned long commandState
Definition: CR95HF.h:220
CR95HF_RETURN_OK
Definition: CR95HF.h:182
CR95HF_COMMAND_ECHO
Definition: CR95HF.h:73
CR95HF_EchoState_Start
Definition: CR95HF.h:89
tCR95HFCtrl::answerKeyWord
char answerKeyWord[CR95HF_ANSWER_BUF_SIZE]
Definition: CR95HF.h:213
CR95HF_Field15693State_Finish
Definition: CR95HF.h:118
CR95HF_FieldOffState_Send
Definition: CR95HF.h:103
CR95HF_BridgeState_Start
Definition: CR95HF.h:167
tCR95HFCtrl::command
tCR95HFCommand command
Definition: CR95HF.h:219
CR95HF_EchoState_WaitAnswer
Definition: CR95HF.h:91
CR95HFEchoStateMachine
void CR95HFEchoStateMachine(void)
Definition: CR95HF.c:210
TickMilliSecElapsedFrom
unsigned long TickMilliSecElapsedFrom(unsigned long refTimeMs)
Get the milliseconds counter.
Definition: tick.c:141
CR95HF_COMMAND_BRIDGE
Definition: CR95HF.h:79
CR95HFCommandManager
void CR95HFCommandManager(void)
Definition: CR95HF.c:161
CR95HF_COMMAND_FIELDOFF
Definition: CR95HF.h:74
CR95HF_WriteState_Finish
Definition: CR95HF.h:157
CR95UartResetReceiver
void CR95UartResetReceiver(void)
Reset the CR95HF Uart interface.
Definition: CR95UartMapper.c:153
tUartFifo::nbrChar
unsigned short nbrChar
Definition: uart_common.h:49
CR95HF_RETURN_ECHO_ERROR
Definition: CR95HF.h:183
tCR95HFCtrl::timeoutMs
unsigned long timeoutMs
Definition: CR95HF.h:217
CR95HF_FieldOffState_Start
Definition: CR95HF.h:102
CR95HFWriteStateMachine
void CR95HFWriteStateMachine(void)
Definition: CR95HF.c:471
CR95HFInit
void CR95HFInit(void)
Function used to initialize the CR95HF global manager.
Definition: CR95HF.c:585
CR95HF_HibernateState_WaitAnswer
Definition: CR95HF.h:130