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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
pn512_hw.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 pn512_hw.h 00019 * \copyright Copyright (c) ARM Ltd 2013 00020 * \author Donatien Garnier 00021 */ 00022 00023 #ifndef PN512_HW_H_ 00024 #define PN512_HW_H_ 00025 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif 00029 00030 #include "stack/nfc_common.h" 00031 #include "pn512.h" 00032 00033 //Utility for transport: SPI address read/write 00034 #define PN512_SPI_ADDR_R(x) ((1<<7) | ((x) << 1)) 00035 #define PN512_SPI_ADDR_W(x) ((0<<7) | ((x) << 1)) 00036 00037 void pn512_hw_init(pn512_t *pPN512); 00038 00039 /** \internal Write bytes at the specified address on the underlying transport link 00040 * \param pPN512 pointer to pn512_t structure 00041 * \param addr address at which to write 00042 * \param buf buffer to write 00043 * \param len length of buffer 00044 */ 00045 static inline void pn512_hw_write(pn512_t *pPN512, uint8_t addr, uint8_t *buf, size_t len) 00046 { 00047 nfc_transport_write(((nfc_transceiver_t *)pPN512)->pTransport, addr, buf, len); 00048 } 00049 00050 /** \internal Read bytes from the specified address on the underlying transport link 00051 * \param pPN512 pointer to pn512_t structure 00052 * \param addr address from which to read 00053 * \param buf buffer to read 00054 * \param len length of buffer 00055 */ 00056 static inline void pn512_hw_read(pn512_t *pPN512, uint8_t addr, uint8_t *buf, size_t len) 00057 { 00058 nfc_transport_read(((nfc_transceiver_t *)pPN512)->pTransport, addr, buf, len); 00059 } 00060 00061 static inline void pn512_hw_write_buffer(pn512_t *pPN512, uint8_t addr, ac_buffer_t *pData, size_t len) 00062 { 00063 while (len > 0) { 00064 if (ac_buffer_reader_readable(pData) == 0) { 00065 return; 00066 } 00067 size_t cpyLen = MIN(len, ac_buffer_reader_current_buffer_length(pData)); 00068 nfc_transport_write(((nfc_transceiver_t *)pPN512)->pTransport, addr, ac_buffer_reader_current_buffer_pointer(pData), cpyLen); 00069 ac_buffer_read_n_skip(pData, cpyLen); 00070 len -= cpyLen; 00071 } 00072 } 00073 00074 static inline void pn512_hw_read_buffer(pn512_t *pPN512, uint8_t addr, ac_buffer_builder_t *pData, size_t len) 00075 { 00076 while (len > 0) { 00077 if (ac_buffer_builder_writable(pData) == 0) { 00078 return; 00079 } 00080 //Read payload 00081 size_t cpyLen = MIN(len, ac_buffer_builder_space(pData)); 00082 nfc_transport_read(((nfc_transceiver_t *)pPN512)->pTransport, addr, ac_buffer_builder_write_position(pData), cpyLen); 00083 ac_buffer_builder_write_n_skip(pData, cpyLen); 00084 len -= cpyLen; 00085 } 00086 } 00087 00088 #ifdef __cplusplus 00089 } 00090 #endif 00091 00092 #endif /* PN512_HW_H_ */
Generated on Tue Jul 12 2022 13:54:41 by
1.7.2