mirror of https://github.com/ARMmbed/mbed-os.git
Remove ownership in OSPI driver
parent
a28a8684c9
commit
0b4fdb5e70
|
@ -229,8 +229,6 @@ protected:
|
||||||
|
|
||||||
ospi_t _ospi;
|
ospi_t _ospi;
|
||||||
|
|
||||||
bool acquire(void);
|
|
||||||
static OSPI *_owner;
|
|
||||||
static SingletonPtr<PlatformMutex> _mutex;
|
static SingletonPtr<PlatformMutex> _mutex;
|
||||||
ospi_bus_width_t _inst_width; //Bus width for Instruction phase
|
ospi_bus_width_t _inst_width; //Bus width for Instruction phase
|
||||||
ospi_inst_size_t _inst_size; //Instruction Size
|
ospi_inst_size_t _inst_size; //Instruction Size
|
||||||
|
@ -249,10 +247,6 @@ protected:
|
||||||
bool (OSPI::* _init_func)(void);
|
bool (OSPI::* _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 {
|
||||||
|
|
||||||
OSPI *OSPI::_owner = NULL;
|
|
||||||
SingletonPtr<PlatformMutex> OSPI::_mutex;
|
SingletonPtr<PlatformMutex> OSPI::_mutex;
|
||||||
|
|
||||||
uint8_t convert_bus_width_to_line_count(ospi_bus_width_t width)
|
uint8_t convert_bus_width_to_line_count(ospi_bus_width_t width)
|
||||||
|
@ -144,15 +143,9 @@ ospi_status_t OSPI::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 (OSPI_STATUS_OK != ospi_frequency(&_ospi, _hz)) {
|
if (OSPI_STATUS_OK != ospi_frequency(&_ospi, _hz)) {
|
||||||
ret_status = OSPI_STATUS_ERROR;
|
ret_status = OSPI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
_acquire();
|
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
} else {
|
} else {
|
||||||
ret_status = OSPI_STATUS_ERROR;
|
ret_status = OSPI_STATUS_ERROR;
|
||||||
|
@ -169,12 +162,10 @@ ospi_status_t OSPI::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_ospi_command(OSPI_NO_INST, address, -1);
|
_build_ospi_command(OSPI_NO_INST, address, -1);
|
||||||
if (OSPI_STATUS_OK == ospi_read(&_ospi, &_ospi_command, rx_buffer, rx_length)) {
|
if (OSPI_STATUS_OK == ospi_read(&_ospi, &_ospi_command, rx_buffer, rx_length)) {
|
||||||
ret_status = OSPI_STATUS_OK;
|
ret_status = OSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -193,12 +184,10 @@ ospi_status_t OSPI::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_ospi_command(OSPI_NO_INST, address, -1);
|
_build_ospi_command(OSPI_NO_INST, address, -1);
|
||||||
if (OSPI_STATUS_OK == ospi_write(&_ospi, &_ospi_command, tx_buffer, tx_length)) {
|
if (OSPI_STATUS_OK == ospi_write(&_ospi, &_ospi_command, tx_buffer, tx_length)) {
|
||||||
ret_status = OSPI_STATUS_OK;
|
ret_status = OSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -217,12 +206,10 @@ ospi_status_t OSPI::read(ospi_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_ospi_command(instruction, address, alt);
|
_build_ospi_command(instruction, address, alt);
|
||||||
if (OSPI_STATUS_OK == ospi_read(&_ospi, &_ospi_command, rx_buffer, rx_length)) {
|
if (OSPI_STATUS_OK == ospi_read(&_ospi, &_ospi_command, rx_buffer, rx_length)) {
|
||||||
ret_status = OSPI_STATUS_OK;
|
ret_status = OSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -241,12 +228,10 @@ ospi_status_t OSPI::write(ospi_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_ospi_command(instruction, address, alt);
|
_build_ospi_command(instruction, address, alt);
|
||||||
if (OSPI_STATUS_OK == ospi_write(&_ospi, &_ospi_command, tx_buffer, tx_length)) {
|
if (OSPI_STATUS_OK == ospi_write(&_ospi, &_ospi_command, tx_buffer, tx_length)) {
|
||||||
ret_status = OSPI_STATUS_OK;
|
ret_status = OSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -263,12 +248,10 @@ ospi_status_t OSPI::command_transfer(ospi_inst_t instruction, int address, const
|
||||||
|
|
||||||
if (_initialized) {
|
if (_initialized) {
|
||||||
lock();
|
lock();
|
||||||
if (true == _acquire()) {
|
|
||||||
_build_ospi_command(instruction, address, -1); //We just need the command
|
_build_ospi_command(instruction, address, -1); //We just need the command
|
||||||
if (OSPI_STATUS_OK == ospi_command_transfer(&_ospi, &_ospi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
|
if (OSPI_STATUS_OK == ospi_command_transfer(&_ospi, &_ospi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
|
||||||
ret_status = OSPI_STATUS_OK;
|
ret_status = OSPI_STATUS_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +279,6 @@ bool OSPI::_initialize()
|
||||||
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);
|
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);
|
||||||
if (OSPI_STATUS_OK == ret) {
|
if (OSPI_STATUS_OK == ret) {
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
_owner = this;
|
|
||||||
} else {
|
} else {
|
||||||
_initialized = false;
|
_initialized = false;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +297,6 @@ bool OSPI::_initialize_direct()
|
||||||
ospi_status_t ret = ospi_init_direct(&_ospi, _static_pinmap, _hz, _mode);
|
ospi_status_t ret = ospi_init_direct(&_ospi, _static_pinmap, _hz, _mode);
|
||||||
if (OSPI_STATUS_OK == ret) {
|
if (OSPI_STATUS_OK == ret) {
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
_owner = this;
|
|
||||||
} else {
|
} else {
|
||||||
_initialized = false;
|
_initialized = false;
|
||||||
}
|
}
|
||||||
|
@ -323,18 +304,6 @@ bool OSPI::_initialize_direct()
|
||||||
return _initialized;
|
return _initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Private function with no locking
|
|
||||||
bool OSPI::_acquire()
|
|
||||||
{
|
|
||||||
if (_owner != this) {
|
|
||||||
//This will set freq as well
|
|
||||||
(this->*_init_func)();
|
|
||||||
_owner = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSPI::_build_ospi_command(ospi_inst_t instruction, int address, int alt)
|
void OSPI::_build_ospi_command(ospi_inst_t instruction, int address, int alt)
|
||||||
{
|
{
|
||||||
memset(&_ospi_command, 0, sizeof(ospi_command_t));
|
memset(&_ospi_command, 0, sizeof(ospi_command_t));
|
||||||
|
|
Loading…
Reference in New Issue