コード例 #1
0
ファイル: CDC1.c プロジェクト: tsbiberdorf/CDCK60d
/*
** ===================================================================
**     Method      :  CDC1_SendChar (component FSL_USB_CDC_Device)
**     Description :
**         Method to send a character to the USB interface. Method is
**         non-blocking: If the output buffer is full, it tries to send
**         it over USB. If this fails or buffer is still full, the
**         character will be lost. If OnError() event is enabled, the
**         error event will be called in case of error.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Chr             - Character to send.
**     Returns     :
**         ---             - Error code. ERR_OK for success and
**                           ERR_FAILED otherwise.
** ===================================================================
*/
byte CDC1_SendChar(CDC1_TComData Chr)
{
  static uint8_t txBuf[CDC1_DATA_BUFF_SIZE];

  if (Tx1_Put(Chr)==ERR_TXFULL) { /* retry once, otherwise throw it away  */
    if (CDC1_App_Task(txBuf, sizeof(txBuf))!=ERR_OK) { /* call USB handler: if active, then this will empty the buffer */
      return ERR_TXFULL;
    } else { /* retry, as USB App_Task() should have sent the buffer */
      return Tx1_Put(Chr); /* retry. If buffer is still full, we will lose the character */
    }
  }
  return ERR_OK;
}
コード例 #2
0
ファイル: CDC1.c プロジェクト: kevin-ledinh/banana-tree
/*
** ===================================================================
**     Method      :  CDC1_PutBufferChecked (component FSL_USB_CDC_Device)
**     Description :
**         Puts a data block into the output buffer, but does not send
**         it. If there is not enough size available, then ERR_TXFULL
**         is returned, otherwise ERR_OK. The application then needs to
**         call USB_App_Callback() to actually send the buffer.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * buf             - Pointer to buffer to be sent
**         bufsize         - Buffer size in bytes
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
uint8_t CDC1_PutBufferChecked(uint8_t *buf, size_t bufSize)
{
  uint8_t res;

  if(bufSize>CDC1_GetFreeInTxBuf()) { /* no room at the Inn... */
    res = ERR_TXFULL;
  } else {
    res = ERR_OK;
    while(bufSize>0 && res==ERR_OK) {
      res = Tx1_Put(*buf);
      bufSize--;
      buf++;
    }
  }
  return res;
}