diff --git a/platform/posix/btstack_uart_posix.c b/platform/posix/btstack_uart_posix.c index c47ae5f8f..eb5317b60 100644 --- a/platform/posix/btstack_uart_posix.c +++ b/platform/posix/btstack_uart_posix.c @@ -48,7 +48,7 @@ #include /* POSIX terminal control definitions */ #include /* File control definitions */ -// #include /* UNIX standard function definitions */ +#include /* UNIX standard function definitions */ // #include // #include @@ -180,4 +180,20 @@ int btstack_uart_posix_set_parity(int fd, int parity){ return -1; } return 0; -} \ No newline at end of file +} + +// Generic helper +void btstack_uart_posix_write(int fd, const uint8_t * data, int size){ + // log_info("btstack_uart_posix_write (%u bytes)", size); + // log_info_hexdump(data, size); + while (size > 0) { + int bytes_written = write(fd, data, size); + if (bytes_written < 0) { + usleep(5000); + continue; + } + data += bytes_written; + size -= bytes_written; + } +} + diff --git a/platform/posix/btstack_uart_posix.h b/platform/posix/btstack_uart_posix.h index 05b452318..4e0bf1d4b 100644 --- a/platform/posix/btstack_uart_posix.h +++ b/platform/posix/btstack_uart_posix.h @@ -73,4 +73,12 @@ int btstack_uart_posix_set_baudrate(int fd, uint32_t baudrate); */ int btstack_uart_posix_set_parity(int fd, int parity); +/** + * @brief Blocking write + * @param fd + * @param data + * @param size + */ + void btstack_uart_posix_write(int fd, const uint8_t * data, int size); + #endif