Implementation of the discussed changes
- remove usbd_edpt_xfer_abort - rename tu_fifo_change_mode to tu_fifo_set_mode - remove CFG_TUD_CDC_CLEAR_AT_CONNECTION definition - remove auto fifo clear at connection event - add tud_cdc_n_write_clear function
This commit is contained in:
@@ -207,6 +207,10 @@ uint32_t tud_cdc_n_write_available (uint8_t itf)
|
|||||||
return tu_fifo_remaining(&_cdcd_itf[itf].tx_ff);
|
return tu_fifo_remaining(&_cdcd_itf[itf].tx_ff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tud_cdc_n_write_clear (uint8_t itf)
|
||||||
|
{
|
||||||
|
return tu_fifo_clear(&_cdcd_itf[itf].tx_ff);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// USBD Driver API
|
// USBD Driver API
|
||||||
@@ -229,6 +233,9 @@ void cdcd_init(void)
|
|||||||
|
|
||||||
// config fifo
|
// config fifo
|
||||||
tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, TU_ARRAY_SIZE(p_cdc->rx_ff_buf), 1, false);
|
tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, TU_ARRAY_SIZE(p_cdc->rx_ff_buf), 1, false);
|
||||||
|
// tx fifo is set to overwritable at initialization and will be changed to not overwritable
|
||||||
|
// if terminal supports DTR bit. Without DTR we do not know if data is actually polled by terminal.
|
||||||
|
// In this way, the most current data is prioritized.
|
||||||
tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, true);
|
tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, true);
|
||||||
|
|
||||||
#if CFG_FIFO_MUTEX
|
#if CFG_FIFO_MUTEX
|
||||||
@@ -384,20 +391,14 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
|||||||
bool const dtr = tu_bit_test(request->wValue, 0);
|
bool const dtr = tu_bit_test(request->wValue, 0);
|
||||||
bool const rts = tu_bit_test(request->wValue, 1);
|
bool const rts = tu_bit_test(request->wValue, 1);
|
||||||
|
|
||||||
#if CFG_TUD_CDC_CLEAR_AT_CONNECTION
|
// TODO if terminal supports DTR we can check for an connection event here and
|
||||||
// DTE connected event (if DTE supports DTR bit)
|
// clear the fifo as well as ongoing transfers with new usbd_edpt_xfer_abort api.
|
||||||
if ( dtr && !tu_bit_test(p_cdc->line_state, 0) )
|
// Until then user can self clear the buffer with tud_cdc_n_write_clear in tud_cdc_line_state_cb
|
||||||
{
|
|
||||||
// Clear not transmitted data
|
|
||||||
usbd_edpt_xfer_abort(rhport, p_cdc->ep_in);
|
|
||||||
tu_fifo_clear(&p_cdc->tx_ff);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
p_cdc->line_state = (uint8_t) request->wValue;
|
p_cdc->line_state = (uint8_t) request->wValue;
|
||||||
|
|
||||||
// Disable fifo overwriting if DTR bit is set
|
// Disable fifo overwriting if DTR bit is set
|
||||||
tu_fifo_change_mode(&p_cdc->tx_ff, (dtr?false:true));
|
tu_fifo_set_mode(&p_cdc->tx_ff, !dtr);
|
||||||
|
|
||||||
TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
|
TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
|
||||||
|
|
||||||
|
@@ -43,10 +43,6 @@
|
|||||||
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CFG_TUD_CDC_CLEAR_AT_CONNECTION
|
|
||||||
#define CFG_TUD_CDC_CLEAR_AT_CONNECTION 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -106,6 +102,9 @@ uint32_t tud_cdc_n_write_flush (uint8_t itf);
|
|||||||
// Return the number of bytes (characters) available for writing to TX FIFO buffer in a single n_write operation.
|
// Return the number of bytes (characters) available for writing to TX FIFO buffer in a single n_write operation.
|
||||||
uint32_t tud_cdc_n_write_available (uint8_t itf);
|
uint32_t tud_cdc_n_write_available (uint8_t itf);
|
||||||
|
|
||||||
|
// Clear the transmit FIFO
|
||||||
|
bool tud_cdc_n_write_clear (uint8_t itf);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Application API (Single Port)
|
// Application API (Single Port)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -125,6 +124,7 @@ static inline uint32_t tud_cdc_write (void const* buffer, uint32_t buf
|
|||||||
static inline uint32_t tud_cdc_write_str (char const* str);
|
static inline uint32_t tud_cdc_write_str (char const* str);
|
||||||
static inline uint32_t tud_cdc_write_flush (void);
|
static inline uint32_t tud_cdc_write_flush (void);
|
||||||
static inline uint32_t tud_cdc_write_available (void);
|
static inline uint32_t tud_cdc_write_available (void);
|
||||||
|
static inline bool tud_cdc_write_clear (void);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Application Callback API (weak is optional)
|
// Application Callback API (weak is optional)
|
||||||
@@ -234,6 +234,11 @@ static inline uint32_t tud_cdc_write_available(void)
|
|||||||
return tud_cdc_n_write_available(0);
|
return tud_cdc_n_write_available(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool tud_cdc_write_clear(void)
|
||||||
|
{
|
||||||
|
return tud_cdc_n_write_clear(0);
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
@@ -603,9 +603,11 @@ bool tu_fifo_clear(tu_fifo_t *f)
|
|||||||
|
|
||||||
@param[in] f
|
@param[in] f
|
||||||
Pointer to the FIFO buffer to manipulate
|
Pointer to the FIFO buffer to manipulate
|
||||||
|
@param[in] overwritable
|
||||||
|
Overwritable mode the fifo is set to
|
||||||
*/
|
*/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
bool tu_fifo_change_mode(tu_fifo_t *f, bool overwritable)
|
bool tu_fifo_set_mode(tu_fifo_t *f, bool overwritable)
|
||||||
{
|
{
|
||||||
tu_fifo_lock(f);
|
tu_fifo_lock(f);
|
||||||
|
|
||||||
|
@@ -89,7 +89,7 @@ typedef struct
|
|||||||
.non_used_index_space = 0xFFFF - 2*_depth-1, \
|
.non_used_index_space = 0xFFFF - 2*_depth-1, \
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tu_fifo_change_mode(tu_fifo_t *f, bool overwritable);
|
bool tu_fifo_set_mode(tu_fifo_t *f, bool overwritable);
|
||||||
bool tu_fifo_clear(tu_fifo_t *f);
|
bool tu_fifo_clear(tu_fifo_t *f);
|
||||||
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable);
|
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable);
|
||||||
|
|
||||||
|
@@ -1191,33 +1191,6 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool usbd_edpt_xfer_abort(uint8_t rhport, uint8_t ep_addr)
|
|
||||||
{
|
|
||||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
|
||||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
|
||||||
|
|
||||||
TU_LOG2(" Abort XFER EP %02X ... ", ep_addr);
|
|
||||||
|
|
||||||
// Abort API is optional for DCD
|
|
||||||
if ( dcd_edpt_xfer_abort )
|
|
||||||
{
|
|
||||||
if ( dcd_edpt_xfer_abort(rhport, ep_addr) )
|
|
||||||
{
|
|
||||||
_usbd_dev.ep_status[epnum][dir].busy = false;
|
|
||||||
TU_LOG2("OK\r\n");
|
|
||||||
return true;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
TU_LOG2("failed\r\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
TU_LOG2("no DCD support\r\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr)
|
bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
(void) rhport;
|
(void) rhport;
|
||||||
|
@@ -70,9 +70,6 @@ void usbd_edpt_close(uint8_t rhport, uint8_t ep_addr);
|
|||||||
// Submit a usb transfer
|
// Submit a usb transfer
|
||||||
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
||||||
|
|
||||||
// Abort a scheduled transfer
|
|
||||||
bool usbd_edpt_xfer_abort(uint8_t rhport, uint8_t ep_addr);
|
|
||||||
|
|
||||||
// Claim an endpoint before submitting a transfer.
|
// Claim an endpoint before submitting a transfer.
|
||||||
// If caller does not make any transfer, it must release endpoint for others.
|
// If caller does not make any transfer, it must release endpoint for others.
|
||||||
bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr);
|
bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr);
|
||||||
|
Reference in New Issue
Block a user