mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-28 16:13:37 +08:00
Modify the _write lock to wait on resource instead of xfer
This commit is contained in:
+12
-13
@@ -26,25 +26,24 @@ int _write(int file, char* data, int len) {
|
||||
int written = 0;
|
||||
switch (serial_printf_select) {
|
||||
case SERIAL_PRINTF_IS_USB: {
|
||||
// transmit over CDC
|
||||
uint8_t status = CDC_Transmit_FS((uint8_t*)data, len);
|
||||
written = (status == USBD_OK) ? len : 0;
|
||||
|
||||
// Wait for transmission to complete
|
||||
osSemaphoreWait(sem_usb_tx, osWaitForever);
|
||||
// Wait for the interface to be available
|
||||
osStatus sem_stat = osSemaphoreWait(sem_usb_tx, osWaitForever);
|
||||
if (sem_stat == osOK) {
|
||||
uint8_t status = CDC_Transmit_FS((uint8_t*)data, len); // transmit over CDC
|
||||
written = (status == USBD_OK) ? len : 0;
|
||||
}
|
||||
} break;
|
||||
|
||||
case SERIAL_PRINTF_IS_UART: {
|
||||
//Check length
|
||||
if (len > UART_TX_BUFFER_SIZE)
|
||||
return 0;
|
||||
// memcpy data into uart_tx_buf
|
||||
memcpy(uart_tx_buf, data, len);
|
||||
// Start DMA background trasnfer
|
||||
HAL_UART_Transmit_DMA(&huart4, uart_tx_buf, len);
|
||||
|
||||
// Wait for the transmission to complete
|
||||
osSemaphoreWait(sem_uart_dma, osWaitForever);
|
||||
// Wait for the interface to be available
|
||||
osStatus sem_stat = osSemaphoreWait(sem_uart_dma, osWaitForever);
|
||||
if (sem_stat == osOK) {
|
||||
memcpy(uart_tx_buf, data, len); // memcpy data into uart_tx_buf
|
||||
HAL_UART_Transmit_DMA(&huart4, uart_tx_buf, len); // Start DMA background transfer
|
||||
}
|
||||
} break;
|
||||
|
||||
default: {
|
||||
|
||||
Reference in New Issue
Block a user