Mistake on this page?
Report an issue in GitHub or email us
pn512_hw.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 pn512_hw.h
19  * \copyright Copyright (c) ARM Ltd 2013
20  * \author Donatien Garnier
21  */
22 
23 #ifndef PN512_HW_H_
24 #define PN512_HW_H_
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include "stack/nfc_common.h"
31 #include "pn512.h"
32 
33 //Utility for transport: SPI address read/write
34 #define PN512_SPI_ADDR_R(x) ((1<<7) | ((x) << 1))
35 #define PN512_SPI_ADDR_W(x) ((0<<7) | ((x) << 1))
36 
37 void pn512_hw_init(pn512_t *pPN512);
38 
39 /** \internal Write bytes at the specified address on the underlying transport link
40  * \param pPN512 pointer to pn512_t structure
41  * \param addr address at which to write
42  * \param buf buffer to write
43  * \param len length of buffer
44  */
45 static inline void pn512_hw_write(pn512_t *pPN512, uint8_t addr, uint8_t *buf, size_t len)
46 {
47  nfc_transport_write(((nfc_transceiver_t *)pPN512)->pTransport, addr, buf, len);
48 }
49 
50 /** \internal Read bytes from the specified address on the underlying transport link
51  * \param pPN512 pointer to pn512_t structure
52  * \param addr address from which to read
53  * \param buf buffer to read
54  * \param len length of buffer
55  */
56 static inline void pn512_hw_read(pn512_t *pPN512, uint8_t addr, uint8_t *buf, size_t len)
57 {
58  nfc_transport_read(((nfc_transceiver_t *)pPN512)->pTransport, addr, buf, len);
59 }
60 
61 static inline void pn512_hw_write_buffer(pn512_t *pPN512, uint8_t addr, ac_buffer_t *pData, size_t len)
62 {
63  while (len > 0) {
64  if (ac_buffer_reader_readable(pData) == 0) {
65  return;
66  }
67  size_t cpyLen = MIN(len, ac_buffer_reader_current_buffer_length(pData));
68  nfc_transport_write(((nfc_transceiver_t *)pPN512)->pTransport, addr, ac_buffer_reader_current_buffer_pointer(pData), cpyLen);
69  ac_buffer_read_n_skip(pData, cpyLen);
70  len -= cpyLen;
71  }
72 }
73 
74 static inline void pn512_hw_read_buffer(pn512_t *pPN512, uint8_t addr, ac_buffer_builder_t *pData, size_t len)
75 {
76  while (len > 0) {
77  if (ac_buffer_builder_writable(pData) == 0) {
78  return;
79  }
80  //Read payload
81  size_t cpyLen = MIN(len, ac_buffer_builder_space(pData));
82  nfc_transport_read(((nfc_transceiver_t *)pPN512)->pTransport, addr, ac_buffer_builder_write_position(pData), cpyLen);
83  ac_buffer_builder_write_n_skip(pData, cpyLen);
84  len -= cpyLen;
85  }
86 }
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif /* PN512_HW_H_ */
Definition: pn512.h:53
void ac_buffer_read_n_skip(ac_buffer_t *pBuf, size_t size)
Skip n bytes from buffer reader and advance read posiion.
size_t ac_buffer_reader_readable(const ac_buffer_t *pBuf)
Get number of bytes readable from buffer.
const uint8_t * ac_buffer_reader_current_buffer_pointer(ac_buffer_t *pBuf)
Get a pointer to the current position within this buffer&#39;s current backing array. ...
#define MIN(a, b)
Returns the minimum value between a and b.
Definition: lora_phy_ds.h:44
void ac_buffer_builder_write_n_skip(ac_buffer_builder_t *pBuilder, size_t size)
Skip n-bytes in ac_buffer builder.
static size_t ac_buffer_builder_writable(ac_buffer_builder_t *pBuilder)
Get number of writable bytes in ac_buffer builder.
static size_t ac_buffer_builder_space(ac_buffer_builder_t *pBuilder)
Get space in ac_buffer builder.
size_t ac_buffer_reader_current_buffer_length(ac_buffer_t *pBuf)
Get the number of bytes readable within the current backing array.
static uint8_t * ac_buffer_builder_write_position(ac_buffer_builder_t *pBuilder)
Get ac_buffer builder&#39;s pointer to write position.
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.