Skip to content

Commit 0b4fdb5

Browse files
committed
Remove ownership in OSPI driver
1 parent a28a868 commit 0b4fdb5

File tree

2 files changed

+17
-54
lines changed

2 files changed

+17
-54
lines changed

drivers/include/drivers/OSPI.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ class OSPI : private NonCopyable<OSPI> {
229229

230230
ospi_t _ospi;
231231

232-
bool acquire(void);
233-
static OSPI *_owner;
234232
static SingletonPtr<PlatformMutex> _mutex;
235233
ospi_bus_width_t _inst_width; //Bus width for Instruction phase
236234
ospi_inst_size_t _inst_size; //Instruction Size
@@ -249,10 +247,6 @@ class OSPI : private NonCopyable<OSPI> {
249247
bool (OSPI::* _init_func)(void);
250248

251249
private:
252-
/* Private acquire function without locking/unlocking
253-
* Implemented in order to avoid duplicate locking and boost performance
254-
*/
255-
bool _acquire(void);
256250
bool _initialize();
257251
bool _initialize_direct();
258252

drivers/source/OSPI.cpp

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
namespace mbed {
2525

26-
OSPI *OSPI::_owner = NULL;
2726
SingletonPtr<PlatformMutex> OSPI::_mutex;
2827

2928
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)
144143
if (_initialized) {
145144
lock();
146145
_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;
155148
}
156149
unlock();
157150
} else {
@@ -169,11 +162,9 @@ ospi_status_t OSPI::read(int address, char *rx_buffer, size_t *rx_length)
169162
if ((rx_length != NULL) && (rx_buffer != NULL)) {
170163
if (*rx_length != 0) {
171164
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;
177168
}
178169
unlock();
179170
}
@@ -193,11 +184,9 @@ ospi_status_t OSPI::write(int address, const char *tx_buffer, size_t *tx_length)
193184
if ((tx_length != NULL) && (tx_buffer != NULL)) {
194185
if (*tx_length != 0) {
195186
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;
201190
}
202191
unlock();
203192
}
@@ -217,11 +206,9 @@ ospi_status_t OSPI::read(ospi_inst_t instruction, int alt, int address, char *rx
217206
if ((rx_length != NULL) && (rx_buffer != NULL)) {
218207
if (*rx_length != 0) {
219208
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;
225212
}
226213
unlock();
227214
}
@@ -241,11 +228,9 @@ ospi_status_t OSPI::write(ospi_inst_t instruction, int alt, int address, const c
241228
if ((tx_length != NULL) && (tx_buffer != NULL)) {
242229
if (*tx_length != 0) {
243230
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;
249234
}
250235
unlock();
251236
}
@@ -263,11 +248,9 @@ ospi_status_t OSPI::command_transfer(ospi_inst_t instruction, int address, const
263248

264249
if (_initialized) {
265250
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;
271254
}
272255
unlock();
273256
}
@@ -296,7 +279,6 @@ bool OSPI::_initialize()
296279
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);
297280
if (OSPI_STATUS_OK == ret) {
298281
_initialized = true;
299-
_owner = this;
300282
} else {
301283
_initialized = false;
302284
}
@@ -315,26 +297,13 @@ bool OSPI::_initialize_direct()
315297
ospi_status_t ret = ospi_init_direct(&_ospi, _static_pinmap, _hz, _mode);
316298
if (OSPI_STATUS_OK == ret) {
317299
_initialized = true;
318-
_owner = this;
319300
} else {
320301
_initialized = false;
321302
}
322303

323304
return _initialized;
324305
}
325306

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-
338307
void OSPI::_build_ospi_command(ospi_inst_t instruction, int address, int alt)
339308
{
340309
memset(&_ospi_command, 0, sizeof(ospi_command_t));

0 commit comments

Comments
 (0)