lpcware

how is vcom_bread supposed to work?

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by sjondur on Mon Nov 02 15:08:22 MST 2015
What happens when you read the com buffer in multiple segments?

In its current form it will copy from the same location again and again when the function is called repeatedly:
memcpy(pBuf, pVcom->rx_buff, cnt);

why not do
memcpy(pBuf, pVcom->rx_buff + rx_rd_count, cnt);  
etc...

cdc_vcom.c
/* Virtual com port buffered read routine */
uint32_t vcom_bread(uint8_t *pBuf, uint32_t buf_len)
{
VCOM_DATA_T *pVcom = &g_vCOM;
uint16_t cnt = 0;
/* read from the default buffer if any data present */
if (pVcom->rx_count) {
cnt = (pVcom->rx_count < buf_len) ? pVcom->rx_count : buf_len;
memcpy(pBuf, pVcom->rx_buff, cnt);
pVcom->rx_rd_count += cnt;

/* enter critical section */
NVIC_DisableIRQ(USB0_IRQn);
if (pVcom->rx_rd_count >= pVcom->rx_count) {
pVcom->rx_flags &= ~VCOM_RX_BUF_FULL;
pVcom->rx_rd_count = pVcom->rx_count = 0;
}
/* exit critical section */
NVIC_EnableIRQ(USB0_IRQn);
}
return cnt;

}

Outcomes