void 
USBSerialStream::BulkIn(U8 bEP, U8 bEPStatus)
{
	static bool bLastWasFull = false;

	instance()->TransferData(false);
	return;

	USBHwEPWrite(bEP, (U8*)"a", 1);
	return;
	if (instance()->m_infifo.size() > 0) {
		int datatoWrite = instance()->m_infifo.size();
		if (datatoWrite >= MAX_PACKET_SIZE) {
			bLastWasFull = true;
			datatoWrite = MAX_PACKET_SIZE;
		} else {
			bLastWasFull = false;
		}
		instance()->m_infifo.pop(dataBuf, datatoWrite);
		USBHwEPWrite(bEP, dataBuf, datatoWrite);
	} else if (bLastWasFull) {
		// I think we need to transmit a zero length package in this case.
		USBHwEPWrite(bEP, dataBuf, 0);
	}

}
Exemple #2
0
/**
	Handles the BOT bulk IN endpoint
		
	@param [in]	bEP			Endpoint number
	@param [in]	bEPStatus	Endpoint status (indicates NAK, STALL, etc)
		
 */
void MSCBotBulkIn(U8 bEP, U8 bEPStatus)
{
	// ignore events on stalled EP
	if (bEPStatus & EP_STATUS_STALLED) {
		return;
	}

	switch (eState) {
	
	case eCBW:
	case eDataOut:
		// ignore possibly old ACKs
		break;
	
	case eDataIn:
		HandleDataIn();
		break;
	
	case eCSW:
		// wait for an IN token, then send the CSW
		USBHwEPWrite(MSC_BULK_IN_EP, (U8 *)&CSW, 13);
		eState = eCBW;
		break;
		
	case eStalled:
		// keep stalling
		USBHwEPStall(MSC_BULK_IN_EP, TRUE);
		break;
		
	default:
		DBG("Invalid state %d\n", eState);
		ASSERT(FALSE);
		break;
	}
}
Exemple #3
0
/*************************************************************************
	HandleDataIn
	============
		Handles data from device-to-host
		
**************************************************************************/
static void HandleDataIn(void)
{
	int iChunk;
	
	// process data for host in SCSI layer
	pbData = SCSIHandleData(CBW.CBWCB, CBW.bCBWCBLength, pbData, dwOffset);
	if (pbData == NULL) {
		BOTStall();
		SendCSW(STATUS_FAILED);
		return;
	}

	// send data to host?
	if (dwOffset < dwTransferSize) {
		iChunk = MIN(64, dwTransferSize - dwOffset);
		USBHwEPWrite(MSC_BULK_IN_EP, pbData, iChunk);
		dwOffset += iChunk;
	}
	
	// are we done now?
	if (dwOffset == dwTransferSize) {
		if (dwOffset != CBW.dwCBWDataTransferLength) {
			// stall pipe
			DBG("stalling DIN");
			BOTStall();
		}
		// done
		SendCSW(STATUS_PASSED);
	}
}
void 
USBSerialStream::TransferData(bool bInit)
{
	// We'll end up here both if we come from the frame handler, and the bulkin handler


	if (bInit) {
		m_bTransferInProgress = true;
		m_bDontStartNew = true;
	}

	if (!m_bTransferInProgress) {
		return;
	}



	int dataToSend = m_infifo.size();

	if (dataToSend >= MAX_PACKET_SIZE) {
		dataToSend = MAX_PACKET_SIZE;
	} else {
		m_bTransferInProgress = false;
		m_bDontStartNew = false;
	}

	
	instance()->m_infifo.pop(dataBuf, dataToSend);
	USBHwEPWrite(BULK_IN_EP, dataBuf, dataToSend);
}
Exemple #5
0
/**
	Local function to handle outgoing bulk data

	@param [in] bEP
	@param [in] bEPStatus
 */
static void BulkIn(unsigned char bEP, unsigned char bEPStatus)
{
    int i, iLen;
    long lHigherPriorityTaskWoken = pdFALSE;

    ( void ) bEPStatus;

    if (uxQueueMessagesWaitingFromISR( xCharsForTx ) == 0) {
        // no more data, disable further NAK interrupts until next USB frame
        USBHwNakIntEnable(0);
        return;
    }

    // get bytes from transmit FIFO into intermediate buffer
    for (i = 0; i < MAX_PACKET_SIZE; i++) {
        if( xQueueReceiveFromISR( xCharsForTx, ( &abBulkBuf[i] ), &lHigherPriorityTaskWoken ) != pdPASS )
        {
            break;
        }
    }
    iLen = i;

    // send over USB
    if (iLen > 0) {
        USBHwEPWrite(bEP, abBulkBuf, iLen);
    }

    portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
}
/**
    Local function to handle outgoing bulk data

    @param [in] bEP
    @param [in] bEPStatus
 */
static void BulkIn(U8 bEP, U8 bEPStatus)
{
  int i, iLen;

  // Verifica se não há data para enviar ao PC
  if (_fifo_avail(&txfifo) == 0)
  {
    // no more data, disable further NAK interrupts until next USB frame
    USBHwNakIntEnable(0); // não é gerada nenhuma interrupção sempre que o host tenta ler/escrever nos EPs mas este estão cheios/vazios.
    return;
  }

  // get bytes from transmit FIFO into intermediate buffer
  for (i = 0; i < MAX_PACKET_SIZE; i++)
  {
    if (!_fifo_get(&txfifo, &abBulkBuf[i]))
    {
      break; // sai do ciclo quando o fifo fica vazio, terminando a transferência de informação do &txfifo para &abBulkBuf[].
    }
  }
  iLen = i;

  // send over USB
  if (iLen > 0)
  {
    USBHwEPWrite(bEP, abBulkBuf, iLen);
  }
}
Exemple #7
0
/**
    Local function to handle outgoing bulk data

    @param [in] bEP
    @param [in] bEPStatus
 */
static void BulkIn(U8 bEP, U8 bEPStatus)
{
  int i, iLen;

  if (_fifo_avail(&txfifo) == 0)
  {
    // no more data, disable further NAK interrupts until next USB frame
    USBHwNakIntEnable(0);
    return;
  }

  // get bytes from transmit FIFO into intermediate buffer
  for (i = 0; i < MAX_PACKET_SIZE; i++)
  {
    if (!_fifo_get(&txfifo, &abBulkBuf[i]))
    {
      break;
    }
  }
  iLen = i;

  // send over USB
  if (iLen > 0)
  {
    USBHwEPWrite(bEP, abBulkBuf, iLen);
  }
}
Exemple #8
0
/**
	Sends the next packet in chain of packets to the host
		
	@param [in] bEP
	@param [in] bEPStatus
 */
static void SendNextBulkIn(uint8_t bEP, bool fFirstPacket)
{
	int iLen;

	// this transfer is done
	fBulkInBusy = FALSE;
	
	// first packet?
	if (fFirstPacket) {
		fChainDone = FALSE;
	}

	// last packet?
	if (fChainDone) {
		return;
	}
	
	// get up to MAX_PACKET_SIZE bytes from transmit FIFO into intermediate buffer
//	for (iLen = 0; iLen < MAX_PACKET_SIZE; iLen++) {
//		if (!fifo_get(&txfifo, &abBulkBuf[iLen])) {
//			break;
//		}
//	}
	
	// send over USB
	USBHwEPWrite(bEP, abBulkBuf, iLen);
	fBulkInBusy = TRUE;

	// was this a short packet?
	if (iLen < MAX_PACKET_SIZE) {
		fChainDone = TRUE;
	}
}
Exemple #9
0
void USBFrameHandler(uint16_t wFrame)
{

    // send over USB
    if( isConnectedFlag ) {

        if( delay < 4000 ) {
            //FIXME need to delay a few seconds before doing isoc writes, impliment more elegant solution, status or event driven....
            delay++;
        } else {

            //Always write whatever is in our most recent isoc output data buffer, you may want to pust somthing interesting in there....
            inputIsocDataBuffer[0]++;

            USBHwEPWrite(ISOC_IN_EP, inputIsocDataBuffer, BYTES_PER_ISOC_FRAME);

            int iLen = USBHwISOCEPRead(ISOC_OUT_EP, outputIsocDataBuffer, sizeof(outputIsocDataBuffer));
            if (iLen > 0) {
                //Insert your code to do somthing interesting here....
                //DBG("z%d", b1);

                //The host sample code will send a byte indicating if the BLUE LED should be on of off.
                if( outputIsocDataBuffer[0] ) {
                    // BLUE_LED_ON
                } else {
                    BLUE_LED_OFF;
                }

            }
        }
    } else {
        RED_LED_ON;
    }
}
void USBFrameHandler(U16 wFrame)
{
    // send over USB
	if( isConnectedFlag ) {
		if( delay < 4000 ) {
			delay++;
		} else {
			USBHwEPWrite(ISOC_IN_EP, inputIsocDataBuffer, BYTES_PER_ISOC_FRAME);
				
			
			
			int iLen = USBHwISOCEPRead(ISOC_OUT_EP, outputIsocDataBuffer, sizeof(outputIsocDataBuffer));
			if (iLen > 0) {
				//FIXME parse data and control somthing
				
				U8 b1 = outputIsocDataBuffer[0];
				if( b1 ) {
					IOSET0 |= (1<<10);
				} else {
					IOCLR0 |= (1<<10);
				}
				DBG("z%d", b1);
			}
			
		}
	}
}
Exemple #11
0
int dequeue_send(u32 clkn)
{
	usb_pkt_rx *pkt = dequeue(&pkt);
	if (pkt != NULL) {
		last_usb_pkt = clkn;
		USBHwEPWrite(BULK_IN_EP, (u8 *)pkt, sizeof(usb_pkt_rx));
		return 1;
	} else {
		if (clkn - last_usb_pkt > USB_KEEP_ALIVE) {
			u8 pkt_type = KEEP_ALIVE;
			last_usb_pkt = clkn;
			USBHwEPWrite(BULK_IN_EP, &pkt_type, 1);
		}
		return 0;
	}
}
Exemple #12
0
/*
	Local function to handle outgoing bulk data
	@param [in] bEP
	@param [in] bEPStatus
*/
void BulkIn(uint8_t bEP, uint8_t bEPStatus)
{
	if(usbSendBufferSize > 0)
	{
		USBHwEPWrite(bEP, usbSendBuffer, usbSendBufferSize);
		deleteBulkInBuf();
	}
}
/**
	Sends next chunk of data (possibly 0 bytes) to host
 */
static void DataIn(void)
{
	int iChunk;

	iChunk = MIN(MAX_PACKET_SIZE0, iResidue);
	USBHwEPWrite(0x80, pbData, iChunk);
	pbData += iChunk;
	iResidue -= iChunk;
}
static void HandleFrame(U16 wFrame)
{
	static int iCount;
	_iFrame++;
	if ((_iFrame > 1000)) {
		// send report (dummy data)
		abReport[0] = (iCount >> 8) & 0xFF;
		abReport[1] = (iCount) & 0xFF;
		iCount++;
		USBHwEPWrite(INTR_IN_EP, abReport, REPORT_SIZE);
		_iFrame = 0;
	}
Exemple #15
0
/**
	Sends next chunk of data (possibly 0 bytes) to host
 */
static void DataIn(void)
{
    int iChunk;

    if( MAX_PACKET_SIZE0 < iResidue ) {
        iChunk = MAX_PACKET_SIZE0;
    } else {
        iChunk = iResidue;
    }

    USBHwEPWrite(0x80, pbData, iChunk);
    pbData += iChunk;
    iResidue -= iChunk;
}
Exemple #16
0
/**
	Sends the next packet in chain of packets to the host
		
	@param [in] bEP
	@param [in] bEPStatus
 */
static void SendNextBulkIn(U8 bEP, BOOL fFirstPacket)
{
	int iLen;

	// this transfer is done
	/*
	fBulkInBusy = FALSE;
	
	// first packet?
	if (fFirstPacket) {
		fChainDone = FALSE;
	}
	*/

	// last packet?
	/*
	if (fChainDone) {
		return;
	}
	*/
	
	// get up to MAX_PACKET_SIZE bytes from transmit FIFO into intermediate buffer
	for (iLen = 0; iLen < MAX_PACKET_SIZE_BULK; iLen++) {
		if (!fifo_get(&bulk_txfifo, &bulkBuf[iLen])) {
			break;
		}
	}
	
	
	// send over USB
	DBG("Ba %d ", iLen);
	USBHwEPWrite(bEP, bulkBuf, iLen);
	DBG("Bb");
	
	//fBulkInBusy = TRUE;

	// was this a short packet?
	/*if (iLen < MAX_PACKET_SIZE_BULK) {
		fChainDone = TRUE;
	}
	*/
}