1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

trezorhal/usb: add Inf timeout to blocking fns

This commit is contained in:
Jan Pochyla 2017-10-26 13:25:56 +02:00 committed by Pavol Rusnak
parent 9cb342fcb6
commit 51d00e1de7
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 14 additions and 19 deletions

View File

@ -8,19 +8,14 @@ int mp_hal_stdin_rx_chr(void) {
ensure(sectrue * (vcp_iface_num >= 0), "vcp stdio is not configured");
#define VCP_READ_TIMEOUT 25
uint8_t c = 0;
while (usb_vcp_read_blocking(vcp_iface_num, &c, 1, VCP_READ_TIMEOUT) < 1) {
// wait until we read a byte
}
usb_vcp_read_blocking(vcp_iface_num, &c, 1, -1);
return c;
}
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
#define VCP_WRITE_TIMEOUT 0
if (vcp_iface_num >= 0) {
usb_vcp_write_blocking(vcp_iface_num, (const uint8_t *)str, len, VCP_WRITE_TIMEOUT);
usb_vcp_write_blocking(vcp_iface_num, (const uint8_t *)str, len, 0);
} else {
// no-op
}

View File

@ -76,5 +76,5 @@ int usb_hid_read(uint8_t iface_num, uint8_t *buf, uint32_t len);
int usb_hid_write(uint8_t iface_num, const uint8_t *buf, uint32_t len);
int usb_hid_read_select(uint32_t timeout);
int usb_hid_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, uint32_t timeout);
int usb_hid_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, uint32_t timeout);
int usb_hid_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, int timeout);
int usb_hid_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, int timeout);

View File

@ -194,10 +194,10 @@ int usb_hid_read_select(uint32_t timeout) {
return -1; // Timeout
}
int usb_hid_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, uint32_t timeout) {
int usb_hid_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, int timeout) {
const uint32_t start = HAL_GetTick();
while (!usb_hid_can_read(iface_num)) {
if (HAL_GetTick() - start >= timeout) {
if (timeout >= 0 && HAL_GetTick() - start >= timeout) {
return 0; // Timeout
}
__WFI(); // Enter sleep mode, waiting for interrupt
@ -205,10 +205,10 @@ int usb_hid_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, uint32_
return usb_hid_read(iface_num, buf, len);
}
int usb_hid_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, uint32_t timeout) {
int usb_hid_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, int timeout) {
const uint32_t start = HAL_GetTick();
while (!usb_hid_can_write(iface_num)) {
if (HAL_GetTick() - start >= timeout) {
if (timeout >= 0 && HAL_GetTick() - start >= timeout) {
return 0; // Timeout
}
__WFI(); // Enter sleep mode, waiting for interrupt

View File

@ -125,5 +125,5 @@ secbool usb_vcp_can_write(uint8_t iface_num);
int usb_vcp_read(uint8_t iface_num, uint8_t *buf, uint32_t len);
int usb_vcp_write(uint8_t iface_num, const uint8_t *buf, uint32_t len);
int usb_vcp_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, uint32_t timeout);
int usb_vcp_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, uint32_t timeout);
int usb_vcp_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, int timeout);
int usb_vcp_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, int timeout);

View File

@ -291,10 +291,10 @@ int usb_vcp_write(uint8_t iface_num, const uint8_t *buf, uint32_t len) {
return len;
}
int usb_vcp_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, uint32_t timeout) {
int usb_vcp_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, int timeout) {
uint32_t start = HAL_GetTick();
while (!usb_vcp_can_read(iface_num)) {
if (HAL_GetTick() - start >= timeout) {
if (timeout >= 0 && HAL_GetTick() - start >= timeout) {
return 0; // Timeout
}
__WFI(); // Enter sleep mode, waiting for interrupt
@ -302,10 +302,10 @@ int usb_vcp_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, uint32_
return usb_vcp_read(iface_num, buf, len);
}
int usb_vcp_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, uint32_t timeout) {
int usb_vcp_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, int timeout) {
uint32_t start = HAL_GetTick();
while (!usb_vcp_can_write(iface_num)) {
if (HAL_GetTick() - start >= timeout) {
if (timeout >= 0 && HAL_GetTick() - start >= timeout) {
return 0; // Timeout
}
__WFI(); // Enter sleep mode, waiting for interrupt