2323
2424namespace mbed {
2525
26- OSPI *OSPI::_owner = NULL ;
2726SingletonPtr<PlatformMutex> OSPI::_mutex;
2827
2928uint8_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-
338307void 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