@@ -367,15 +367,14 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size)
367
367
if (xSemaphoreTake (tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
368
368
return 0 ;
369
369
}
370
- size_t max_size = xRingbufferGetMaxItemSize (tx_ring_buf);
371
370
size_t space = xRingbufferGetCurFreeSize (tx_ring_buf);
372
371
size_t to_send = size, so_far = 0 ;
373
372
374
373
if (space > size){
375
374
space = size;
376
375
}
377
376
// Non-Blocking method, Sending data to ringbuffer, and handle the data in ISR.
378
- if (xRingbufferSend (tx_ring_buf, (void *) (buffer), space, 0 ) != pdTRUE){
377
+ if (space > 0 && xRingbufferSend (tx_ring_buf, (void *) (buffer), space, 0 ) != pdTRUE){
379
378
size = 0 ;
380
379
} else {
381
380
to_send -= space;
@@ -385,16 +384,17 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size)
385
384
if (connected) usb_serial_jtag_ll_ena_intr_mask (USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
386
385
387
386
while (to_send){
388
- if (max_size > to_send){
389
- max_size = to_send;
387
+ space = xRingbufferGetCurFreeSize (tx_ring_buf);
388
+ if (space > to_send){
389
+ space = to_send;
390
390
}
391
391
// Blocking method, Sending data to ringbuffer, and handle the data in ISR.
392
- if (xRingbufferSend (tx_ring_buf, (void *) (buffer+so_far), max_size , tx_timeout_ms / portTICK_PERIOD_MS) != pdTRUE){
392
+ if (xRingbufferSend (tx_ring_buf, (void *) (buffer+so_far), space , tx_timeout_ms / portTICK_PERIOD_MS) != pdTRUE){
393
393
size = so_far;
394
394
break ;
395
395
}
396
- so_far += max_size ;
397
- to_send -= max_size ;
396
+ so_far += space ;
397
+ to_send -= space ;
398
398
// Now trigger the ISR to read data from the ring buffer.
399
399
usb_serial_jtag_ll_txfifo_flush ();
400
400
if (connected) usb_serial_jtag_ll_ena_intr_mask (USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
0 commit comments