23
23
24
24
namespace mbed {
25
25
26
- OSPI *OSPI::_owner = NULL ;
27
26
SingletonPtr<PlatformMutex> OSPI::_mutex;
28
27
29
28
uint8_t convert_bus_width_to_line_count (ospi_bus_width_t width)
@@ -144,14 +143,8 @@ ospi_status_t OSPI::set_frequency(int hz)
144
143
if (_initialized) {
145
144
lock ();
146
145
_hz = hz;
147
- // If the same owner, just change freq.
148
- // Otherwise we may have to change mode as well, so call _acquire
149
- if (_owner == this ) {
150
- if (OSPI_STATUS_OK != ospi_frequency (&_ospi, _hz)) {
151
- ret_status = OSPI_STATUS_ERROR;
152
- }
153
- } else {
154
- _acquire ();
146
+ if (OSPI_STATUS_OK != ospi_frequency (&_ospi, _hz)) {
147
+ ret_status = OSPI_STATUS_ERROR;
155
148
}
156
149
unlock ();
157
150
} else {
@@ -169,11 +162,9 @@ ospi_status_t OSPI::read(int address, char *rx_buffer, size_t *rx_length)
169
162
if ((rx_length != NULL ) && (rx_buffer != NULL )) {
170
163
if (*rx_length != 0 ) {
171
164
lock ();
172
- if (true == _acquire ()) {
173
- _build_ospi_command (OSPI_NO_INST, address, -1 );
174
- if (OSPI_STATUS_OK == ospi_read (&_ospi, &_ospi_command, rx_buffer, rx_length)) {
175
- ret_status = OSPI_STATUS_OK;
176
- }
165
+ _build_ospi_command (OSPI_NO_INST, address, -1 );
166
+ if (OSPI_STATUS_OK == ospi_read (&_ospi, &_ospi_command, rx_buffer, rx_length)) {
167
+ ret_status = OSPI_STATUS_OK;
177
168
}
178
169
unlock ();
179
170
}
@@ -193,11 +184,9 @@ ospi_status_t OSPI::write(int address, const char *tx_buffer, size_t *tx_length)
193
184
if ((tx_length != NULL ) && (tx_buffer != NULL )) {
194
185
if (*tx_length != 0 ) {
195
186
lock ();
196
- if (true == _acquire ()) {
197
- _build_ospi_command (OSPI_NO_INST, address, -1 );
198
- if (OSPI_STATUS_OK == ospi_write (&_ospi, &_ospi_command, tx_buffer, tx_length)) {
199
- ret_status = OSPI_STATUS_OK;
200
- }
187
+ _build_ospi_command (OSPI_NO_INST, address, -1 );
188
+ if (OSPI_STATUS_OK == ospi_write (&_ospi, &_ospi_command, tx_buffer, tx_length)) {
189
+ ret_status = OSPI_STATUS_OK;
201
190
}
202
191
unlock ();
203
192
}
@@ -217,11 +206,9 @@ ospi_status_t OSPI::read(ospi_inst_t instruction, int alt, int address, char *rx
217
206
if ((rx_length != NULL ) && (rx_buffer != NULL )) {
218
207
if (*rx_length != 0 ) {
219
208
lock ();
220
- if (true == _acquire ()) {
221
- _build_ospi_command (instruction, address, alt);
222
- if (OSPI_STATUS_OK == ospi_read (&_ospi, &_ospi_command, rx_buffer, rx_length)) {
223
- ret_status = OSPI_STATUS_OK;
224
- }
209
+ _build_ospi_command (instruction, address, alt);
210
+ if (OSPI_STATUS_OK == ospi_read (&_ospi, &_ospi_command, rx_buffer, rx_length)) {
211
+ ret_status = OSPI_STATUS_OK;
225
212
}
226
213
unlock ();
227
214
}
@@ -241,11 +228,9 @@ ospi_status_t OSPI::write(ospi_inst_t instruction, int alt, int address, const c
241
228
if ((tx_length != NULL ) && (tx_buffer != NULL )) {
242
229
if (*tx_length != 0 ) {
243
230
lock ();
244
- if (true == _acquire ()) {
245
- _build_ospi_command (instruction, address, alt);
246
- if (OSPI_STATUS_OK == ospi_write (&_ospi, &_ospi_command, tx_buffer, tx_length)) {
247
- ret_status = OSPI_STATUS_OK;
248
- }
231
+ _build_ospi_command (instruction, address, alt);
232
+ if (OSPI_STATUS_OK == ospi_write (&_ospi, &_ospi_command, tx_buffer, tx_length)) {
233
+ ret_status = OSPI_STATUS_OK;
249
234
}
250
235
unlock ();
251
236
}
@@ -263,11 +248,9 @@ ospi_status_t OSPI::command_transfer(ospi_inst_t instruction, int address, const
263
248
264
249
if (_initialized) {
265
250
lock ();
266
- if (true == _acquire ()) {
267
- _build_ospi_command (instruction, address, -1 ); // We just need the command
268
- if (OSPI_STATUS_OK == ospi_command_transfer (&_ospi, &_ospi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
269
- ret_status = OSPI_STATUS_OK;
270
- }
251
+ _build_ospi_command (instruction, address, -1 ); // We just need the command
252
+ if (OSPI_STATUS_OK == ospi_command_transfer (&_ospi, &_ospi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
253
+ ret_status = OSPI_STATUS_OK;
271
254
}
272
255
unlock ();
273
256
}
@@ -296,7 +279,6 @@ bool OSPI::_initialize()
296
279
ospi_status_t ret = ospi_init (&_ospi, _ospi_io0, _ospi_io1, _ospi_io2, _ospi_io3, _ospi_io4, _ospi_io5, _ospi_io6, _ospi_io7, _ospi_clk, _ospi_cs, _ospi_dqs, _hz, _mode);
297
280
if (OSPI_STATUS_OK == ret) {
298
281
_initialized = true ;
299
- _owner = this ;
300
282
} else {
301
283
_initialized = false ;
302
284
}
@@ -315,26 +297,13 @@ bool OSPI::_initialize_direct()
315
297
ospi_status_t ret = ospi_init_direct (&_ospi, _static_pinmap, _hz, _mode);
316
298
if (OSPI_STATUS_OK == ret) {
317
299
_initialized = true ;
318
- _owner = this ;
319
300
} else {
320
301
_initialized = false ;
321
302
}
322
303
323
304
return _initialized;
324
305
}
325
306
326
- // Note: Private function with no locking
327
- bool OSPI::_acquire ()
328
- {
329
- if (_owner != this ) {
330
- // This will set freq as well
331
- (this ->*_init_func)();
332
- _owner = this ;
333
- }
334
-
335
- return _initialized;
336
- }
337
-
338
307
void OSPI::_build_ospi_command (ospi_inst_t instruction, int address, int alt)
339
308
{
340
309
memset (&_ospi_command, 0 , sizeof (ospi_command_t ));
0 commit comments