Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
#include <errno.h>

using namespace mbed;
using namespace std::chrono;

#ifndef MBED_CONF_SD_CMD_TIMEOUT
#define MBED_CONF_SD_CMD_TIMEOUT 5000 /*!< Timeout in ms for response */
Expand All @@ -163,7 +164,7 @@ using namespace mbed;
#endif


#define SD_COMMAND_TIMEOUT MBED_CONF_SD_CMD_TIMEOUT
#define SD_COMMAND_TIMEOUT milliseconds{MBED_CONF_SD_CMD_TIMEOUT}
#define SD_CMD0_GO_IDLE_STATE_RETRIES MBED_CONF_SD_CMD0_IDLE_STATE_RETRIES
#define SD_DBG 0 /*!< 1 - Enable debugging */
#define SD_CMD_TRACE 0 /*!< 1 - Enable SD command tracing */
Expand Down Expand Up @@ -355,7 +356,7 @@ int SDBlockDevice::_initialise_card()
_spi_timer.start();
do {
status = _cmd(ACMD41_SD_SEND_OP_COND, arg, 1, &response);
} while ((response & R1_IDLE_STATE) && (_spi_timer.read_ms() < SD_COMMAND_TIMEOUT));
} while ((response & R1_IDLE_STATE) && (_spi_timer.elapsed_time() < SD_COMMAND_TIMEOUT));
_spi_timer.stop();

// Initialization complete: ACMD41 successful
Expand Down Expand Up @@ -894,7 +895,7 @@ uint32_t SDBlockDevice::_go_idle_state()
if (R1_IDLE_STATE == response) {
break;
}
rtos::ThisThread::sleep_for(1);
rtos::ThisThread::sleep_for(1ms);
}
return response;
}
Expand Down Expand Up @@ -1093,15 +1094,15 @@ bool SDBlockDevice::_wait_token(uint8_t token)
_spi_timer.stop();
return true;
}
} while (_spi_timer.read_ms() < 300); // Wait for 300 msec for start token
} while (_spi_timer.elapsed_time() < 300ms); // Wait for 300 msec for start token
_spi_timer.stop();
debug_if(SD_DBG, "_wait_token: timeout\n");
return false;
}

// SPI function to wait till chip is ready
// The host controller should wait for end of the process until DO goes high (a 0xFF is received).
bool SDBlockDevice::_wait_ready(uint16_t ms)
bool SDBlockDevice::_wait_ready(std::chrono::duration<uint32_t, std::milli> timeout)
{
uint8_t response;
_spi_timer.reset();
Expand All @@ -1112,7 +1113,7 @@ bool SDBlockDevice::_wait_ready(uint16_t ms)
_spi_timer.stop();
return true;
}
} while (_spi_timer.read_ms() < ms);
} while (_spi_timer.elapsed_time() < timeout);
_spi_timer.stop();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class SDBlockDevice : public mbed::BlockDevice {
void _spi_wait(uint8_t count);

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