CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_FlashIface/AP_FlashIface_Abstract.h
Views: 1798
1
/*
2
* This file is free software: you can redistribute it and/or modify it
3
* under the terms of the GNU General Public License as published by the
4
* Free Software Foundation, either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* This file is distributed in the hope that it will be useful, but
8
* WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
* See the GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License along
13
* with this program. If not, see <http://www.gnu.org/licenses/>.
14
*
15
* Code by
16
* Andy Piper
17
* Siddharth Bharat Purohit, Cubepilot Pty. Ltd.
18
*/
19
/*
20
Implements Common frontend methods for Flash Interface Driver
21
*/
22
#pragma once
23
24
#include <AP_HAL/AP_HAL.h>
25
26
class AP_FlashIface
27
{
28
29
public:
30
virtual bool init() = 0;
31
32
/**
33
* @details Read data from flash chip.
34
*
35
* @param[in] offset address offset from where to start the read
36
* @param[out] data data to be read from the device
37
* @param[in] size size of the data to be read
38
* @return The operation status.
39
* @retval false if the operation failed.
40
* @retval true if the operation succeeded.
41
*
42
*/
43
virtual bool read(uint32_t offset, uint8_t* data, uint32_t size) = 0;
44
45
/**
46
* @details Gets number bytes that can be written in one go (page size).
47
*
48
* @return page size in bytes.
49
*
50
*/
51
virtual uint32_t get_page_size() const = 0;
52
53
/**
54
* @details Gets number pages, each page can written in one go
55
*
56
* @return Number of pages.
57
*
58
*/
59
virtual uint32_t get_page_count() const = 0;
60
61
/**
62
* @details Sends command to start programming a page of the chip.
63
*
64
* @param[in] page Page number to be written to
65
* @param[in] data data to be written
66
* @param[out] delay_us Time to wait until next is_device_busy call
67
* @param[out] timeout_us Time after which the erase should be timedout,
68
* should be reset at every call.
69
* @return The operation status.
70
* @retval false if the operation failed.
71
* @retval true if the operation succeeded.
72
*
73
*/
74
virtual bool start_program_page(uint32_t page, const uint8_t *data, uint32_t &delay_us, uint32_t &timeout_us) = 0;
75
76
/**
77
* @details Tries to program as much as possible starting from the offset
78
* until size. User needs to call this as many times as needed
79
* taking already programmed bytes into account.
80
*
81
* @param[in] offset address offset for program
82
* @param[in] data data to be programmed
83
* @param[in] size size desired to be programmed
84
* @param[out] programming number of bytes programming, taking care of the limits
85
* @param[out] delay_us Time to wait until program typically finishes
86
* @param[out] timeout_us Time by which current program should have timedout.
87
* @return The operation status.
88
* @retval false if the operation failed.
89
* @retval true if the operation succeeded.
90
*
91
*/
92
virtual bool start_program_offset(uint32_t offset, const uint8_t* data, uint32_t size, uint32_t &programming,
93
uint32_t &delay_us, uint32_t &timeout_us)
94
{
95
return false;
96
}
97
98
/**
99
* @details Gets number bytes that can erased in one go(sector size)
100
*
101
* @return Sector size in bytes.
102
*
103
*/
104
virtual uint32_t get_sector_size() const = 0;
105
106
107
/**
108
* @details Gets number of sectors, each sector can be erased in one go
109
*
110
* @return Number of sectors.
111
*
112
*/
113
virtual uint32_t get_sector_count() const = 0;
114
115
/**
116
* @details Sends command to erase the entire chips.
117
*
118
* @param[out] delay_ms Time to wait until next is_device_busy call
119
* @param[out] timeout_ms Time by which the erase should have timedout
120
*
121
* @return The operation status.
122
* @retval false if the operation failed.
123
* @retval true if the operation succeeded.
124
*
125
*/
126
virtual bool start_mass_erase(uint32_t &delay_ms, uint32_t &timeout_ms) = 0;
127
128
/**
129
* @details Sends command to erase a sector of the chip.
130
*
131
* @param[in] sector Sector number to be erased
132
* @param[out] delay_ms Time to wait until next is_device_busy call
133
* @param[out] timeout_ms Time by which the erase should have timedout
134
*
135
* @return The operation status.
136
* @retval false if the operation failed.
137
* @retval true if the operation succeeded.
138
*
139
*/
140
virtual bool start_sector_erase(uint32_t sector, uint32_t &delay_ms, uint32_t &timeout_ms) = 0;
141
142
/**
143
* @details Tries to erase as much as possible starting from the offset
144
* until size. User needs to call this as many times as needed
145
* taking already erased bytes into account, until desired erase
146
* has taken place
147
*
148
* @param[in] offset address offset for erase
149
* @param[in] size size desired to be erased
150
* @param[out] erasing number of bytes erasing
151
* @param[out] delay_ms Time to wait until next is_device_busy call
152
* @param[out] timeout_ms Time by which the erase should have timedout
153
*
154
* @return The operation status.
155
* @retval false if the operation failed.
156
* @retval true if the operation succeeded.
157
*
158
*/
159
virtual bool start_erase_offset(uint32_t offset, uint32_t size, uint32_t &erasing,
160
uint32_t &delay_ms, uint32_t &timeout_ms)
161
{
162
return false;
163
}
164
165
/**
166
* @details Check if the device is busy.
167
*
168
* @return device busy with last op.
169
*
170
* @retval false if the device is ready.
171
* @retval true if the device is busy.
172
*
173
*/
174
virtual bool is_device_busy() = 0;
175
176
177
/**
178
* @details Check if selected sector is erased.
179
*
180
* @param[in] sector sector for which to check erase
181
* @return The operation status.
182
* @retval false if the operation failed.
183
* @retval true if the operation succeeded.
184
*
185
*/
186
virtual bool verify_sector_erase(uint32_t sector) = 0;
187
188
/**
189
* @details minimum number of bytes that can be erased
190
*
191
* @return Number of bytes.
192
*
193
*/
194
virtual uint32_t min_erase_size() const = 0;
195
196
/**
197
* @details Starts execution in place mode
198
*
199
* @return if successfully entered XIP mode.
200
*
201
* @retval false the device failed to enter XIP mode.
202
* @retval true the device has entered XIP mode.
203
*
204
*/
205
virtual bool start_xip_mode(void** addr) { return false; }
206
207
virtual bool stop_xip_mode() { return false; }
208
};
209
210