Remove ownership in QSPI driver

pull/14437/head
George Psimenos 2021-03-17 13:26:25 +00:00
parent c73413893f
commit a28a8684c9
2 changed files with 17 additions and 54 deletions

View File

@ -223,8 +223,6 @@ protected:
qspi_t _qspi;
bool acquire(void);
static QSPI *_owner;
static SingletonPtr<PlatformMutex> _mutex;
qspi_bus_width_t _inst_width; //Bus width for Instruction phase
qspi_bus_width_t _address_width; //Bus width for Address phase
@ -242,10 +240,6 @@ protected:
bool (QSPI::* _init_func)(void);
private:
/* Private acquire function without locking/unlocking
* Implemented in order to avoid duplicate locking and boost performance
*/
bool _acquire(void);
bool _initialize();
bool _initialize_direct();

View File

@ -23,7 +23,6 @@
namespace mbed {
QSPI *QSPI::_owner = NULL;
SingletonPtr<PlatformMutex> QSPI::_mutex;
uint8_t convert_bus_width_to_line_count(qspi_bus_width_t width)
@ -124,15 +123,9 @@ qspi_status_t QSPI::set_frequency(int hz)
if (_initialized) {
lock();
_hz = hz;
//If the same owner, just change freq.
//Otherwise we may have to change mode as well, so call _acquire
if (_owner == this) {
if (QSPI_STATUS_OK != qspi_frequency(&_qspi, _hz)) {
ret_status = QSPI_STATUS_ERROR;
}
} else {
_acquire();
}
unlock();
} else {
ret_status = QSPI_STATUS_ERROR;
@ -149,12 +142,10 @@ qspi_status_t QSPI::read(int address, char *rx_buffer, size_t *rx_length)
if ((rx_length != NULL) && (rx_buffer != NULL)) {
if (*rx_length != 0) {
lock();
if (true == _acquire()) {
_build_qspi_command(QSPI_NO_INST, address, -1);
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
@ -173,12 +164,10 @@ qspi_status_t QSPI::write(int address, const char *tx_buffer, size_t *tx_length)
if ((tx_length != NULL) && (tx_buffer != NULL)) {
if (*tx_length != 0) {
lock();
if (true == _acquire()) {
_build_qspi_command(QSPI_NO_INST, address, -1);
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
@ -197,12 +186,10 @@ qspi_status_t QSPI::read(qspi_inst_t instruction, int alt, int address, char *rx
if ((rx_length != NULL) && (rx_buffer != NULL)) {
if (*rx_length != 0) {
lock();
if (true == _acquire()) {
_build_qspi_command(instruction, address, alt);
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
@ -221,12 +208,10 @@ qspi_status_t QSPI::write(qspi_inst_t instruction, int alt, int address, const c
if ((tx_length != NULL) && (tx_buffer != NULL)) {
if (*tx_length != 0) {
lock();
if (true == _acquire()) {
_build_qspi_command(instruction, address, alt);
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
@ -243,12 +228,10 @@ qspi_status_t QSPI::command_transfer(qspi_inst_t instruction, int address, const
if (_initialized) {
lock();
if (true == _acquire()) {
_build_qspi_command(instruction, address, -1); //We just need the command
if (QSPI_STATUS_OK == qspi_command_transfer(&_qspi, &_qspi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
@ -276,7 +259,6 @@ bool QSPI::_initialize()
qspi_status_t ret = qspi_init(&_qspi, _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs, _hz, _mode);
if (QSPI_STATUS_OK == ret) {
_initialized = true;
_owner = this;
} else {
_initialized = false;
}
@ -295,7 +277,6 @@ bool QSPI::_initialize_direct()
qspi_status_t ret = qspi_init_direct(&_qspi, _static_pinmap, _hz, _mode);
if (QSPI_STATUS_OK == ret) {
_initialized = true;
_owner = this;
} else {
_initialized = false;
}
@ -303,18 +284,6 @@ bool QSPI::_initialize_direct()
return _initialized;
}
// Note: Private function with no locking
bool QSPI::_acquire()
{
if (_owner != this) {
//This will set freq as well
(this->*_init_func)();
_owner = this;
}
return _initialized;
}
void QSPI::_build_qspi_command(qspi_inst_t instruction, int address, int alt)
{
memset(&_qspi_command, 0, sizeof(qspi_command_t));