Skip to content

Commit 24f801d

Browse files
author
Amanda Butler
authored
Merge pull request #669 from paul-szczepanek-arm/eeprom
NFC EEPROM driver porting guide
2 parents 25352cb + d791d40 commit 24f801d

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<h2 id="NFC-port">NFC EEPROM driver porting guide</h2>
2+
3+
NFC EEPROM provides low level operations needed to create an NFC TAG. The device usually allows one device at a time to read and write into a shared memory through one of two channels. One is the radio channel that external devices interacting with the device use. The other is wired to the MCU. Either device needs to obtain a session before performing its operations. The session is released as the last step or through a timeout.
4+
5+
### Class hierarchy
6+
7+
The `NFCTarget` uses an implementation of `NFCEEPROMDriver` as the backend that delivers the fundamental operations needed to access and modify the memory containing the NDEF messages. The target implementation of `NFCTarget` creates the instance of the class.
8+
9+
Your implementation inherits from `NFCEEPROMDriver` and implements all the public methods therein.
10+
11+
### Required methods
12+
13+
`NFCEEPROMDriver` defines the following pure virtual methods.
14+
15+
These must return synchronously:
16+
17+
- `void reset()`.
18+
- `size_t read_max_size()`.
19+
20+
These must return their results through calling methods in the `Delegate`:
21+
22+
- `void start_session(bool force = false)`.
23+
- `void end_session()`.
24+
- `void read_bytes(uint32_t address, uint8_t* bytes, size_t count)`.
25+
- `void write_bytes(uint32_t address, const uint8_t* bytes, size_t count)`.
26+
- `void write_size(size_t count)`.
27+
- `void read_size()`.
28+
- `void erase_bytes(uint32_t address, size_t size)`.
29+
30+
#### Implementing `reset`
31+
32+
`reset` is called during initialization and may be called repeatedly. This must be safe to be called at any time and should return when the device is ready for operation.
33+
34+
#### Implementing `read_max_size`
35+
36+
This must synchronously return the (effective) size of the EEPROM memory available to NDEF messages (not including the memory required by other files or headers).
37+
38+
#### Implementing `start_session` and `end_session`
39+
40+
`start_session` and `end_session` open and close the communication with the device. `start_session` has an extra parameter that indicates the session should be started even if it would kill the RF session in the process. Otherwise, the `open_session` triggers the `on_session_opened` with the parameter set to false (failure) if an RF session is already opened.
41+
42+
#### Implementing `read_bytes` and `write_bytes`
43+
44+
Both methods contain the `address`, which is to be used as the starting offset in the file. This starts at the beginning of the body of the file where NDEF messages may be written. You must account for any headers in the offset and size calculations. The `count` parameters are the maximum sizes of the operations, but the operation may return less than the requested counts.
45+
46+
The events `on_bytes_read` and `on_bytes_written` must return the number of bytes successfully read or written in case the maximum size of the operation the device allows is smaller than the request operation. It's up to the caller to call these methods multiple times with appropriate offsets as required.
47+
48+
#### Implementing `read_size` and `write_size`
49+
50+
`read_size` and `write_size` read and write the limits the write and read operations use. Writing or reading beyond the set size must be truncated to the current size.
51+
52+
#### Implementing `erase_bytes`
53+
54+
This is the equivalent of calling `write_bytes` with a buffer filled with `0`. Like `write_bytes`, it must return the number of bytes successfully set to `0`.
55+
56+
### Asynchronous operation
57+
58+
Depending on your hardware, you may support synchronous or asynchronous operation.
59+
60+
We designed the `NFCEEPROMDriver` with asynchronous operation, and the results of long operations are communicated through events. You must use these events, even if your implementation is synchronous.
61+
62+
In asynchronous implementations, you may use an `EventQueue` to schedule processing caused by interrupts. The `NFCTarget` has set up your event queue, which you can get by calling:
63+
64+
`EventQueue* event_queue()`
65+
66+
You may initiate your event processing by calling `call()` on the event queue.
67+
68+
For example:
69+
70+
If your event management occurs in a function called `manage_event`, you should call:
71+
72+
`event_queue()->call(&manage_event);`
73+
74+
The `EventQueue` also accepts passed in parameters and objects for nonstatic method calls. Please see the `EventQueue` documentation for details on calling functions on the queue.
75+
76+
#### Communicating events back to the NFCTarget
77+
78+
All events call methods in the `Delegate` class object that has been set by the `NFCTarget`. Delegate is accessible through:
79+
`Delegate* delegate()`
80+
81+
It implements the following methods:
82+
83+
- `void on_session_started(bool success)`
84+
- `void on_session_ended(bool success)`
85+
- `void on_bytes_read(size_t count)`
86+
- `void on_bytes_written(size_t count)`
87+
- `void on_size_written(bool success)`
88+
- `void on_size_read(bool success, size_t size)`
89+
- `void on_bytes_erased(size_t count)`
90+
91+
You must use these to communicate the results of all asynchronous calls.
92+
93+
### Testing
94+
95+
A macro `NFCEEPROM` is required for the test to build. The module containing your driver should contain `mbed_lib.json`. Add a configuration option for the build system to convert into a macro. Your `mbed_lib.json` could look like this:
96+
97+
```javascript
98+
{
99+
"name": "MBED_NFC_<name of your driver>",
100+
"config": {
101+
"nfceeprom": {
102+
"macro_name": "NFCEEPROM",
103+
"value": true,
104+
"help": "Device supports NFC EEPROM"
105+
}
106+
}
107+
}
108+
```
109+
110+
Run the tests with:
111+
112+
`mbed test -m [mcu] -t [toolchain] -n tests-nfc-eeprom*`.

0 commit comments

Comments
 (0)