mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

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