SRD Standelone programmation box: CR95HF.h 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.h
Go to the documentation of this file.
1 /*############################################################################################*/
2 /*############################################################################################*/
3 /**
4 * \file CR95HF.h
5 * \author Thibaut LALUQUE 3D-Ouest
6 * \date 25/11/2014
7 * \version 1.0
8 * \brief Headerfile for CR95HF driver.
9 * \details All Right Reserved.
10 */
11 /*############################################################################################*/
12 /*############################################################################################*/
13 #ifndef __CR95HF_H__
14 #define __CR95HF_H__
15
16 /*############################################################################################*/
17 /*## INCLUDES ################################################################################*/
18 /*############################################################################################*/
19 #include "CR95UartMapper.h"
20 #include "StringTools.h"
21 #include "Tick.h"
22 /*############################################################################################*/
23 /*## END INCLUDES ############################################################################*/
24 /*############################################################################################*/
25
26
27 /*############################################################################################*/
28 /*## DEFINES #################################################################################*/
29 /*############################################################################################*/
30 /*----------------------------------------------------------------------------*/
31 /**
32 * \def CR95HF_UART_BAUDRATE
33 * \brief Define the baudrate of the interface used to communicate with the CR95HF.
34 */
35 /*----------------------------------------------------------------------------*/
36 #define CR95HF_UART_BAUDRATE (57600U)
37
38 /*----------------------------------------------------------------------------*/
39 /**
40 * \brief Define the buffer size.
41 */
42 ///@{
43 /*----------------------------------------------------------------------------*/
44 #define CR95HF_RX_BUF_SIZE (128U)
45 #define CR95HF_ANSWER_BUF_SIZE (64U)
46 ///@}
47
48 /*----------------------------------------------------------------------------*/
49 /**
50 * \def CR95HF_ECHO_MAX_TRY
51 * \brief Define the maximum number of echo sended to try to establish a communication with the CR95HF.
52 */
53 /*----------------------------------------------------------------------------*/
54 #define CR95HF_ECHO_MAX_TRY (20U)
55
56 /*############################################################################################*/
57 /*## END DEFINES #############################################################################*/
58 /*############################################################################################*/
59
60
61
62 /*############################################################################################*/
63 /*## TYPEDEF/STRUCT/ENUM/UNION ###############################################################*/
64 /*############################################################################################*/
65 /*----------------------------------------------------------------------------*/
66 /**
67 * \enum tCR95HFCommand
68 * \brief Define the global state machine of the CR95HF interface.
69 */
70 /*----------------------------------------------------------------------------*/
71 typedef enum {
72 CR95HF_COMMAND_NONE = 0, /*!< Standby */
73 CR95HF_COMMAND_ECHO, /*!< Echo */
74 CR95HF_COMMAND_FIELDOFF, /*!< Field off command */
75 CR95HF_COMMAND_FIELD15693, /*!< Field enable and configured for ISO15693 */
76 CR95HF_COMMAND_HIBERNATE, /*!< Module hibernate */
77 CR95HF_COMMAND_READ, /*!< Read operation */
78 CR95HF_COMMAND_WRITE, /*!< Write operation */
79 CR95HF_COMMAND_BRIDGE /*!< Bridge command */
80 }tCR95HFCommand;
81
82 /*----------------------------------------------------------------------------*/
83 /**
84 * \enum tCR95HFEchoState
85 * \brief Define the different state of the Echo global state machine.
86 */
87 /*----------------------------------------------------------------------------*/
88 typedef enum {
89 CR95HF_EchoState_Start, /*!< Start */
90 CR95HF_EchoState_Send, /*!< Send echo command */
91 CR95HF_EchoState_WaitAnswer, /*!< Wait answer */
92 CR95HF_EchoState_Finish /*!< Finish */
93 }tCR95HFEchoState;
94
95 /*----------------------------------------------------------------------------*/
96 /**
97 * \enum tCR95HFFieldOffState
98 * \brief Define the different state of the Field off state machine.
99 */
100 /*----------------------------------------------------------------------------*/
101 typedef enum {
102 CR95HF_FieldOffState_Start, /*!< Start */
103 CR95HF_FieldOffState_Send, /*!< Send filed off command */
104 CR95HF_FieldOffState_WaitAnswer, /*!< Wait answer */
105 CR95HF_FieldOffState_Finish /*!< Finish */
106 }tCR95HFFieldOffState;
107
108 /*----------------------------------------------------------------------------*/
109 /**
110 * \enum tCR95HFField15693State
111 * \brief Define the different state of the enable ISO15693 Field state machine.
112 */
113 /*----------------------------------------------------------------------------*/
114 typedef enum {
115 CR95HF_Field15693State_Start, /*!< Start */
116 CR95HF_Field15693State_Send, /*!< Send configuration for IS15693 */
117 CR95HF_Field15693State_WaitAnswer, /*!< Wait answer */
118 CR95HF_Field15693State_Finish /*!< Finish */
119 } tCR95HFField15693State;
120
121 /*----------------------------------------------------------------------------*/
122 /**
123 * \enum tCR95HFHibernateState
124 * \brief Define the different state of the hibernate state machine.
125 */
126 /*----------------------------------------------------------------------------*/
127 typedef enum {
128 CR95HF_HibernateState_Start, /*!< Start */
129 CR95HF_HibernateState_Send, /*!< Send hibernate command */
130 CR95HF_HibernateState_WaitAnswer, /*!< Wait answer */
131 CR95HF_HibernateState_Finish /*:< Finish */
132 }tCR95HFHibernateState;
133
134 /*----------------------------------------------------------------------------*/
135 /**
136 * \enum tCR95HFReadState
137 * \brief Define the different state of the read state machine.
138 */
139 /*----------------------------------------------------------------------------*/
140 typedef enum {
141 CR95HF_ReadState_Start, /*!< Start */
142 CR95HF_ReadState_Send, /*!< Send read command */
143 CR95HF_ReadState_WaitAnswer, /*!< Wait answer */
144 CR95HF_ReadState_Finish /*!< Finish */
145 }tCR95HFReadState;
146
147 /*----------------------------------------------------------------------------*/
148 /**
149 * \enum tCR95HFWriteState
150 * \brief Define the different state of the write state machine.
151 */
152 /*----------------------------------------------------------------------------*/
153 typedef enum {
154 CR95HF_WriteState_Start, /*!< Start */
155 CR95HF_WriteState_Send, /*!< Send write command and data */
156 CR95HF_WriteState_WaitAnswer, /*!< Wait answer */
157 CR95HF_WriteState_Finish /*!< Finish */
158 }tCR95HFWriteState;
159
160 /*----------------------------------------------------------------------------*/
161 /**
162 * \enum tCR95HFBridgeState
163 * \brief Define the different state of the bridge state machine.
164 */
165 /*----------------------------------------------------------------------------*/
166 typedef enum {
167 CR95HF_BridgeState_Start, /*!< Start */
168 CR95HF_BridgeState_Send, /*!< Send command bridge */
169 CR95HF_BridgeState_WaitAnswer, /*!< Wait answer */
170 CR95HF_BridgeState_Finish /*!< Finish */
171 }tCR95HFBridgeState;
172
173
174 /*----------------------------------------------------------------------------*/
175 /**
176 * \enum tCR95HFReturn
177 * \brief Define the module error.
178 */
179 /*----------------------------------------------------------------------------*/
180 typedef enum {
181 CR95HF_RETURN_WORKING = 0, /*!< Module is working */
182 CR95HF_RETURN_OK = 1, /*!< module return OK */
183 CR95HF_RETURN_ECHO_ERROR = 2, /*!< Module echo error */
184 CR95HF_RETURN_FIELDOFF_ERROR = 3, /*!< Module field off error*/
185 CR95HF_RETURN_FIELD15693_ERROR = 4, /*!< Module ISO15693 error */
186 CR95HF_RETURN_HIBERNATE_ERROR = 5, /*!< Module hibernate error */
187 CR95HF_RETURN_READ_ERROR = 6, /*!< Module read error */
188 CR95HF_RETURN_WRITE_ERROR = 7, /*!< Module write error */
189 CR95HF_RETURN_STATEMACHINE_ERROR = 0xFFFE, /*!< State machine error */
190 CR95HF_RETURN_BUSY = 0xFFFF /*!< Module is busy */
191 }tCR95HFReturn;
192
193 /*----------------------------------------------------------------------------*/
194 /**
195 * \struct tCR95HFCtrl
196 * \brief Define the structure used to control the CR95HF module.
197 */
198 /*----------------------------------------------------------------------------*/
199 typedef struct {
200 union {
201 struct {
202 unsigned short isWorking : 1; /*!< 0 if no command are currently executed */
203 unsigned short timeout : 1; /*!< Last command timeout */
204 unsigned short anwserReceived : 1; /*!< answer Received */
205 unsigned short sizeReceive : 1; /*!< The number of char as been receive */
206 unsigned short RSVD : 12; /*!< RESERVED */
207 }bits;
208 unsigned short all;
209 }flags;
210
211 char receiveBuf[CR95HF_RX_BUF_SIZE]; /*!< Receive buffer */
212 unsigned short rxPos; /*!< Write index of the Rx buffer */
213 char answerKeyWord[CR95HF_ANSWER_BUF_SIZE]; /*!< KeyWord use to indicate that the answer are received */
214 unsigned short answerSize; /*!< Size of the answer */
215 unsigned short waitForNbrRx; /*!< if dif from 0 wait for this number of char receive from uart */
216 unsigned long refMs; /*!< Time reference for the timeout and the time completion */
217 unsigned long timeoutMs; /*!< tiemout for the current command (ms) */
218 unsigned short completionTimeMs; /*!< Minimum completion time for the current command */
219 tCR95HFCommand command; /*!< Current command (state machine) */
220 unsigned long commandState; /*!< Current state of the current state machine */
221 unsigned long resultCode; /*!< Result code */
222 unsigned short deviceRegAddr; /*!< Device register address */
223 unsigned long deviceReg; /*!< Device read result or write data*/
224 char bridgeCommand[CR95HF_ANSWER_BUF_SIZE];
225 unsigned short bridgeCommandLength;
226 } tCR95HFCtrl;
227
228 /*----------------------------------------------------------------------------*/
229 /**
230 * \enum tCR95HFIsReady
231 * \brief Define constant to indicate if module is used or not.
232 */
233 /*----------------------------------------------------------------------------*/
234 typedef enum {
235 CR95HF_IS_BUSY, /*!< CR95HF is busy */
236 CR95HF_IS_READY /*!< CR95HF is ready */
237 }tCR95HFIsReady;
238 /*############################################################################################*/
239 /*## END TYPEDEF/STRUCT/ENUM/UNION ###########################################################*/
240 /*############################################################################################*/
241
242
243
244 /*############################################################################################*/
245 /*## VARIABLES ###############################################################################*/
246 /*############################################################################################*/
247 /*----------------------------------------------------------------------------*/
248 /**
249 * \var CR95HFCtrl
250 * \brief Variable used by the state machine of the CR95HF.
251 */
252 /*----------------------------------------------------------------------------*/
253 extern tCR95HFCtrl CR95HFCtrl;
254 /*############################################################################################*/
255 /*## END VARIABLES ###########################################################################*/
256 /*############################################################################################*/
257
258
259
260 /*############################################################################################*/
261 /*## DECLARATION FONCTIONS ###################################################################*/
262 /*############################################################################################*/
263 /*----------------------------------------------------------------------------*/
264 /**
265 * \fn void CR95HFInit (void)
266 * \brief Function used to initialize the CR95HF global manager.
267 */
268 /*----------------------------------------------------------------------------*/
269 extern void CR95HFInit (void);
270
271 /*----------------------------------------------------------------------------*/
272 /**
273 * \fn void CR95HFManager (void)
274 * \brief Global manager of the CR95HF module.
275 */
276 /*----------------------------------------------------------------------------*/
277 extern void CR95HFManager (void);
278
279 /*----------------------------------------------------------------------------*/
280 /**
281 * \fn tCR95HFIsReady CR95HFManagerIsReady()
282 * \brief Return the current state of the CR95HF module in it's manager.
283 */
284 /*----------------------------------------------------------------------------*/
285 extern tCR95HFIsReady CR95HFManagerIsReady();
286
287 /*----------------------------------------------------------------------------*/
288 /**
289 * \brief Manager used to deal each specific state.
290 */
291 ///@{
292 /*----------------------------------------------------------------------------*/
293 extern void CR95HFStartEcho (void);
294 extern void CR95HFStartFieldOff (void);
295 extern void CR95HFStartField15693 (void);
296 extern void CR95HFStartHibernate (void);
297 extern void CR95HFStartRead (unsigned short addr);
298 extern void CR95HFStartWrite (unsigned short addr, unsigned long data);
299 extern void CR95HFStartBridge (char* data, unsigned short dataLength);
300 ///@}
301 /*############################################################################################*/
302 /*## END DECLARATION FONCTIONS ###############################################################*/
303 /*############################################################################################*/
304 #endif
tCR95HFCommand
tCR95HFCommand
Define the global state machine of the CR95HF interface.
Definition: CR95HF.h:71
CR95HFStartField15693
void CR95HFStartField15693(void)
Manager used to deal each specific state.
Definition: CR95HF.c:655
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
tick.h
Headerfile for tick.
CR95HF_WriteState_WaitAnswer
Definition: CR95HF.h:156
CR95HFStartWrite
void CR95HFStartWrite(unsigned short addr, unsigned long data)
Manager used to deal each specific state.
Definition: CR95HF.c:687
CR95HF_FieldOffState_WaitAnswer
Definition: CR95HF.h:104
tCR95HFField15693State
tCR95HFField15693State
Define the different state of the enable ISO15693 Field state machine.
Definition: CR95HF.h:114
CR95HF_RETURN_WRITE_ERROR
Definition: CR95HF.h:188
tCR95HFCtrl::refMs
unsigned long refMs
Definition: CR95HF.h:216
StringTools.h
Functions used to manipulate string. \ details All Right Reserved.
CR95HF_RETURN_FIELD15693_ERROR
Definition: CR95HF.h:185
tCR95HFCtrl::deviceReg
unsigned long deviceReg
Definition: CR95HF.h:223
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
CR95HFManagerIsReady
tCR95HFIsReady CR95HFManagerIsReady()
Return the current state of the CR95HF module in it's manager.
Definition: CR95HF.c:718
CR95HF_WriteState_Start
Definition: CR95HF.h:154
CR95HF_HibernateState_Finish
Definition: CR95HF.h:131
CR95HF_COMMAND_READ
Definition: CR95HF.h:77
CR95HF_RETURN_READ_ERROR
Definition: CR95HF.h:187
tCR95HFCtrl
Define the structure used to control the CR95HF module.
Definition: CR95HF.h:199
tCR95HFHibernateState
tCR95HFHibernateState
Define the different state of the hibernate state machine.
Definition: CR95HF.h:127
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
tCR95HFBridgeState
tCR95HFBridgeState
Define the different state of the bridge state machine.
Definition: CR95HF.h:166
CR95HFManager
void CR95HFManager(void)
Global manager of the CR95HF module.
Definition: CR95HF.c:598
CR95HF_ANSWER_BUF_SIZE
#define CR95HF_ANSWER_BUF_SIZE
Define the buffer size.
Definition: CR95HF.h:45
CR95HF_Field15693State_Start
Definition: CR95HF.h:115
CR95HF_ReadState_Finish
Definition: CR95HF.h:144
CR95HF_RETURN_WORKING
Definition: CR95HF.h:181
tCR95HFReadState
tCR95HFReadState
Define the different state of the read state machine.
Definition: CR95HF.h:140
CR95HF_BridgeState_WaitAnswer
Definition: CR95HF.h:169
tCR95HFCtrl::answerSize
unsigned short answerSize
Definition: CR95HF.h:214
CR95HF_Field15693State_Send
Definition: CR95HF.h:116
CR95HF_RETURN_STATEMACHINE_ERROR
Definition: CR95HF.h:189
CR95HFStartEcho
void CR95HFStartEcho(void)
Manager used to deal each specific state.
Definition: CR95HF.c:635
tCR95HFEchoState
tCR95HFEchoState
Define the different state of the Echo global state machine.
Definition: CR95HF.h:88
CR95HF_ReadState_Start
Definition: CR95HF.h:141
CR95HF_COMMAND_FIELD15693
Definition: CR95HF.h:75
CR95HF_IS_READY
Definition: CR95HF.h:236
CR95HF_ReadState_WaitAnswer
Definition: CR95HF.h:143
tCR95HFFieldOffState
tCR95HFFieldOffState
Define the different state of the Field off state machine.
Definition: CR95HF.h:101
CR95UartMapper.h
Headerfile for Uart mapping on external/internal CR95.
CR95HFStartRead
void CR95HFStartRead(unsigned short addr)
Manager used to deal each specific state.
Definition: CR95HF.c:676
CR95HF_RETURN_HIBERNATE_ERROR
Definition: CR95HF.h:186
tCR95HFCtrl::resultCode
unsigned long resultCode
Definition: CR95HF.h:221
CR95HF_EchoState_Send
Definition: CR95HF.h:90
CR95HFStartFieldOff
void CR95HFStartFieldOff(void)
Manager used to deal each specific state.
Definition: CR95HF.c:645
CR95HF_Field15693State_WaitAnswer
Definition: CR95HF.h:117
tCR95HFCtrl::bridgeCommandLength
unsigned short bridgeCommandLength
Definition: CR95HF.h:225
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
CR95HF_WriteState_Send
Definition: CR95HF.h:155
CR95HF_BridgeState_Finish
Definition: CR95HF.h:170
CR95HF_RETURN_BUSY
Definition: CR95HF.h:190
tCR95HFCtrl::rxPos
unsigned short rxPos
Definition: CR95HF.h:212
CR95HFStartHibernate
void CR95HFStartHibernate(void)
Manager used to deal each specific state.
Definition: CR95HF.c:666
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
CR95HF_Field15693State_Finish
Definition: CR95HF.h:118
tCR95HFWriteState
tCR95HFWriteState
Define the different state of the write state machine.
Definition: CR95HF.h:153
CR95HF_FieldOffState_Send
Definition: CR95HF.h:103
CR95HF_BridgeState_Start
Definition: CR95HF.h:167
CR95HFInit
void CR95HFInit(void)
Function used to initialize the CR95HF global manager.
Definition: CR95HF.c:585
tCR95HFCtrl::command
tCR95HFCommand command
Definition: CR95HF.h:219
CR95HF_EchoState_WaitAnswer
Definition: CR95HF.h:91
CR95HF_COMMAND_BRIDGE
Definition: CR95HF.h:79
CR95HF_COMMAND_FIELDOFF
Definition: CR95HF.h:74
tCR95HFReturn
tCR95HFReturn
Define the module error.
Definition: CR95HF.h:180
CR95HF_WriteState_Finish
Definition: CR95HF.h:157
CR95HFCtrl
tCR95HFCtrl CR95HFCtrl
Variable used by the state machine of the CR95HF.
Definition: CR95HF.c:67
CR95HF_RETURN_ECHO_ERROR
Definition: CR95HF.h:183
tCR95HFCtrl::timeoutMs
unsigned long timeoutMs
Definition: CR95HF.h:217
CR95HF_FieldOffState_Start
Definition: CR95HF.h:102
CR95HFStartBridge
void CR95HFStartBridge(char *data, unsigned short dataLength)
Manager used to deal each specific state.
Definition: CR95HF.c:699
CR95HF_HibernateState_WaitAnswer
Definition: CR95HF.h:130