Skip to content

Commit a28a868

Browse files
committed
Remove ownership in QSPI driver
1 parent c734138 commit a28a868

File tree

2 files changed

+17
-54
lines changed

2 files changed

+17
-54
lines changed

drivers/include/drivers/QSPI.h

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

224224
qspi_t _qspi;
225225

226-
bool acquire(void);
227-
static QSPI *_owner;
228226
static SingletonPtr<PlatformMutex> _mutex;
229227
qspi_bus_width_t _inst_width; //Bus width for Instruction phase
230228
qspi_bus_width_t _address_width; //Bus width for Address phase
@@ -242,10 +240,6 @@ class QSPI : private NonCopyable<QSPI> {
242240
bool (QSPI::* _init_func)(void);
243241

244242
private:
245-
/* Private acquire function without locking/unlocking
246-
* Implemented in order to avoid duplicate locking and boost performance
247-
*/
248-
bool _acquire(void);
249243
bool _initialize();
250244
bool _initialize_direct();
251245

drivers/source/QSPI.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-
QSPI *QSPI::_owner = NULL;
2726
SingletonPtr<PlatformMutex> QSPI::_mutex;
2827

2928
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)
124123
if (_initialized) {
125124
lock();
126125
_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;
135128
}
136129
unlock();
137130
} else {
@@ -149,11 +142,9 @@ qspi_status_t QSPI::read(int address, char *rx_buffer, size_t *rx_length)
149142
if ((rx_length != NULL) && (rx_buffer != NULL)) {
150143
if (*rx_length != 0) {
151144
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;
157148
}
158149
unlock();
159150
}
@@ -173,11 +164,9 @@ qspi_status_t QSPI::write(int address, const char *tx_buffer, size_t *tx_length)
173164
if ((tx_length != NULL) && (tx_buffer != NULL)) {
174165
if (*tx_length != 0) {
175166
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;
181170
}
182171
unlock();
183172
}
@@ -197,11 +186,9 @@ qspi_status_t QSPI::read(qspi_inst_t instruction, int alt, int address, char *rx
197186
if ((rx_length != NULL) && (rx_buffer != NULL)) {
198187
if (*rx_length != 0) {
199188
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;
205192
}
206193
unlock();
207194
}
@@ -221,11 +208,9 @@ qspi_status_t QSPI::write(qspi_inst_t instruction, int alt, int address, const c
221208
if ((tx_length != NULL) && (tx_buffer != NULL)) {
222209
if (*tx_length != 0) {
223210
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;
229214
}
230215
unlock();
231216
}
@@ -243,11 +228,9 @@ qspi_status_t QSPI::command_transfer(qspi_inst_t instruction, int address, const
243228

244229
if (_initialized) {
245230
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;
251234
}
252235
unlock();
253236
}
@@ -276,7 +259,6 @@ bool QSPI::_initialize()
276259
qspi_status_t ret = qspi_init(&_qspi, _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs, _hz, _mode);
277260
if (QSPI_STATUS_OK == ret) {
278261
_initialized = true;
279-
_owner = this;
280262
} else {
281263
_initialized = false;
282264
}
@@ -295,26 +277,13 @@ bool QSPI::_initialize_direct()
295277
qspi_status_t ret = qspi_init_direct(&_qspi, _static_pinmap, _hz, _mode);
296278
if (QSPI_STATUS_OK == ret) {
297279
_initialized = true;
298-
_owner = this;
299280
} else {
300281
_initialized = false;
301282
}
302283

303284
return _initialized;
304285
}
305286

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-
318287
void QSPI::_build_qspi_command(qspi_inst_t instruction, int address, int alt)
319288
{
320289
memset(&_qspi_command, 0, sizeof(qspi_command_t));

0 commit comments

Comments
 (0)