Skip to content

Commit 6d75e28

Browse files
authored
Merge pull request #12904 from kjbracey-arm/chrono_sd
SDBlockDevice: Convert to Chrono
2 parents 3fe0022 + f35667f commit 6d75e28

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
#include <errno.h>
150150

151151
using 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
}

components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class SDBlockDevice : public mbed::BlockDevice {
267267
void _spi_wait(uint8_t count);
268268

269269
bool _wait_token(uint8_t token); /**< Wait for token */
270-
bool _wait_ready(uint16_t ms = 300); /**< 300ms default wait for card to be ready */
270+
bool _wait_ready(std::chrono::duration<uint32_t, std::milli> timeout = std::chrono::milliseconds{300}); /**< 300ms default wait for card to be ready */
271271
int _read(uint8_t *buffer, uint32_t length);
272272
int _read_bytes(uint8_t *buffer, uint32_t length);
273273
uint8_t _write(const uint8_t *buffer, uint8_t token, uint32_t length);

0 commit comments

Comments
 (0)