/*---------------------------------------------------------------------------- write data to CDC_InBuf *---------------------------------------------------------------------------*/ int CDC_WrInBuf (const char *buffer, int *length) { int bytesToWrite, bytesWritten; // Write *length bytes bytesToWrite = *length; bytesWritten = bytesToWrite; // Just block if we can't write all at once // +1 to prevent an overflow of the ring buffer while( CDC_BUF_SIZE - CDC_BUF_COUNT(CDC_InBuf) < bytesToWrite+1 ); //uint8_t flush = CDC_DepInEmpty; USB_DEVINTEN = 0; while (bytesToWrite--) { CDC_BUF_WR(CDC_InBuf, *buffer++); // Copy Data to buffer } //if( flush == 1 ){ //if( CDC_DepInEmpty && CDC_BUF_COUNT(CDC_InBuf) ){ if( CDC_DepInEmpty ){ CDC_DepInEmpty = 0; CDC_BulkIn(); } USB_DEVINTEN = DEV_STAT_INT | (0xFF<<1) | (USB_SOF_EVENT ? FRAME_INT : 0); return (bytesWritten); }
/*---------------------------------------------------------------------------- write data to CDC_OutBuf *---------------------------------------------------------------------------*/ int CDC_WrOutBuf (const char *buffer, int length) { int bytesWritten; // ... add code to check for overwrite for( bytesWritten = 0; bytesWritten < length; bytesWritten++ ) { CDC_BUF_WR(CDC_OutBuf, *buffer++); // Copy Data to buffer } return (bytesWritten); }
/*---------------------------------------------------------------------------- write data to CDC_OutBuf *---------------------------------------------------------------------------*/ int CDC_WrOutBuf (const char *buffer, int *length) { int bytesToWrite, bytesWritten; // Write *length bytes bytesToWrite = *length; bytesWritten = bytesToWrite; // ... add code to check for overwrite while (bytesToWrite) { CDC_BUF_WR(CDC_OutBuf, *buffer++); // Copy Data to buffer bytesToWrite--; } return (bytesWritten); }