mirror of https://github.com/ARMmbed/mbed-os.git
To judge send ZLP or not in USBCDC::AsyncWrite
parent
ca616c865a
commit
c30af6a7df
|
@ -39,7 +39,7 @@ public:
|
|||
AsyncWrite(USBCDC *serial, uint8_t *buf, uint32_t size):
|
||||
serial(serial), tx_buf(buf), tx_size(size), result(false)
|
||||
{
|
||||
|
||||
need_zlp = (size % CDC_MAX_PACKET_SIZE == 0) ? true : false;
|
||||
}
|
||||
|
||||
virtual ~AsyncWrite()
|
||||
|
@ -59,6 +59,12 @@ public:
|
|||
tx_size -= actual_size;
|
||||
tx_buf += actual_size;
|
||||
if (tx_size == 0) {
|
||||
// For ZLP case, not ending yet and need one more time to invoke process to send zero packet.
|
||||
if (need_zlp) {
|
||||
need_zlp = false;
|
||||
serial->_send_isr_start();
|
||||
return false;
|
||||
}
|
||||
result = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -72,6 +78,7 @@ public:
|
|||
uint8_t *tx_buf;
|
||||
uint32_t tx_size;
|
||||
bool result;
|
||||
bool need_zlp;
|
||||
};
|
||||
|
||||
class USBCDC::AsyncRead: public AsyncOp {
|
||||
|
@ -388,7 +395,9 @@ void USBCDC::send_nb(uint8_t *buffer, uint32_t size, uint32_t *actual, bool now)
|
|||
}
|
||||
_tx_size += write_size;
|
||||
*actual = write_size;
|
||||
if ((CDC_MAX_PACKET_SIZE == size) && (CDC_MAX_PACKET_SIZE == write_size)) {
|
||||
|
||||
/* Enable ZLP flag as while send_nb() zero size */
|
||||
if (size == 0) {
|
||||
_trans_zlp = true;
|
||||
}
|
||||
|
||||
|
@ -409,6 +418,14 @@ void USBCDC::_send_isr_start()
|
|||
_tx_in_progress = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Send ZLP write start */
|
||||
if (!_tx_in_progress && _trans_zlp) {
|
||||
if (USBDevice::write_start(_bulk_in, _tx_buffer, 0)) {
|
||||
_tx_in_progress = true;
|
||||
_trans_zlp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -419,11 +436,6 @@ void USBCDC::_send_isr()
|
|||
{
|
||||
assert_locked();
|
||||
|
||||
/* Send ZLP write start after last alignment packet sent */
|
||||
if (_trans_zlp && USBDevice::write_start(_bulk_in, _tx_buffer, 0)) {
|
||||
_trans_zlp = false;
|
||||
}
|
||||
|
||||
write_finish(_bulk_in);
|
||||
_tx_buf = _tx_buffer;
|
||||
_tx_size = 0;
|
||||
|
|
Loading…
Reference in New Issue