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