mirror of https://github.com/ARMmbed/mbed-os.git
Remove ownership in QSPI driver
parent
c73413893f
commit
a28a8684c9
|
@ -223,8 +223,6 @@ protected:
|
||||||
|
|
||||||
qspi_t _qspi;
|
qspi_t _qspi;
|
||||||
|
|
||||||
bool acquire(void);
|
|
||||||
static QSPI *_owner;
|
|
||||||
static SingletonPtr<PlatformMutex> _mutex;
|
static SingletonPtr<PlatformMutex> _mutex;
|
||||||
qspi_bus_width_t _inst_width; //Bus width for Instruction phase
|
qspi_bus_width_t _inst_width; //Bus width for Instruction phase
|
||||||
qspi_bus_width_t _address_width; //Bus width for Address phase
|
qspi_bus_width_t _address_width; //Bus width for Address phase
|
||||||
|
@ -242,10 +240,6 @@ protected:
|
||||||
bool (QSPI::* _init_func)(void);
|
bool (QSPI::* _init_func)(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Private acquire function without locking/unlocking
|
|
||||||
* Implemented in order to avoid duplicate locking and boost performance
|
|
||||||
*/
|
|
||||||
bool _acquire(void);
|
|
||||||
bool _initialize();
|
bool _initialize();
|
||||||
bool _initialize_direct();
|
bool _initialize_direct();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
QSPI *QSPI::_owner = NULL;
|
|
||||||
SingletonPtr<PlatformMutex> QSPI::_mutex;
|
SingletonPtr<PlatformMutex> QSPI::_mutex;
|
||||||
|
|
||||||
uint8_t convert_bus_width_to_line_count(qspi_bus_width_t width)
|
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) {
|
if (_initialized) {
|
||||||
lock();
|
lock();
|
||||||
_hz = hz;
|
_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)) {
|
if (QSPI_STATUS_OK != qspi_frequency(&_qspi, _hz)) {
|
||||||
ret_status = QSPI_STATUS_ERROR;
|
ret_status = QSPI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
_acquire();
|
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
} else {
|
} else {
|
||||||
ret_status = QSPI_STATUS_ERROR;
|
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 != NULL) && (rx_buffer != NULL)) {
|
||||||
if (*rx_length != 0) {
|
if (*rx_length != 0) {
|
||||||
lock();
|
lock();
|
||||||
if (true == _acquire()) {
|
|
||||||
_build_qspi_command(QSPI_NO_INST, address, -1);
|
_build_qspi_command(QSPI_NO_INST, address, -1);
|
||||||
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
|
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
|
||||||
ret_status = QSPI_STATUS_OK;
|
ret_status = QSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} 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 != NULL) && (tx_buffer != NULL)) {
|
||||||
if (*tx_length != 0) {
|
if (*tx_length != 0) {
|
||||||
lock();
|
lock();
|
||||||
if (true == _acquire()) {
|
|
||||||
_build_qspi_command(QSPI_NO_INST, address, -1);
|
_build_qspi_command(QSPI_NO_INST, address, -1);
|
||||||
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
|
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
|
||||||
ret_status = QSPI_STATUS_OK;
|
ret_status = QSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} 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 != NULL) && (rx_buffer != NULL)) {
|
||||||
if (*rx_length != 0) {
|
if (*rx_length != 0) {
|
||||||
lock();
|
lock();
|
||||||
if (true == _acquire()) {
|
|
||||||
_build_qspi_command(instruction, address, alt);
|
_build_qspi_command(instruction, address, alt);
|
||||||
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
|
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
|
||||||
ret_status = QSPI_STATUS_OK;
|
ret_status = QSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} 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 != NULL) && (tx_buffer != NULL)) {
|
||||||
if (*tx_length != 0) {
|
if (*tx_length != 0) {
|
||||||
lock();
|
lock();
|
||||||
if (true == _acquire()) {
|
|
||||||
_build_qspi_command(instruction, address, alt);
|
_build_qspi_command(instruction, address, alt);
|
||||||
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
|
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
|
||||||
ret_status = QSPI_STATUS_OK;
|
ret_status = QSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -243,12 +228,10 @@ qspi_status_t QSPI::command_transfer(qspi_inst_t instruction, int address, const
|
||||||
|
|
||||||
if (_initialized) {
|
if (_initialized) {
|
||||||
lock();
|
lock();
|
||||||
if (true == _acquire()) {
|
|
||||||
_build_qspi_command(instruction, address, -1); //We just need the command
|
_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)) {
|
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;
|
ret_status = QSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
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);
|
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) {
|
if (QSPI_STATUS_OK == ret) {
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
_owner = this;
|
|
||||||
} else {
|
} else {
|
||||||
_initialized = false;
|
_initialized = false;
|
||||||
}
|
}
|
||||||
|
@ -295,7 +277,6 @@ bool QSPI::_initialize_direct()
|
||||||
qspi_status_t ret = qspi_init_direct(&_qspi, _static_pinmap, _hz, _mode);
|
qspi_status_t ret = qspi_init_direct(&_qspi, _static_pinmap, _hz, _mode);
|
||||||
if (QSPI_STATUS_OK == ret) {
|
if (QSPI_STATUS_OK == ret) {
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
_owner = this;
|
|
||||||
} else {
|
} else {
|
||||||
_initialized = false;
|
_initialized = false;
|
||||||
}
|
}
|
||||||
|
@ -303,18 +284,6 @@ bool QSPI::_initialize_direct()
|
||||||
return _initialized;
|
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)
|
void QSPI::_build_qspi_command(qspi_inst_t instruction, int address, int alt)
|
||||||
{
|
{
|
||||||
memset(&_qspi_command, 0, sizeof(qspi_command_t));
|
memset(&_qspi_command, 0, sizeof(qspi_command_t));
|
||||||
|
|
Loading…
Reference in New Issue