21
21
namespace mbed {
22
22
23
23
ExhaustibleBlockDevice::ExhaustibleBlockDevice (BlockDevice *bd, uint32_t erase_cycles)
24
- : _bd(bd), _erase_array(NULL ), _programmable_array(NULL ), _erase_cycles(erase_cycles),
25
- _init_ref_count (0 ), _is_initialized(false )
24
+ : _bd(bd), _erase_array(NULL ), _erase_cycles(erase_cycles), _init_ref_count(0 ), _is_initialized(false )
26
25
{
27
26
}
28
27
29
28
ExhaustibleBlockDevice::~ExhaustibleBlockDevice ()
30
29
{
31
30
delete[] _erase_array;
32
- delete[] _programmable_array;
33
- }
34
-
35
- uint32_t ExhaustibleBlockDevice::get_erase_cycles (bd_addr_t addr) const
36
- {
37
- if (!_is_initialized) {
38
- return 0 ;
39
- }
40
- return _erase_array[addr / get_erase_size ()];
41
- }
42
-
43
- void ExhaustibleBlockDevice::set_erase_cycles (bd_addr_t addr, uint32_t cycles)
44
- {
45
- if (!_is_initialized) {
46
- return ;
47
- }
48
- _erase_array[addr / get_erase_size ()] = cycles;
49
31
}
50
32
51
33
int ExhaustibleBlockDevice::init ()
@@ -70,13 +52,6 @@ int ExhaustibleBlockDevice::init()
70
52
}
71
53
}
72
54
73
- if (!_programmable_array) {
74
- _programmable_array = new bool [_bd->size () / _bd->get_erase_size ()];
75
- for (size_t i = 0 ; i < _bd->size () / _bd->get_erase_size (); i++) {
76
- _programmable_array[i] = true ;
77
- }
78
- }
79
-
80
55
_is_initialized = true ;
81
56
return BD_ERROR_OK;
82
57
@@ -133,20 +108,10 @@ int ExhaustibleBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_
133
108
}
134
109
135
110
if (_erase_array[addr / get_erase_size ()] == 0 ) {
136
- return BD_ERROR_DEVICE_ERROR;
137
- }
138
-
139
- if (!_programmable_array[addr / get_erase_size ()]) {
140
- return BD_ERROR_DEVICE_ERROR;
141
- }
142
-
143
- int ret = _bd->program (buffer, addr, size);
144
-
145
- if (ret == BD_ERROR_OK) {
146
- _programmable_array[addr / get_erase_size ()] = false ;
111
+ return 0 ;
147
112
}
148
113
149
- return ret ;
114
+ return _bd-> program (buffer, addr, size) ;
150
115
}
151
116
152
117
int ExhaustibleBlockDevice::erase (bd_addr_t addr, bd_size_t size)
@@ -164,13 +129,13 @@ int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size)
164
129
// use an erase cycle
165
130
if (_erase_array[addr / eu_size] > 0 ) {
166
131
_erase_array[addr / eu_size] -= 1 ;
132
+ }
133
+
134
+ if (_erase_array[addr / eu_size] > 0 ) {
167
135
int err = _bd->erase (addr, eu_size);
168
136
if (err) {
169
137
return err;
170
138
}
171
- _programmable_array[addr / get_erase_size ()] = true ;
172
- } else {
173
- return BD_ERROR_DEVICE_ERROR;
174
139
}
175
140
176
141
addr += eu_size;
0 commit comments