149
149
#include < errno.h>
150
150
151
151
using namespace mbed ;
152
+ using namespace std ::chrono;
152
153
153
154
#ifndef MBED_CONF_SD_CMD_TIMEOUT
154
155
#define MBED_CONF_SD_CMD_TIMEOUT 5000 /* !< Timeout in ms for response */
@@ -163,7 +164,7 @@ using namespace mbed;
163
164
#endif
164
165
165
166
166
- #define SD_COMMAND_TIMEOUT MBED_CONF_SD_CMD_TIMEOUT
167
+ #define SD_COMMAND_TIMEOUT milliseconds{ MBED_CONF_SD_CMD_TIMEOUT}
167
168
#define SD_CMD0_GO_IDLE_STATE_RETRIES MBED_CONF_SD_CMD0_IDLE_STATE_RETRIES
168
169
#define SD_DBG 0 /* !< 1 - Enable debugging */
169
170
#define SD_CMD_TRACE 0 /* !< 1 - Enable SD command tracing */
@@ -355,7 +356,7 @@ int SDBlockDevice::_initialise_card()
355
356
_spi_timer.start ();
356
357
do {
357
358
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));
359
360
_spi_timer.stop ();
360
361
361
362
// Initialization complete: ACMD41 successful
@@ -894,7 +895,7 @@ uint32_t SDBlockDevice::_go_idle_state()
894
895
if (R1_IDLE_STATE == response) {
895
896
break ;
896
897
}
897
- rtos::ThisThread::sleep_for (1 );
898
+ rtos::ThisThread::sleep_for (1ms );
898
899
}
899
900
return response;
900
901
}
@@ -1093,15 +1094,15 @@ bool SDBlockDevice::_wait_token(uint8_t token)
1093
1094
_spi_timer.stop ();
1094
1095
return true ;
1095
1096
}
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
1097
1098
_spi_timer.stop ();
1098
1099
debug_if (SD_DBG, " _wait_token: timeout\n " );
1099
1100
return false ;
1100
1101
}
1101
1102
1102
1103
// SPI function to wait till chip is ready
1103
1104
// 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 )
1105
1106
{
1106
1107
uint8_t response;
1107
1108
_spi_timer.reset ();
@@ -1112,7 +1113,7 @@ bool SDBlockDevice::_wait_ready(uint16_t ms)
1112
1113
_spi_timer.stop ();
1113
1114
return true ;
1114
1115
}
1115
- } while (_spi_timer.read_ms () < ms );
1116
+ } while (_spi_timer.elapsed_time () < timeout );
1116
1117
_spi_timer.stop ();
1117
1118
return false ;
1118
1119
}
0 commit comments