23
23
24
24
namespace mbed {
25
25
26
- QSPI *QSPI::_owner = NULL ;
27
26
SingletonPtr<PlatformMutex> QSPI::_mutex;
28
27
29
28
uint8_t convert_bus_width_to_line_count (qspi_bus_width_t width)
@@ -124,14 +123,8 @@ qspi_status_t QSPI::set_frequency(int hz)
124
123
if (_initialized) {
125
124
lock ();
126
125
_hz = hz;
127
- // If the same owner, just change freq.
128
- // Otherwise we may have to change mode as well, so call _acquire
129
- if (_owner == this ) {
130
- if (QSPI_STATUS_OK != qspi_frequency (&_qspi, _hz)) {
131
- ret_status = QSPI_STATUS_ERROR;
132
- }
133
- } else {
134
- _acquire ();
126
+ if (QSPI_STATUS_OK != qspi_frequency (&_qspi, _hz)) {
127
+ ret_status = QSPI_STATUS_ERROR;
135
128
}
136
129
unlock ();
137
130
} else {
@@ -149,11 +142,9 @@ qspi_status_t QSPI::read(int address, char *rx_buffer, size_t *rx_length)
149
142
if ((rx_length != NULL ) && (rx_buffer != NULL )) {
150
143
if (*rx_length != 0 ) {
151
144
lock ();
152
- if (true == _acquire ()) {
153
- _build_qspi_command (QSPI_NO_INST, address, -1 );
154
- if (QSPI_STATUS_OK == qspi_read (&_qspi, &_qspi_command, rx_buffer, rx_length)) {
155
- ret_status = QSPI_STATUS_OK;
156
- }
145
+ _build_qspi_command (QSPI_NO_INST, address, -1 );
146
+ if (QSPI_STATUS_OK == qspi_read (&_qspi, &_qspi_command, rx_buffer, rx_length)) {
147
+ ret_status = QSPI_STATUS_OK;
157
148
}
158
149
unlock ();
159
150
}
@@ -173,11 +164,9 @@ qspi_status_t QSPI::write(int address, const char *tx_buffer, size_t *tx_length)
173
164
if ((tx_length != NULL ) && (tx_buffer != NULL )) {
174
165
if (*tx_length != 0 ) {
175
166
lock ();
176
- if (true == _acquire ()) {
177
- _build_qspi_command (QSPI_NO_INST, address, -1 );
178
- if (QSPI_STATUS_OK == qspi_write (&_qspi, &_qspi_command, tx_buffer, tx_length)) {
179
- ret_status = QSPI_STATUS_OK;
180
- }
167
+ _build_qspi_command (QSPI_NO_INST, address, -1 );
168
+ if (QSPI_STATUS_OK == qspi_write (&_qspi, &_qspi_command, tx_buffer, tx_length)) {
169
+ ret_status = QSPI_STATUS_OK;
181
170
}
182
171
unlock ();
183
172
}
@@ -197,11 +186,9 @@ qspi_status_t QSPI::read(qspi_inst_t instruction, int alt, int address, char *rx
197
186
if ((rx_length != NULL ) && (rx_buffer != NULL )) {
198
187
if (*rx_length != 0 ) {
199
188
lock ();
200
- if (true == _acquire ()) {
201
- _build_qspi_command (instruction, address, alt);
202
- if (QSPI_STATUS_OK == qspi_read (&_qspi, &_qspi_command, rx_buffer, rx_length)) {
203
- ret_status = QSPI_STATUS_OK;
204
- }
189
+ _build_qspi_command (instruction, address, alt);
190
+ if (QSPI_STATUS_OK == qspi_read (&_qspi, &_qspi_command, rx_buffer, rx_length)) {
191
+ ret_status = QSPI_STATUS_OK;
205
192
}
206
193
unlock ();
207
194
}
@@ -221,11 +208,9 @@ qspi_status_t QSPI::write(qspi_inst_t instruction, int alt, int address, const c
221
208
if ((tx_length != NULL ) && (tx_buffer != NULL )) {
222
209
if (*tx_length != 0 ) {
223
210
lock ();
224
- if (true == _acquire ()) {
225
- _build_qspi_command (instruction, address, alt);
226
- if (QSPI_STATUS_OK == qspi_write (&_qspi, &_qspi_command, tx_buffer, tx_length)) {
227
- ret_status = QSPI_STATUS_OK;
228
- }
211
+ _build_qspi_command (instruction, address, alt);
212
+ if (QSPI_STATUS_OK == qspi_write (&_qspi, &_qspi_command, tx_buffer, tx_length)) {
213
+ ret_status = QSPI_STATUS_OK;
229
214
}
230
215
unlock ();
231
216
}
@@ -243,11 +228,9 @@ qspi_status_t QSPI::command_transfer(qspi_inst_t instruction, int address, const
243
228
244
229
if (_initialized) {
245
230
lock ();
246
- if (true == _acquire ()) {
247
- _build_qspi_command (instruction, address, -1 ); // We just need the command
248
- if (QSPI_STATUS_OK == qspi_command_transfer (&_qspi, &_qspi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
249
- ret_status = QSPI_STATUS_OK;
250
- }
231
+ _build_qspi_command (instruction, address, -1 ); // We just need the command
232
+ if (QSPI_STATUS_OK == qspi_command_transfer (&_qspi, &_qspi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
233
+ ret_status = QSPI_STATUS_OK;
251
234
}
252
235
unlock ();
253
236
}
@@ -276,7 +259,6 @@ bool QSPI::_initialize()
276
259
qspi_status_t ret = qspi_init (&_qspi, _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs, _hz, _mode);
277
260
if (QSPI_STATUS_OK == ret) {
278
261
_initialized = true ;
279
- _owner = this ;
280
262
} else {
281
263
_initialized = false ;
282
264
}
@@ -295,26 +277,13 @@ bool QSPI::_initialize_direct()
295
277
qspi_status_t ret = qspi_init_direct (&_qspi, _static_pinmap, _hz, _mode);
296
278
if (QSPI_STATUS_OK == ret) {
297
279
_initialized = true ;
298
- _owner = this ;
299
280
} else {
300
281
_initialized = false ;
301
282
}
302
283
303
284
return _initialized;
304
285
}
305
286
306
- // Note: Private function with no locking
307
- bool QSPI::_acquire ()
308
- {
309
- if (_owner != this ) {
310
- // This will set freq as well
311
- (this ->*_init_func)();
312
- _owner = this ;
313
- }
314
-
315
- return _initialized;
316
- }
317
-
318
287
void QSPI::_build_qspi_command (qspi_inst_t instruction, int address, int alt)
319
288
{
320
289
memset (&_qspi_command, 0 , sizeof (qspi_command_t ));
0 commit comments