Mbed OS Reference
Loading...
Searching...
No Matches
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
27extern "C" {
28#endif
29
30#include "stack/nfc_common.h"
31
32typedef struct __nfc_tech nfc_tech_t;
33typedef struct __transceiver nfc_transceiver_t;
35
36#include "protocols.h"
39
40enum __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};
54typedef enum __nfc_framing nfc_framing_t;
55
56struct __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
69 unsigned int bail_at_first_target : 1;
70 unsigned int bail_at_first_tech : 1;
71 int32_t listen_for;
72};
73
74typedef void (*transceiver_cb_t)(nfc_transceiver_t *pTransceiver, nfc_err_t ret, void *pUserData);
75typedef void (*set_protocols_fn_t)(nfc_transceiver_t *pTransceiver, nfc_tech_t initiators, nfc_tech_t targets, polling_options_t options);
76typedef void (*poll_fn_t)(nfc_transceiver_t *pTransceiver);
77typedef void (*set_crc_fn_t)(nfc_transceiver_t *pTransceiver, bool crcOut, bool crcIn);
78typedef void (*set_timeout_fn_t)(nfc_transceiver_t *pTransceiver, int timeout);
79typedef void (*set_transceive_options_fn_t)(nfc_transceiver_t *pTransceiver, bool transmit, bool receive, bool repoll);
80typedef void (*set_transceive_framing_fn_t)(nfc_transceiver_t *pTransceiver, nfc_framing_t framing);
81typedef void (*set_write_fn_t)(nfc_transceiver_t *pTransceiver, ac_buffer_t *pWriteBuf); //Set write buffer
82typedef ac_buffer_t *(*get_read_fn_t)(nfc_transceiver_t *pTransceiver); //Get read buffer
83typedef size_t (*get_last_byte_length_fn_t)(nfc_transceiver_t *pTransceiver);
84typedef void (*set_last_byte_length_fn_t)(nfc_transceiver_t *pTransceiver, size_t lastByteLength);
85typedef size_t (*get_first_byte_align_fn_t)(nfc_transceiver_t *pTransceiver);
86typedef void (*set_first_byte_align_fn_t)(nfc_transceiver_t *pTransceiver, size_t firstByteAlign);
87typedef void (*transceive_fn_t)(nfc_transceiver_t *pTransceiver);
88typedef void (*abort_fn_t)(nfc_transceiver_t *pTransceiver);
89typedef void (*close_fn_t)(nfc_transceiver_t *pTransceiver);
90typedef 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
110typedef struct __nfc_a_info nfc_a_info_t;
112 uint8_t uid[10];
113 size_t uidLength;
114 uint8_t sak;
115 uint8_t atqa[2];
116};
117
118typedef struct __nfc_b_info nfc_b_info_t;
120 uint8_t pupi[4];
121 uint8_t application_data[4];
122 uint8_t protocol_info[3];
123};
124
125typedef struct __nfc_f_info nfc_f_info_t;
127 uint8_t nfcid2[8];
128};
129
130typedef struct __nfc_info nfc_info_t;
131
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
159void transceiver_init(nfc_transceiver_t *pTransceiver, nfc_transport_t *pTransport, nfc_scheduler_timer_t *pTimer);
160
161static 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
166static 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
173static inline void transceiver_set_crc(nfc_transceiver_t *pTransceiver, bool crcOut, bool crcIn)
174{
175 pTransceiver->fn->set_crc(pTransceiver, crcOut, crcIn);
176}
177
178static inline void transceiver_set_timeout(nfc_transceiver_t *pTransceiver, int timeout)
179{
180 pTransceiver->fn->set_timeout(pTransceiver, timeout);
181}
182
183static 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
188static 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
193static inline void transceiver_set_write(nfc_transceiver_t *pTransceiver, ac_buffer_t *pWriteBuf)
194{
195 pTransceiver->fn->set_write(pTransceiver, pWriteBuf);
196}
197
198static inline ac_buffer_t *transceiver_get_read(nfc_transceiver_t *pTransceiver)
199{
200 return pTransceiver->fn->get_read(pTransceiver);
201}
202
203static inline size_t transceiver_get_last_byte_length(nfc_transceiver_t *pTransceiver)
204{
205 return pTransceiver->fn->get_last_byte_length(pTransceiver);
206}
207
208static 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
213static 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
218static 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
225static inline void transceiver_abort(nfc_transceiver_t *pTransceiver)
226{
227 pTransceiver->fn->abort(pTransceiver);
228}
229
230static inline void transceiver_close(nfc_transceiver_t *pTransceiver)
231{
232 pTransceiver->fn->close(pTransceiver);
233}
234
235static inline bool transceiver_is_initiator_mode(nfc_transceiver_t *pTransceiver)
236{
237 return pTransceiver->initiator_ntarget;
238}
239
240static inline nfc_tech_t transceiver_get_active_techs(nfc_transceiver_t *pTransceiver)
241{
242 return pTransceiver->active_tech;
243}
244
245static inline nfc_scheduler_t *transceiver_get_scheduler(nfc_transceiver_t *pTransceiver)
246{
247 return &pTransceiver->scheduler;
248}
249
250static 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
258static inline size_t transceiver_get_remote_targets_count(nfc_transceiver_t *pTransceiver)
259{
260 return pTransceiver->remote_targets_count;
261}
262
263static 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 nfc_err_t
Type for NFC errors.
Definition: nfc_errors.h:60