<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic how is vcom_bread supposed to work? in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/how-is-vcom-bread-supposed-to-work/m-p/523252#M5888</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sjondur on Mon Nov 02 15:08:22 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;What happens when you read the com buffer in multiple segments?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In its current form it will copy from the same location again and again when the function is called repeatedly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;memcpy(pBuf, pVcom-&amp;gt;rx_buff, cnt);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;why not do&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;memcpy(pBuf, pVcom-&amp;gt;rx_buff + rx_rd_count, cnt);&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;etc...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;cdc_vcom.c&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;/* Virtual com port buffered read routine */
uint32_t vcom_bread(uint8_t *pBuf, uint32_t buf_len)
{
VCOM_DATA_T *pVcom = &amp;amp;g_vCOM;
uint16_t cnt = 0;
/* read from the default buffer if any data present */
if (pVcom-&amp;gt;rx_count) {
cnt = (pVcom-&amp;gt;rx_count &amp;lt; buf_len) ? pVcom-&amp;gt;rx_count : buf_len;
memcpy(pBuf, pVcom-&amp;gt;rx_buff, cnt);
pVcom-&amp;gt;rx_rd_count += cnt;

/* enter critical section */
NVIC_DisableIRQ(USB0_IRQn);
if (pVcom-&amp;gt;rx_rd_count &amp;gt;= pVcom-&amp;gt;rx_count) {
pVcom-&amp;gt;rx_flags &amp;amp;= ~VCOM_RX_BUF_FULL;
pVcom-&amp;gt;rx_rd_count = pVcom-&amp;gt;rx_count = 0;
}
/* exit critical section */
NVIC_EnableIRQ(USB0_IRQn);
}
return cnt;

}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 16:44:15 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T16:44:15Z</dc:date>
    <item>
      <title>how is vcom_bread supposed to work?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/how-is-vcom-bread-supposed-to-work/m-p/523252#M5888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sjondur on Mon Nov 02 15:08:22 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;What happens when you read the com buffer in multiple segments?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In its current form it will copy from the same location again and again when the function is called repeatedly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;memcpy(pBuf, pVcom-&amp;gt;rx_buff, cnt);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;why not do&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;memcpy(pBuf, pVcom-&amp;gt;rx_buff + rx_rd_count, cnt);&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;etc...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;cdc_vcom.c&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;/* Virtual com port buffered read routine */
uint32_t vcom_bread(uint8_t *pBuf, uint32_t buf_len)
{
VCOM_DATA_T *pVcom = &amp;amp;g_vCOM;
uint16_t cnt = 0;
/* read from the default buffer if any data present */
if (pVcom-&amp;gt;rx_count) {
cnt = (pVcom-&amp;gt;rx_count &amp;lt; buf_len) ? pVcom-&amp;gt;rx_count : buf_len;
memcpy(pBuf, pVcom-&amp;gt;rx_buff, cnt);
pVcom-&amp;gt;rx_rd_count += cnt;

/* enter critical section */
NVIC_DisableIRQ(USB0_IRQn);
if (pVcom-&amp;gt;rx_rd_count &amp;gt;= pVcom-&amp;gt;rx_count) {
pVcom-&amp;gt;rx_flags &amp;amp;= ~VCOM_RX_BUF_FULL;
pVcom-&amp;gt;rx_rd_count = pVcom-&amp;gt;rx_count = 0;
}
/* exit critical section */
NVIC_EnableIRQ(USB0_IRQn);
}
return cnt;

}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 16:44:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/how-is-vcom-bread-supposed-to-work/m-p/523252#M5888</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T16:44:15Z</dc:date>
    </item>
  </channel>
</rss>

