Exemplo n.º 1
0
/*virtual*/ size_t USBSerialStream::available()
{
  setupReadableISR(false); //m_inBuf.available() is not reentrant
  size_t len = m_inBuf.available();
  setupReadableISR(true);
  return len;
}
Exemplo n.º 2
0
//0 for non-blocking (returns immediately), -1 for infinite blocking
/*virtual*/ int USBSerialStream::read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout/*=osWaitForever*/)
{
  uint8_t *bufPointerCopy = buf;
  DBG("Trying to read at most %d chars", maxLength);
  int ret = waitAvailable(timeout);
  if(ret)
  {
    WARN("Error %d while waiting for incoming data", ret);
    return ret;
  }
  int a = available(); //Prevent macro issues
  int readLen = MIN( a, maxLength );
  *pLength = readLen;
  
  
  setupReadableISR(false);
  while(readLen--)
  {
    m_inBuf.dequeue(buf);
    buf++;
  }
  setupReadableISR(true);
  //printBuffer(bufPointerCopy,*pLength,true); // XXX
  
  return OK;
}