Mistake on this page?
Report an issue in GitHub or email us
NFCEEPROMDriver.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MBED_NFC_EEPROM_DRIVER_H
18 #define MBED_NFC_EEPROM_DRIVER_H
19 
20 #include <stdint.h>
21 
22 #include "events/EventQueue.h"
23 
24 namespace mbed {
25 namespace nfc {
26 
27 /**
28  * @addtogroup nfc
29  * @{
30  */
31 
32 /**
33  * The abstraction for a NFC EEPROM driver.
34  * Implementers need to derive from this class and implement its methods.
35  */
37 public:
38  /**
39  * Construct a NFCEEPROM driver instance.
40  */
42 
43  /**
44  * NFCEEPROM driver destructor.
45  */
46  virtual ~NFCEEPROMDriver();
47 
48  /**
49  * The NFCEEPROMDriver delegate.
50  * Methods in this class are called by the driver on completion of long-running operations.
51  */
52  struct Delegate {
53  /**
54  * Completion of session start operation.
55  *
56  * @param[in] success whether this operation succeeded
57  */
58  virtual void on_session_started(bool success) = 0;
59 
60  /**
61  * Completion of session end operation.
62  *
63  * @param[in] success whether this operation succeeded
64  */
65  virtual void on_session_ended(bool success) = 0;
66 
67  /**
68  * Completion of read operation.
69  *
70  * @param[in] count number of bytes actually read
71  */
72  virtual void on_bytes_read(size_t count) = 0;
73 
74  /**
75  * Completion of write operation.
76  *
77  * @param[in] count number of bytes actually written
78  */
79  virtual void on_bytes_written(size_t count) = 0;
80 
81  /**
82  * Completion of size retrieval operation.
83  *
84  * @param[in] success whether this operation succeeded
85  * @param[out] size the current addressable memory size
86  */
87  virtual void on_size_read(bool success, size_t size) = 0;
88 
89  /**
90  * Completion of size setting operation.
91  *
92  * @param[in] success whether this operation succeeded
93  */
94  virtual void on_size_written(bool success) = 0;
95 
96  /**
97  * Completion of erasing operation.
98  *
99  * @param[in] count number of bytes actually erased
100  */
101  virtual void on_bytes_erased(size_t count) = 0;
102 
103  protected:
104  ~Delegate() {}
105  };
106 
107  /**
108  * Set the delegate that will receive events generated by this EEPROM.
109  *
110  * @param[in] delegate the delegate instance to use
111  */
112  void set_delegate(Delegate *delegate);
113 
114  /**
115  * Set the event queue that will be used to schedule event handling
116  *
117  * @param[in] queue the queue instance to use
118  */
119  void set_event_queue(events::EventQueue *queue);
120 
121  /**
122  * Reset and initialize the EEPROM.
123  * This method should complete synchronously.
124  */
125  virtual void reset() = 0;
126 
127  /**
128  * Get the maximum memory size addressable by the EEPROM.
129  */
130  virtual size_t read_max_size() = 0;
131 
132  /**
133  * Start a session of operations (reads, writes, erases, size gets/sets).
134  * This method is called prior to any memory access to allow the underlying implementation
135  * to disable the RF interface or abort the transaction if it's being used.
136  * This method should complete asynchronously by calling has_started_session().
137  */
138  virtual void start_session(bool force = true) = 0; // This could lock the chip's RF interface
139 
140  /**
141  * End a session.
142  * This method should complete asynchronously by calling has_ended_session().
143  */
144  virtual void end_session() = 0;
145 
146  /**
147  * Read bytes from memory.
148  * @param[in] address the virtual address (starting from 0) from which to start the read.
149  * @param[out] bytes a buffer in which the read bytes will be stored.
150  * This buffer should remain valid till the callback is called.
151  * @param[in] count the number of bytes to read.
152  * This method should complete asynchronously by calling has_read_bytes().
153  */
154  virtual void read_bytes(uint32_t address, uint8_t *bytes, size_t count) = 0;
155 
156  /**
157  * Write bytes to memory.
158  * @param[in] address the virtual address (starting from 0) from which to start the write.
159  * @param[in] bytes a buffer from to copy.
160  * This buffer should remain valid till the callback is called.
161  * @param[in] count the number of bytes to write.
162  * This method should complete asynchronously by calling has_written_bytes().
163  */
164  virtual void write_bytes(uint32_t address, const uint8_t *bytes, size_t count) = 0;
165 
166  /**
167  * Retrieve the size of the addressable memory.
168  * This method should complete asynchronously by calling has_gotten_size().
169  */
170  virtual void read_size() = 0;
171 
172  /**
173  * Set the size of the addressable memory.
174  * @param[in] count the number of addressable bytes.
175  * This method should complete asynchronously by calling has_set_size().
176  */
177  virtual void write_size(size_t count) = 0;
178 
179  /**
180  * Erase bytes from memory.
181  * @param[in] address the virtual address (starting from 0) from which to start erasing.
182  * @param[in] size the number of bytes to erase.
183  * This method should complete asynchronously by calling has_erased_bytes().
184  */
185  virtual void erase_bytes(uint32_t address, size_t size) = 0;
186 
187 protected:
188  Delegate *delegate();
189  events::EventQueue *event_queue();
190 
191 private:
192  Delegate *_delegate;
193  events::EventQueue *_event_queue;
194 };
195 
196 /**
197  * @}
198  */
199 
200 } // namespace nfc
201 } // namespace mbed
202 
203 #endif
NFCEEPROMDriver()
Construct a NFCEEPROM driver instance.
virtual void write_bytes(uint32_t address, const uint8_t *bytes, size_t count)=0
Write bytes to memory.
virtual void on_session_ended(bool success)=0
Completion of session end operation.
virtual void on_session_started(bool success)=0
Completion of session start operation.
virtual void on_size_written(bool success)=0
Completion of size setting operation.
virtual void read_size()=0
Retrieve the size of the addressable memory.
EventQueue.
Definition: EventQueue.h:60
The abstraction for a NFC EEPROM driver.
virtual void end_session()=0
End a session.
virtual void reset()=0
Reset and initialize the EEPROM.
virtual void read_bytes(uint32_t address, uint8_t *bytes, size_t count)=0
Read bytes from memory.
virtual void write_size(size_t count)=0
Set the size of the addressable memory.
virtual size_t read_max_size()=0
Get the maximum memory size addressable by the EEPROM.
void set_event_queue(events::EventQueue *queue)
Set the event queue that will be used to schedule event handling.
void set_delegate(Delegate *delegate)
Set the delegate that will receive events generated by this EEPROM.
virtual void start_session(bool force=true)=0
Start a session of operations (reads, writes, erases, size gets/sets).
virtual void erase_bytes(uint32_t address, size_t size)=0
Erase bytes from memory.
virtual void on_bytes_written(size_t count)=0
Completion of write operation.
virtual ~NFCEEPROMDriver()
NFCEEPROM driver destructor.
virtual void on_bytes_erased(size_t count)=0
Completion of erasing operation.
virtual void on_bytes_read(size_t count)=0
Completion of read operation.
The NFCEEPROMDriver delegate.
virtual void on_size_read(bool success, size_t size)=0
Completion of size retrieval operation.
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.