149149#include < errno.h>
150150
151151using namespace mbed ;
152+ using namespace std ::chrono;
152153
153154#ifndef MBED_CONF_SD_CMD_TIMEOUT
154155#define MBED_CONF_SD_CMD_TIMEOUT 5000 /* !< Timeout in ms for response */
@@ -163,7 +164,7 @@ using namespace mbed;
163164#endif
164165
165166
166- #define SD_COMMAND_TIMEOUT MBED_CONF_SD_CMD_TIMEOUT
167+ #define SD_COMMAND_TIMEOUT milliseconds{ MBED_CONF_SD_CMD_TIMEOUT}
167168#define SD_CMD0_GO_IDLE_STATE_RETRIES MBED_CONF_SD_CMD0_IDLE_STATE_RETRIES
168169#define SD_DBG 0 /* !< 1 - Enable debugging */
169170#define SD_CMD_TRACE 0 /* !< 1 - Enable SD command tracing */
@@ -355,7 +356,7 @@ int SDBlockDevice::_initialise_card()
355356 _spi_timer.start ();
356357 do {
357358 status = _cmd (ACMD41_SD_SEND_OP_COND, arg, 1 , &response);
358- } while ((response & R1_IDLE_STATE) && (_spi_timer.read_ms () < SD_COMMAND_TIMEOUT));
359+ } while ((response & R1_IDLE_STATE) && (_spi_timer.elapsed_time () < SD_COMMAND_TIMEOUT));
359360 _spi_timer.stop ();
360361
361362 // Initialization complete: ACMD41 successful
@@ -894,7 +895,7 @@ uint32_t SDBlockDevice::_go_idle_state()
894895 if (R1_IDLE_STATE == response) {
895896 break ;
896897 }
897- rtos::ThisThread::sleep_for (1 );
898+ rtos::ThisThread::sleep_for (1ms );
898899 }
899900 return response;
900901}
@@ -1093,15 +1094,15 @@ bool SDBlockDevice::_wait_token(uint8_t token)
10931094 _spi_timer.stop ();
10941095 return true ;
10951096 }
1096- } while (_spi_timer.read_ms () < 300 ); // Wait for 300 msec for start token
1097+ } while (_spi_timer.elapsed_time () < 300ms ); // Wait for 300 msec for start token
10971098 _spi_timer.stop ();
10981099 debug_if (SD_DBG, " _wait_token: timeout\n " );
10991100 return false ;
11001101}
11011102
11021103// SPI function to wait till chip is ready
11031104// The host controller should wait for end of the process until DO goes high (a 0xFF is received).
1104- bool SDBlockDevice::_wait_ready (uint16_t ms )
1105+ bool SDBlockDevice::_wait_ready (std::chrono::duration< uint32_t , std::milli> timeout )
11051106{
11061107 uint8_t response;
11071108 _spi_timer.reset ();
@@ -1112,7 +1113,7 @@ bool SDBlockDevice::_wait_ready(uint16_t ms)
11121113 _spi_timer.stop ();
11131114 return true ;
11141115 }
1115- } while (_spi_timer.read_ms () < ms );
1116+ } while (_spi_timer.elapsed_time () < timeout );
11161117 _spi_timer.stop ();
11171118 return false ;
11181119}
0 commit comments