Mistake on this page?
Report an issue in GitHub or email us
transceiver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2018, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 /**
18  * \file transceiver.h
19  * \copyright Copyright (c) ARM Ltd 2013
20  * \author Donatien Garnier
21  */
22 
23 #ifndef TRANSCEIVER_H_
24 #define TRANSCEIVER_H_
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include "stack/nfc_common.h"
31 
32 typedef struct __nfc_tech nfc_tech_t;
33 typedef struct __transceiver nfc_transceiver_t;
35 
36 #include "protocols.h"
37 #include "platform/nfc_transport.h"
38 #include "platform/nfc_scheduler.h"
39 
40 enum __nfc_framing {
41  nfc_framing_unknown,
42 
43  nfc_framing_target_mode_detector, //Framing is unknown and will be detected by the hardware
44  nfc_framing_target_a_106,
45  nfc_framing_target_b_106,
46  nfc_framing_target_f_212,
47  nfc_framing_target_f_424,
48 
49  nfc_framing_initiator_a_106,
50  nfc_framing_initiator_b_106,
51  nfc_framing_initiator_f_212,
52  nfc_framing_initiator_f_424,
53 };
54 typedef enum __nfc_framing nfc_framing_t;
55 
56 struct __nfc_tech {
57  unsigned int nfc_type1 : 1;
58  unsigned int nfc_type2 : 1;
59  unsigned int nfc_type3 : 1;
60  unsigned int nfc_iso_dep_a : 1;
61  unsigned int nfc_iso_dep_b : 1;
62  unsigned int nfc_nfc_dep_a : 1;
63  unsigned int nfc_nfc_dep_f_212 : 1;
64  unsigned int nfc_nfc_dep_f_424 : 1;
65 };
66 
67 typedef struct __polling_options polling_options_t;
69  unsigned int bail_at_first_target : 1;
70  unsigned int bail_at_first_tech : 1;
71  int32_t listen_for;
72 };
73 
74 typedef void (*transceiver_cb_t)(nfc_transceiver_t *pTransceiver, nfc_err_t ret, void *pUserData);
75 typedef void (*set_protocols_fn_t)(nfc_transceiver_t *pTransceiver, nfc_tech_t initiators, nfc_tech_t targets, polling_options_t options);
76 typedef void (*poll_fn_t)(nfc_transceiver_t *pTransceiver);
77 typedef void (*set_crc_fn_t)(nfc_transceiver_t *pTransceiver, bool crcOut, bool crcIn);
78 typedef void (*set_timeout_fn_t)(nfc_transceiver_t *pTransceiver, int timeout);
79 typedef void (*set_transceive_options_fn_t)(nfc_transceiver_t *pTransceiver, bool transmit, bool receive, bool repoll);
80 typedef void (*set_transceive_framing_fn_t)(nfc_transceiver_t *pTransceiver, nfc_framing_t framing);
81 typedef void (*set_write_fn_t)(nfc_transceiver_t *pTransceiver, ac_buffer_t *pWriteBuf); //Set write buffer
82 typedef ac_buffer_t *(*get_read_fn_t)(nfc_transceiver_t *pTransceiver); //Get read buffer
83 typedef size_t (*get_last_byte_length_fn_t)(nfc_transceiver_t *pTransceiver);
84 typedef void (*set_last_byte_length_fn_t)(nfc_transceiver_t *pTransceiver, size_t lastByteLength);
85 typedef size_t (*get_first_byte_align_fn_t)(nfc_transceiver_t *pTransceiver);
86 typedef void (*set_first_byte_align_fn_t)(nfc_transceiver_t *pTransceiver, size_t firstByteAlign);
87 typedef void (*transceive_fn_t)(nfc_transceiver_t *pTransceiver);
88 typedef void (*abort_fn_t)(nfc_transceiver_t *pTransceiver);
89 typedef void (*close_fn_t)(nfc_transceiver_t *pTransceiver);
90 typedef void (*sleep_fn_t)(nfc_transceiver_t *pTransceiver, bool sleep);
91 
93  set_protocols_fn_t set_protocols;
94  poll_fn_t poll;
95  set_crc_fn_t set_crc;
96  set_timeout_fn_t set_timeout;
97  set_transceive_options_fn_t set_transceive_options;
98  set_transceive_framing_fn_t set_transceive_framing;
99  set_write_fn_t set_write;
100  get_read_fn_t get_read;
101  set_last_byte_length_fn_t set_last_byte_length;
102  get_last_byte_length_fn_t get_last_byte_length;
103  set_first_byte_align_fn_t set_first_byte_align;
104  transceive_fn_t transceive;
105  abort_fn_t abort;
106  close_fn_t close;
107  sleep_fn_t sleep;
108 };
109 
110 typedef struct __nfc_a_info nfc_a_info_t;
111 struct __nfc_a_info {
112  uint8_t uid[10];
113  size_t uidLength;
114  uint8_t sak;
115  uint8_t atqa[2];
116 };
117 
118 typedef struct __nfc_b_info nfc_b_info_t;
119 struct __nfc_b_info {
120  uint8_t pupi[4];
121  uint8_t application_data[4];
122  uint8_t protocol_info[3];
123 };
124 
125 typedef struct __nfc_f_info nfc_f_info_t;
126 struct __nfc_f_info {
127  uint8_t nfcid2[8];
128 };
129 
130 typedef struct __nfc_info nfc_info_t;
131 
132 struct __nfc_info {
133  nfc_tech_t type;
134  union {
135  nfc_a_info_t nfcA;
136  nfc_b_info_t nfcB;
137  nfc_f_info_t nfcF;
138  };
139 };
140 
141 #define MUNFC_MAX_REMOTE_TARGETS 4
143  const transceiver_impl_t *fn; //vtable
144 
145  bool initiator_ntarget;
146  nfc_info_t remote_targets[MUNFC_MAX_REMOTE_TARGETS];
147  size_t remote_targets_count;
148 
149  nfc_tech_t active_tech;
150 
151  transceiver_cb_t cb; //Callback to upper layer
152  void *pUserData;
153  nfc_task_t task; //Task for deferred execution
154 
155  nfc_transport_t *pTransport;
156  nfc_scheduler_t scheduler;
157 };
158 
159 void transceiver_init(nfc_transceiver_t *pTransceiver, nfc_transport_t *pTransport, nfc_scheduler_timer_t *pTimer);
160 
161 static inline void transceiver_set_protocols(nfc_transceiver_t *pTransceiver, nfc_tech_t initiators, nfc_tech_t targets, polling_options_t options)
162 {
163  pTransceiver->fn->set_protocols(pTransceiver, initiators, targets, options);
164 }
165 
166 static inline void transceiver_poll(nfc_transceiver_t *pTransceiver, transceiver_cb_t cb, void *pUserData)
167 {
168  pTransceiver->cb = cb;
169  pTransceiver->pUserData = pUserData;
170  pTransceiver->fn->poll(pTransceiver);
171 }
172 
173 static inline void transceiver_set_crc(nfc_transceiver_t *pTransceiver, bool crcOut, bool crcIn)
174 {
175  pTransceiver->fn->set_crc(pTransceiver, crcOut, crcIn);
176 }
177 
178 static inline void transceiver_set_timeout(nfc_transceiver_t *pTransceiver, int timeout)
179 {
180  pTransceiver->fn->set_timeout(pTransceiver, timeout);
181 }
182 
183 static inline void transceiver_set_transceive_options(nfc_transceiver_t *pTransceiver, bool transmit, bool receive, bool repoll)
184 {
185  pTransceiver->fn->set_transceive_options(pTransceiver, transmit, receive, repoll);
186 }
187 
188 static inline void transceiver_set_transceive_framing(nfc_transceiver_t *pTransceiver, nfc_framing_t framing)
189 {
190  pTransceiver->fn->set_transceive_framing(pTransceiver, framing);
191 }
192 
193 static inline void transceiver_set_write(nfc_transceiver_t *pTransceiver, ac_buffer_t *pWriteBuf)
194 {
195  pTransceiver->fn->set_write(pTransceiver, pWriteBuf);
196 }
197 
198 static inline ac_buffer_t *transceiver_get_read(nfc_transceiver_t *pTransceiver)
199 {
200  return pTransceiver->fn->get_read(pTransceiver);
201 }
202 
203 static inline size_t transceiver_get_last_byte_length(nfc_transceiver_t *pTransceiver)
204 {
205  return pTransceiver->fn->get_last_byte_length(pTransceiver);
206 }
207 
208 static inline void transceiver_set_last_byte_length(nfc_transceiver_t *pTransceiver, size_t lastByteLength)
209 {
210  pTransceiver->fn->set_last_byte_length(pTransceiver, lastByteLength);
211 }
212 
213 static inline void transceiver_set_first_byte_align(nfc_transceiver_t *pTransceiver, size_t firstByteAlign)
214 {
215  pTransceiver->fn->set_first_byte_align(pTransceiver, firstByteAlign);
216 }
217 
218 static inline void nfc_transceiver_transceive(nfc_transceiver_t *pTransceiver, transceiver_cb_t cb, void *pUserData)
219 {
220  pTransceiver->cb = cb;
221  pTransceiver->pUserData = pUserData;
222  pTransceiver->fn->transceive(pTransceiver);
223 }
224 
225 static inline void transceiver_abort(nfc_transceiver_t *pTransceiver)
226 {
227  pTransceiver->fn->abort(pTransceiver);
228 }
229 
230 static inline void transceiver_close(nfc_transceiver_t *pTransceiver)
231 {
232  pTransceiver->fn->close(pTransceiver);
233 }
234 
235 static inline bool transceiver_is_initiator_mode(nfc_transceiver_t *pTransceiver)
236 {
237  return pTransceiver->initiator_ntarget;
238 }
239 
240 static inline nfc_tech_t transceiver_get_active_techs(nfc_transceiver_t *pTransceiver)
241 {
242  return pTransceiver->active_tech;
243 }
244 
245 static inline nfc_scheduler_t *transceiver_get_scheduler(nfc_transceiver_t *pTransceiver)
246 {
247  return &pTransceiver->scheduler;
248 }
249 
250 static inline const nfc_info_t *transceiver_get_remote_target_info(nfc_transceiver_t *pTransceiver, size_t number)
251 {
252  if (number > pTransceiver->remote_targets_count) {
253  return NULL;
254  }
255  return &pTransceiver->remote_targets[number];
256 }
257 
258 static inline size_t transceiver_get_remote_targets_count(nfc_transceiver_t *pTransceiver)
259 {
260  return pTransceiver->remote_targets_count;
261 }
262 
263 static inline void transceiver_sleep(nfc_transceiver_t *pTransceiver, bool sleep)
264 {
265  pTransceiver->fn->sleep(pTransceiver, sleep);
266 }
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 
272 #endif /* TRANSCEIVER_H_ */
int poll(pollfh fhs[], unsigned nfhs, int timeout)
A mechanism to multiplex input/output over a set of file handles(file descriptors).
int nfc_err_t
Type for NFC errors.
Definition: nfc_errors.h:59
static void sleep(void)
Send the microcontroller to sleep.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.