Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
transceiver.h
00001 /* 00002 * Copyright (c) 2013-2018, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 /** 00018 * \file transceiver.h 00019 * \copyright Copyright (c) ARM Ltd 2013 00020 * \author Donatien Garnier 00021 */ 00022 00023 #ifndef TRANSCEIVER_H_ 00024 #define TRANSCEIVER_H_ 00025 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif 00029 00030 #include "stack/nfc_common.h" 00031 00032 typedef struct __nfc_tech nfc_tech_t; 00033 typedef struct __transceiver nfc_transceiver_t; 00034 typedef struct __transceiver_impl transceiver_impl_t; 00035 00036 #include "protocols.h" 00037 #include "platform/nfc_transport.h" 00038 #include "platform/nfc_scheduler.h" 00039 00040 enum __nfc_framing { 00041 nfc_framing_unknown, 00042 00043 nfc_framing_target_mode_detector, //Framing is unknown and will be detected by the hardware 00044 nfc_framing_target_a_106, 00045 nfc_framing_target_b_106, 00046 nfc_framing_target_f_212, 00047 nfc_framing_target_f_424, 00048 00049 nfc_framing_initiator_a_106, 00050 nfc_framing_initiator_b_106, 00051 nfc_framing_initiator_f_212, 00052 nfc_framing_initiator_f_424, 00053 }; 00054 typedef enum __nfc_framing nfc_framing_t; 00055 00056 struct __nfc_tech { 00057 unsigned int nfc_type1 : 1; 00058 unsigned int nfc_type2 : 1; 00059 unsigned int nfc_type3 : 1; 00060 unsigned int nfc_iso_dep_a : 1; 00061 unsigned int nfc_iso_dep_b : 1; 00062 unsigned int nfc_nfc_dep_a : 1; 00063 unsigned int nfc_nfc_dep_f_212 : 1; 00064 unsigned int nfc_nfc_dep_f_424 : 1; 00065 }; 00066 00067 typedef struct __polling_options polling_options_t; 00068 struct __polling_options { 00069 unsigned int bail_at_first_target : 1; 00070 unsigned int bail_at_first_tech : 1; 00071 int32_t listen_for; 00072 }; 00073 00074 typedef void (*transceiver_cb_t)(nfc_transceiver_t *pTransceiver, nfc_err_t ret, void *pUserData); 00075 typedef void (*set_protocols_fn_t)(nfc_transceiver_t *pTransceiver, nfc_tech_t initiators, nfc_tech_t targets, polling_options_t options); 00076 typedef void (*poll_fn_t)(nfc_transceiver_t *pTransceiver); 00077 typedef void (*set_crc_fn_t)(nfc_transceiver_t *pTransceiver, bool crcOut, bool crcIn); 00078 typedef void (*set_timeout_fn_t)(nfc_transceiver_t *pTransceiver, int timeout); 00079 typedef void (*set_transceive_options_fn_t)(nfc_transceiver_t *pTransceiver, bool transmit, bool receive, bool repoll); 00080 typedef void (*set_transceive_framing_fn_t)(nfc_transceiver_t *pTransceiver, nfc_framing_t framing); 00081 typedef void (*set_write_fn_t)(nfc_transceiver_t *pTransceiver, ac_buffer_t *pWriteBuf); //Set write buffer 00082 typedef ac_buffer_t *(*get_read_fn_t)(nfc_transceiver_t *pTransceiver); //Get read buffer 00083 typedef size_t (*get_last_byte_length_fn_t)(nfc_transceiver_t *pTransceiver); 00084 typedef void (*set_last_byte_length_fn_t)(nfc_transceiver_t *pTransceiver, size_t lastByteLength); 00085 typedef size_t (*get_first_byte_align_fn_t)(nfc_transceiver_t *pTransceiver); 00086 typedef void (*set_first_byte_align_fn_t)(nfc_transceiver_t *pTransceiver, size_t firstByteAlign); 00087 typedef void (*transceive_fn_t)(nfc_transceiver_t *pTransceiver); 00088 typedef void (*abort_fn_t)(nfc_transceiver_t *pTransceiver); 00089 typedef void (*close_fn_t)(nfc_transceiver_t *pTransceiver); 00090 typedef void (*sleep_fn_t)(nfc_transceiver_t *pTransceiver, bool sleep); 00091 00092 struct __transceiver_impl { 00093 set_protocols_fn_t set_protocols; 00094 poll_fn_t poll; 00095 set_crc_fn_t set_crc; 00096 set_timeout_fn_t set_timeout; 00097 set_transceive_options_fn_t set_transceive_options; 00098 set_transceive_framing_fn_t set_transceive_framing; 00099 set_write_fn_t set_write; 00100 get_read_fn_t get_read; 00101 set_last_byte_length_fn_t set_last_byte_length; 00102 get_last_byte_length_fn_t get_last_byte_length; 00103 set_first_byte_align_fn_t set_first_byte_align; 00104 transceive_fn_t transceive; 00105 abort_fn_t abort; 00106 close_fn_t close; 00107 sleep_fn_t sleep; 00108 }; 00109 00110 typedef struct __nfc_a_info nfc_a_info_t; 00111 struct __nfc_a_info { 00112 uint8_t uid[10]; 00113 size_t uidLength; 00114 uint8_t sak; 00115 uint8_t atqa[2]; 00116 }; 00117 00118 typedef struct __nfc_b_info nfc_b_info_t; 00119 struct __nfc_b_info { 00120 uint8_t pupi[4]; 00121 uint8_t application_data[4]; 00122 uint8_t protocol_info[3]; 00123 }; 00124 00125 typedef struct __nfc_f_info nfc_f_info_t; 00126 struct __nfc_f_info { 00127 uint8_t nfcid2[8]; 00128 }; 00129 00130 typedef struct __nfc_info nfc_info_t; 00131 00132 struct __nfc_info { 00133 nfc_tech_t type; 00134 union { 00135 nfc_a_info_t nfcA; 00136 nfc_b_info_t nfcB; 00137 nfc_f_info_t nfcF; 00138 }; 00139 }; 00140 00141 #define MUNFC_MAX_REMOTE_TARGETS 4 00142 struct __transceiver { 00143 const transceiver_impl_t *fn; //vtable 00144 00145 bool initiator_ntarget; 00146 nfc_info_t remote_targets[MUNFC_MAX_REMOTE_TARGETS]; 00147 size_t remote_targets_count; 00148 00149 nfc_tech_t active_tech; 00150 00151 transceiver_cb_t cb; //Callback to upper layer 00152 void *pUserData; 00153 nfc_task_t task; //Task for deferred execution 00154 00155 nfc_transport_t *pTransport; 00156 nfc_scheduler_t scheduler; 00157 }; 00158 00159 void transceiver_init(nfc_transceiver_t *pTransceiver, nfc_transport_t *pTransport, nfc_scheduler_timer_t *pTimer); 00160 00161 static inline void transceiver_set_protocols(nfc_transceiver_t *pTransceiver, nfc_tech_t initiators, nfc_tech_t targets, polling_options_t options) 00162 { 00163 pTransceiver->fn->set_protocols(pTransceiver, initiators, targets, options); 00164 } 00165 00166 static inline void transceiver_poll(nfc_transceiver_t *pTransceiver, transceiver_cb_t cb, void *pUserData) 00167 { 00168 pTransceiver->cb = cb; 00169 pTransceiver->pUserData = pUserData; 00170 pTransceiver->fn->poll(pTransceiver); 00171 } 00172 00173 static inline void transceiver_set_crc(nfc_transceiver_t *pTransceiver, bool crcOut, bool crcIn) 00174 { 00175 pTransceiver->fn->set_crc(pTransceiver, crcOut, crcIn); 00176 } 00177 00178 static inline void transceiver_set_timeout(nfc_transceiver_t *pTransceiver, int timeout) 00179 { 00180 pTransceiver->fn->set_timeout(pTransceiver, timeout); 00181 } 00182 00183 static inline void transceiver_set_transceive_options(nfc_transceiver_t *pTransceiver, bool transmit, bool receive, bool repoll) 00184 { 00185 pTransceiver->fn->set_transceive_options(pTransceiver, transmit, receive, repoll); 00186 } 00187 00188 static inline void transceiver_set_transceive_framing(nfc_transceiver_t *pTransceiver, nfc_framing_t framing) 00189 { 00190 pTransceiver->fn->set_transceive_framing(pTransceiver, framing); 00191 } 00192 00193 static inline void transceiver_set_write(nfc_transceiver_t *pTransceiver, ac_buffer_t *pWriteBuf) 00194 { 00195 pTransceiver->fn->set_write(pTransceiver, pWriteBuf); 00196 } 00197 00198 static inline ac_buffer_t *transceiver_get_read(nfc_transceiver_t *pTransceiver) 00199 { 00200 return pTransceiver->fn->get_read(pTransceiver); 00201 } 00202 00203 static inline size_t transceiver_get_last_byte_length(nfc_transceiver_t *pTransceiver) 00204 { 00205 return pTransceiver->fn->get_last_byte_length(pTransceiver); 00206 } 00207 00208 static inline void transceiver_set_last_byte_length(nfc_transceiver_t *pTransceiver, size_t lastByteLength) 00209 { 00210 pTransceiver->fn->set_last_byte_length(pTransceiver, lastByteLength); 00211 } 00212 00213 static inline void transceiver_set_first_byte_align(nfc_transceiver_t *pTransceiver, size_t firstByteAlign) 00214 { 00215 pTransceiver->fn->set_first_byte_align(pTransceiver, firstByteAlign); 00216 } 00217 00218 static inline void nfc_transceiver_transceive(nfc_transceiver_t *pTransceiver, transceiver_cb_t cb, void *pUserData) 00219 { 00220 pTransceiver->cb = cb; 00221 pTransceiver->pUserData = pUserData; 00222 pTransceiver->fn->transceive(pTransceiver); 00223 } 00224 00225 static inline void transceiver_abort(nfc_transceiver_t *pTransceiver) 00226 { 00227 pTransceiver->fn->abort(pTransceiver); 00228 } 00229 00230 static inline void transceiver_close(nfc_transceiver_t *pTransceiver) 00231 { 00232 pTransceiver->fn->close(pTransceiver); 00233 } 00234 00235 static inline bool transceiver_is_initiator_mode(nfc_transceiver_t *pTransceiver) 00236 { 00237 return pTransceiver->initiator_ntarget; 00238 } 00239 00240 static inline nfc_tech_t transceiver_get_active_techs(nfc_transceiver_t *pTransceiver) 00241 { 00242 return pTransceiver->active_tech; 00243 } 00244 00245 static inline nfc_scheduler_t *transceiver_get_scheduler(nfc_transceiver_t *pTransceiver) 00246 { 00247 return &pTransceiver->scheduler; 00248 } 00249 00250 static inline const nfc_info_t *transceiver_get_remote_target_info(nfc_transceiver_t *pTransceiver, size_t number) 00251 { 00252 if (number > pTransceiver->remote_targets_count) { 00253 return NULL; 00254 } 00255 return &pTransceiver->remote_targets[number]; 00256 } 00257 00258 static inline size_t transceiver_get_remote_targets_count(nfc_transceiver_t *pTransceiver) 00259 { 00260 return pTransceiver->remote_targets_count; 00261 } 00262 00263 static inline void transceiver_sleep(nfc_transceiver_t *pTransceiver, bool sleep) 00264 { 00265 pTransceiver->fn->sleep(pTransceiver, sleep); 00266 } 00267 00268 #ifdef __cplusplus 00269 } 00270 #endif 00271 00272 #endif /* TRANSCEIVER_H_ */
Generated on Tue Aug 9 2022 00:37:23 by
1.7.2