Commit graph

12 commits

Author SHA1 Message Date
Philippe Teuwen
e4df2f3334 astyle 2017-02-18 13:05:59 +01:00
Olliver Schinagl
e946f7a97a drivers: pn532_i2c: Errata on i2c timing
The datasheet is wrong for the pn532_i2c. After having constant issues
with the device failing to respond on the bus and after contacting NXP
about this, it turns out 1.3 ms is too tight. The official timing spec
is unknown for now, but we tested 4 and 5 ms without problems. Thus we
have choosen 5 ms as a safe delay.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-12-06 11:40:56 +01:00
Olliver Schinagl
d960673681 drivers: pn532_i2c: Add retry on error mechanism
Currently, we very occasionally can EXNIO errors from pn532_i2c_write() ->
i2c_write() -> write(). This may happen about once every 30 seconds.
Based from the kernel sources, EXNIO happens if the chip no longer
responds to its own address.

To make sure we do not loose any sent packets, we retry to send
PN532_SEND_RETRIES number of times. Since we miss 1 every 30 or so
seconds, doing 1 retry should be fine.

This might be considered a hack as the failure may be some other timing
related issue.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-10-24 13:05:42 +02:00
Olliver Schinagl
8f8f780c2b drivers: pn532_i2c: Respect proper timing specifications
The pn532 user manual states that after a i2c stop condition and before a i2c
start condition there should be a delay of minimally 1.3 milliseconds.
This is probably a limitation of the i2c peripheral or the firmware. In
any case, each i2c_read and i2c_write creates the packets which are
complemented with start/stop markers. It is thus required to take care
of timing in these two functions.

We solve this by wrapping the lower i2c_read and i2c_write functions for
the pn532, as this requirement is not for all chips.

Currently, we keep time using local variable, and thus the code is not
thread-safe. With libnfc being single threaded and only one instances of
libnfc can open a bus anyway, this is not yet a problem.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-10-24 12:02:58 +02:00
Olliver Schinagl
b953002f8f drivers: pn532_i2c: Clarify preamble and start byte
The pn532 documentation differs slightly from the included ascii art
documentation on how a packet looks like. The preamble was omitted
however the postamble is mentioned. This patch adds the Preamble to the
ascii frame documentation.

The code later refers incorrectly to the start byte as the preamble.
This variable was renamed to more descriptively state that it is the
preambe and the start bytes.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-10-24 12:00:36 +02:00
Philippe Teuwen
3d040d73f3 Fix memory leak
Problems reported by Coverity:

CID 1090335 ( of 1): Resource leak (RESOURCE_LEAK)
24. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.

CID 1090336 ( of 1): Resource leak (RESOURCE_LEAK)
10. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.

CID 1090337 ( of 1): Resource leak (RESOURCE_LEAK)
21. leaked_storage: Variable "i2cPorts" going out of scope leaks the storage it points to.

CID 1090338 ( of 1): Resource leak (RESOURCE_LEAK)
21. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.

CID 1090339 ( of 1): Resource leak (RESOURCE_LEAK)
23. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.
2013-09-19 23:34:52 +02:00
Philippe Teuwen
bb5b712a74 Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
Philippe Teuwen
03e1f23a40 Make use of new PN53x_ACK_FRAME__LEN 2013-06-15 23:14:54 +02:00
Laurent Latil
80a41010fb Fix various problems in I2C support of PN532: - Fix a memory leak in pn532_i2c_wait_rdyframe() - Remove unused parameters and local variables - Fix all other compilation warnings
Note: a new constant (PN53x_ACK_FRAME__LEN) has been defined in
pn53x-internal.h file to avoid hard coding the ACK frame length.
2013-06-15 22:53:35 +02:00
Philippe Teuwen
3cd26a18f1 I2C: add Laurent Latil as author 2013-06-15 00:04:06 +02:00
Philippe Teuwen
238be3f068 make style 2013-06-15 00:01:25 +02:00
Laurent Latil
1b11450312 Add I2C protocol support for PN532. 2013-06-14 23:59:46 +02:00