Example #1
0
/*
 *  usb_test()
 *    USB Bulk transfer test. Device is detected as an eZDSP5535 when
 *    connected to PC while test is running. Bulk transfers can be
 *    made using USB_55xx program.
 *
 */
CSL_Status usb_test(void)
{
	CSL_IRQ_Config    config;
	CSL_Status        result;
	Uint16            eventMask;

	result = CSL_USB_TEST_FAILED;

	usbConfig.opMode             = CSL_USB_OPMODE_POLLED;
    usbConfig.devNum             = CSL_USB0;
	usbConfig.maxCurrent         = CSL_USB_MAX_CURRENT;
	usbConfig.appSuspendCallBack = (CSL_USB_APP_CALLBACK)CSL_suspendCallBack;
	usbConfig.appWakeupCallBack  = (CSL_USB_APP_CALLBACK)CSL_selfWakeupCallBack;
	usbConfig.startTransferCallback  = CSL_startTransferCallback;
	usbConfig.completeTransferCallback = CSL_completeTransferCallback;

	hEpObjArray[0] = &usbCtrlOutEpObj;
	hEpObjArray[1] = &usbCtrlInEpObj;
	hEpObjArray[2] = &usbBulkOutEpObj;
	hEpObjArray[3] = &usbBulkInEpObj;

	/* Set the interrupt vector start address */
	IRQ_setVecs((Uint32)(&VECSTART));

	/* Plug the USB Isr into vector table */
	config.funcAddr = &usb_isr;
	IRQ_plug(USB_EVENT, config.funcAddr);

	/* Enable USB Interrupts */
	IRQ_enable(USB_EVENT);
	/* Enable CPU Interrupts */
	IRQ_globalEnable();

	/* Initialize the USB module */
	status = USB_init(&usbConfig);
	if(status != CSL_SOK)
	{
		printf("USB init failed\n");
		return(result);
	}

	/* Reset the USB device */
	status = USB_resetDev(CSL_USB0);
	if(status != CSL_SOK)
	{
		printf("USB Reset failed\n");
		return(result);
	}

	/* Initialize the Control Endpoint OUT 0 */
	eventMask = (CSL_USB_EVENT_RESET | CSL_USB_EVENT_SETUP |
				 CSL_USB_EVENT_SUSPEND | CSL_USB_EVENT_RESUME |
				 CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT);

	status = USB_initEndptObj(CSL_USB0, hEpObjArray[0],
	                          CSL_USB_OUT_EP0,CSL_USB_CTRL,
					          CSL_USB_EP0_PACKET_SIZE, eventMask, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Control Endpoint IN 0 */
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[1], CSL_USB_IN_EP0,
	                          CSL_USB_CTRL, CSL_USB_EP0_PACKET_SIZE,
	                          CSL_USB_EVENT_EOT, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Bulk Endpoint IN 1 */
	eventMask = (CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT);
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[2], CSL_USB_IN_EP1,
	                          CSL_USB_BULK, CSL_USB_EP1_PACKET_SIZE_FS,
	                          eventMask, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Bulk Endpoint OUT 2 */
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[3], CSL_USB_OUT_EP1,
	                          CSL_USB_BULK, CSL_USB_EP1_PACKET_SIZE_FS,
	                          CSL_USB_EVENT_EOT, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Set the parameters */
	status = USB_setParams(CSL_USB0, hEpObjArray, FALSE);
	if(status != CSL_SOK)
	{
		printf("USB Set params failed\n");
		return(result);
	}

	/* Connect the USB device */
	status = USB_connectDev(CSL_USB0);
	if(status != CSL_SOK)
	{
		printf("USB Connect failed\n");
		return(result);
	}

	deviceDescPtr = (Uint16 *)deviceDesc;
	cfgDescPtr    = (Uint16 *)cfgDesc;
	strDescPtr    = (Uint16 *)strDesc;
	dataReadBuffPtr  = (Uint16 *)dataReadBuff;
	dataWriteBuffPtr = (Uint16 *)dataWriteBuff;
	
	while(stopRunning != TRUE);

	result = CSL_USB_TEST_PASSED;
	return(result);
}
/**
 *  \brief  Audio Class intialization function
 *
 *  \param  None
 *
 *  \return None
 */
void CSL_acTest(void)
{
    I2sInitPrms i2sInitPrms;
    CSL_UsbConfig usbConfig;
    PSP_Result result;
    Int16 status;
    HWI_Attrs attrs;


    LOG_printf(&trace, "USB ISO FULL SPEED MODE\n");

    /* Initialize audio module */
    result = AIC3254_init();
    if(result != 0)
    {
        LOG_printf(&trace, "ERROR: Unable to configure audio codec");
    }
    else
    {
#if !defined(SAMPLE_BY_SAMPLE_PB) || !defined(SAMPLE_BY_SAMPLE_REC)
        DMA_HwInit();
        DMA_DrvInit();
#endif

        /* Initialize I2S and associated DMA channels for Playback and Record */
        i2sInitPrms.enablePlayback = TRUE;
        i2sInitPrms.enableStereoPb = TRUE;
#ifdef SAMPLE_BY_SAMPLE_PB
        i2sInitPrms.sampleBySamplePb = TRUE;
#else /* Configuration untested since ASRC only works with I2S in sample-by-sample mode */
        i2sInitPrms.sampleBySamplePb = FALSE;
        i2sInitPrms.enableDmaPingPongPb = FALSE;
        i2sInitPrms.pingI2sTxLeftBuf = ping_i2sTxLeftBuf;
        i2sInitPrms.pongI2sTxLeftBuf = pong_i2sTxLeftBuf;
        i2sInitPrms.pingI2sTxRightBuf = ping_i2sTxRightBuf;
        i2sInitPrms.pongI2sTxRightBuf = pong_i2sTxRightBuf;
        i2sInitPrms.zeroBuf = ZeroBuf;
#endif
        i2sInitPrms.i2sPb = PSP_I2S_TX_INST_ID;
        i2sInitPrms.enableRecord = TRUE;
        i2sInitPrms.enableStereoRec = FALSE;
#ifdef SAMPLE_BY_SAMPLE_REC
        i2sInitPrms.sampleBySampleRec = TRUE;
#else
        i2sInitPrms.sampleBySampleRec = FALSE;
        i2sInitPrms.enableDmaPingPongRec = TRUE;
        i2sInitPrms.pingI2sRxLeftBuf = (Int16 *)ping_pong_i2sRxLeftBuf;
        i2sInitPrms.pongI2sRxLeftBuf = NULL;
        i2sInitPrms.pingI2sRxRightBuf = (Int16 *)ping_pong_i2sRxRightBuf;
        i2sInitPrms.pongI2sRxRightBuf = NULL;
#endif
        i2sInitPrms.i2sRec = PSP_I2S_RX_INST_ID;
        status = i2sInit(&i2sInitPrms);
        if (status != I2SSAMPLE_SOK)
        {
            LOG_printf(&trace, "ERROR: Unable to initialize I2S");
        }

#ifdef C5535_EZDSP_DEMO
		// initialize the OLED display        
        oled_init();
#endif
        
        /* Initialising the Pointer to the Audio Class Handle to the Buffer Allocated */
        AC_AppHandle.pAcObj = &ACAppBuffer[0];

        usbConfig.devNum                = CSL_USB0;
        usbConfig.opMode                = CSL_USB_OPMODE_POLLED;
#ifdef APP_USB_SELF_POWERED
        usbConfig.selfPowered           = TRUE;
#else
        usbConfig.selfPowered           = FALSE;
#endif
        usbConfig.maxCurrent            = APP_USB_MAX_CURRENT;
        usbConfig.appSuspendCallBack    = (CSL_USB_APP_CALLBACK)CSL_suspendCallBack;
        usbConfig.appWakeupCallBack     = (CSL_USB_APP_CALLBACK)CSL_selfWakeupCallBack;
        usbConfig.startTransferCallback  = StartTransfer;
        usbConfig.completeTransferCallback = CompleteTransfer;

        USB_init(&usbConfig);

        USB_setFullSpeedMode(0x40); /* parameter is EP0 data size in bytes */

        USB_resetDev(CSL_USB0);

        /* Calling init routine */
        /* Giving all the table hanldes and the buffers to the Audio Class module */
        AC_AppHandle.strDescrApp = (char **)&string_descriptor[0];
        AC_AppHandle.lbaBufferPbApp = &lbaBufferPbApp[0];
        AC_AppHandle.lbaBufferRecApp = &lbaBufferRecApp[0];
        AC_AppHandle.lbaBufferHidReportApp = &lbaBufferHidReportApp[0];
        AC_AppHandle.acReqTableApp = USB_ReqTable;
        AC_AppHandle.pId = pId;
        AC_AppHandle.vId = vId;

#ifndef ENABLE_PLAYBACK_TWO_SAMPLE_RATES
        #ifdef SAMPLE_RATE_TX_48kHz
        LOG_printf(&trace, "PLAYBACK: 48KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = EP_PB_MAXP; // max packet size for 48K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x60; // max packet size for 48K mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_48kHz

        #ifdef SAMPLE_RATE_TX_44_1kHz
        LOG_printf(&trace, "PLAYBACK: 44.1KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = 0xB0; // max packet size for 44.1 stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x58; // max packet size for 44.1 mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_44_1kHz

        #ifdef SAMPLE_RATE_TX_32kHz
        LOG_printf(&trace, "PLAYBACK: 32KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = 0x80; // max packet size for 32K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x40; // max packet size for 32K mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_32kHz

        #ifdef SAMPLE_RATE_TX_16kHz
        LOG_printf(&trace, "PLAYBACK: 16KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = RX_PKT_SIZE_16K_PLAYBACK_STEREO; // max packet size for 16K stereo
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_STEREO; // max packet size for 16K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = RX_PKT_SIZE_16K_PLAYBACK_MONO; // max packet size for 16K mono
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_MONO;  // max packet size for 16K mono
        #endif // ENABLE_STEREO_PLAYBACK
        #endif // SAMPLE_RATE_TX_16kHz

#else /* ENABLE_PLAYBACK_TWO_SAMPLE_RATES */
        LOG_printf(&trace, "PLAYBACK: 48KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "STEREO\n");
        AC_AppHandle.rxPktSize = EP_PB_MAXP; // max packet size for 48K stereo
        #else // ENABLE_STEREO_PLAYBACK
        LOG_printf(&trace, "MONO\n");
        AC_AppHandle.rxPktSize = 0x60; // max packet size for 48K mono
        #endif // ENABLE_STEREO_PLAYBACK

        LOG_printf(&trace, "PLAYBACK: 16KHZ ");
        #ifdef ENABLE_STEREO_PLAYBACK
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_STEREO; // max packet size for 16K stereo
        LOG_printf(&trace, "STEREO\n");
        #else // ENABLE_STEREO_PLAYBACK
        rx_pkt_size_16K_playback = RX_PKT_SIZE_16K_PLAYBACK_MONO;  // max packet size for 16K mono
        LOG_printf(&trace, "MONO\n");
        #endif // ENABLE_STEREO_PLAYBACK
#endif /* ENABLE_PLAYBACK_TWO_SAMPLE_RATES */

        AC_AppHandle.txPktSize = EP_REC_MAXP; // max packet size for 16K mono
        AC_AppHandle.hidTxPktSize = EP_HID_MAXP; // max packet size for HID output report

        /* All Function Handlers need to be Initialised */
        AC_AppHandle.playAudioApp = appPlayAudio;
        AC_AppHandle.recordAudioApp = appRecordAudio;
        AC_AppHandle.initPlayAudioApp = appInitPlayAudio;
        AC_AppHandle.initRecordAudioApp = appInitRecordAudio;
        AC_AppHandle.stopPlayAudioApp = appStopPlayAudio;
        AC_AppHandle.stopRecordAudioApp = appStopRecordAudio;
        AC_AppHandle.mediaGetPresentStateApp = AppGetMediaStatus;
        AC_AppHandle.mediaInitApp = AppMediaInit;
        AC_AppHandle.mediaEjectApp = AppMediaEject;
        AC_AppHandle.mediaLockUnitApp = AppLockMedia;
        AC_AppHandle.getMediaSizeApp = AppGetMediaSize;
        AC_AppHandle.getHidReportApp = appGetHidReport;
        AC_AppHandle.ctrlHandler  = appCtrlFxn;
        AC_AppHandle.isoHandler   = appIsoFxn;
        AC_AppHandle.hidHandler = appHidFxn;

        AC_AppHandle.numLun = 2;

        /* Initialize End point descriptors */
        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)deviceDescriptorB,
                            CSL_AC_DEVICE_DESCR, sizeof(deviceDescriptorB));

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)deviceQualifierDescr,
                            CSL_AC_DEVICE_QUAL_DESCR, 10);

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)configDescriptor,
                            CSL_AC_CONFIG_DESCR, sizeof(configDescriptor));

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)stringLanId,
                            CSL_AC_STRING_LANGID_DESC, 6);

        AC_initDescriptors(AC_AppHandle.pAcObj, (Uint16 *)acHidReportDescriptor,
                            CSL_AC_HID_REPORT_DESC, sizeof(acHidReportDescriptor));

        /* Initialize HID */
        AC_AppHandle.acHidIfNum = IF_NUM_HID; // HID interface number
        AC_AppHandle.acHidReportId = HID_REPORT_ID; // HID report ID
        AC_AppHandle.acHidReportLen = HID_REPORT_SIZE_BYTES; // HID report length (bytes)
        genHidReport(UI_PUSH_BUTTON_NONE, gHidReport); // init. HID report for Get Report 

        /* Call Init API */
        AC_Open(&AC_AppHandle);

        /* Enable CPU USB interrupts */
        CSL_FINST(CSL_CPU_REGS->IER1, CPU_IER1_USB, ENABLE);

        /* Initialize active sample rate */
        initSampleRate(RATE_48_KHZ, &active_sample_rate, 
            &i2sTxBuffSz);

        /* Initialize ASRC */ 
        Init_Sample_Rate_Converter(active_sample_rate);

        /* Reset codec output buffer */
        reset_codec_output_buffer();

        #ifdef ENABLE_RECORD
        #ifdef SAMPLE_RATE_RX_48kHz
        LOG_printf(&trace, "RECORD: 48KHZ ");
        #else
        LOG_printf(&trace, "RECORD: 16KHZ ");
        #endif // SAMPLE_RATE_RX_48kHz
        // start the rx DMAs
        DMA_StartTransfer(hDmaRxLeft);

        #ifdef ENABLE_STEREO_RECORD
        LOG_printf(&trace, "STEREO  NOT SUPPORTED - RECORD WILL BE MONO\n");
        DMA_StartTransfer(hDmaRxRight);
         #else
        LOG_printf(&trace, "MONO\n");
        #endif

        #endif // ENABLE_RECORD

#ifdef STORE_PARAMETERS_TO_SDRAM
        initSdram(FALSE, 0x0000);
#endif // STORE_PARAMETERS_TO_SDRAM
#ifdef SAMPLE_BY_SAMPLE_PB
        /* SampleBySample, init interrupt */       
        /* Use with compiler "interrupt" keyword */
        //IRQ_plug(I2S_TX_EVENT, i2s_txIsr);
        
        /* Use with dispatcher, no "interrupt" keyword */
        attrs.ier0mask = 0xFFFF;
        attrs.ier1mask = 0xFFFF;
        HWI_dispatchPlug(I2S_TX_EVENT, (Fxn)i2s_txIsr, &attrs);

        IRQ_enable(I2S_TX_EVENT);   /* SampleBySample, enable IRQ for I2S Tx */
#endif
#if defined(SAMPLE_BY_SAMPLE_REC) && !defined(COMBINE_I2S_TX_RX_ISR)
        /* SampleBySample, init interrupt */
        /* Use with compiler "interrupt" keyword */
        IRQ_plug(I2S_RX_EVENT, i2s_rxIsr);
        
        /* Use with dispatcher, no "interrupt" keyword */
        //attrs.ier0mask = 0xFFFF;
        //attrs.ier1mask = 0xFFFF;
        //HWI_dispatchPlug(I2S_RX_EVENT, (Fxn)i2s_rxIsr, &attrs);

        IRQ_enable(I2S_RX_EVENT);    /* SampleBySample, enable IRQ for I2S Rx */
#endif
#if defined(SAMPLE_BY_SAMPLE_PB) || defined(SAMPLE_BY_SAMLE_REC)
        DDC_I2S_transEnable((DDC_I2SHandle)i2sHandleTx, TRUE);    /* SampleBySample, enable I2S transmit and receive */
#endif
#ifndef SAMPLE_BY_SAMPLE_PB
        i2sTxStart(); // - moved from appPlayAudio()
#endif

#ifdef C5535_EZDSP_DEMO
        // clock gating usused peripherals
		ClockGating();
#endif
    }
}
CSL_Status CSL_usbPollTest(void)
{
	CSL_Status        status;
	CSL_Status        result;
	pUsbContext       pContext;
	pUsbEpHandle      hEPx;
	CSL_UsbBoolean    txRxStatus;
	Uint16            bytesRem;
	Uint16            eventMask;
	Uint16            saveIndex;
	Uint16            endpt;
	pUsbEpHandle tempEpH;

	pContext = &gUsbContext;
	result   = CSL_USB_TEST_FAILED;

	usbConfig.opMode             = CSL_USB_OPMODE_POLLED;
    usbConfig.devNum             = CSL_USB0;
	usbConfig.maxCurrent         = CSL_USB_MAX_CURRENT;
	usbConfig.appSuspendCallBack = (CSL_USB_APP_CALLBACK)CSL_suspendCallBack;
	usbConfig.appWakeupCallBack  = (CSL_USB_APP_CALLBACK)CSL_selfWakeupCallBack;
	usbConfig.startTransferCallback  = CSL_startTransferCallback;
	usbConfig.completeTransferCallback = CSL_completeTransferCallback;

	hEpObjArray[0] = &usbCtrlOutEpObj;
	hEpObjArray[1] = &usbCtrlInEpObj;
	hEpObjArray[2] = &usbBulkOutEpObj;
	hEpObjArray[3] = &usbBulkInEpObj;

#ifdef CSL_USB_SELFWAKEUP_TEST

	/* Configure SAR to generate event for self wakeup */
	/* NOTE: Self Wakeup is interfaced to the STOP key of the EVM keypad */
	status = CSL_configSarForSelfWakeup();
	if(status != CSL_SOK)
	{
		printf("SAR Configuration failed\n");
		return(result);
	}

#endif  // CSL_USB_SELFWAKEUP_TEST

	/* Initialize the USB module */
	status = USB_init(&usbConfig);
	if(status != CSL_SOK)
	{
		printf("USB init failed\n");
		return(result);
	}

	/* Reset the USB device */
	status = USB_resetDev(CSL_USB0);
	if(status != CSL_SOK)
	{
		printf("USB Reset failed\n");
		return(result);
	}

	/* Initialized the Control Endpoint OUT 0 */
	eventMask = (CSL_USB_EVENT_RESET | CSL_USB_EVENT_SETUP |
				 CSL_USB_EVENT_SUSPEND | CSL_USB_EVENT_RESUME |
				 CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT);

	status = USB_initEndptObj(CSL_USB0, hEpObjArray[0],
	                          CSL_USB_OUT_EP0,CSL_USB_CTRL,
					          CSL_USB_EP0_PACKET_SIZE, eventMask, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialized the Control Endpoint IN 0 */
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[1], CSL_USB_IN_EP0,
	                          CSL_USB_CTRL, CSL_USB_EP0_PACKET_SIZE,
	                          CSL_USB_EVENT_EOT, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Bulk Endpoint IN 1 */
	eventMask = (CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT);
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[2], CSL_USB_IN_EP1,
	                          CSL_USB_BULK, CSL_USB_EP1_PACKET_SIZE_FS,
	                          eventMask, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Initialize the Bulk Endpoint OUT 2 */
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[3], CSL_USB_OUT_EP2,
	                          CSL_USB_BULK, CSL_USB_EP2_PACKET_SIZE_FS,
	                          CSL_USB_EVENT_EOT, NULL);
	if(status != CSL_SOK)
	{
		printf("USB End point init failed\n");
		return(result);
	}

	/* Set the parameters */
	status = USB_setParams(CSL_USB0, hEpObjArray, FALSE);
	if(status != CSL_SOK)
	{
		printf("USB Set params failed\n");
		return(result);
	}

	/* Connect the USB device */
	status = USB_connectDev(CSL_USB0);
	if(status != CSL_SOK)
	{
		printf("USB Connect failed\n");
		return(result);
	}

	deviceDescPtr = (Uint16 *)deviceDesc;
	cfgDescPtr    = (Uint16 *)cfgDesc;
	strDescPtr    = (Uint16 *)strDesc;
	selfWakeupServiced = TRUE;

	while(stopRunning != TRUE)
	{
    	/* Read the masked interrupt status register */
		pContext->dwIntSourceL = usbRegisters->INTMASKEDR1;
		pContext->dwIntSourceH = usbRegisters->INTMASKEDR2;

		/* Clear the interrupts */
		if(pContext->dwIntSourceL != FALSE)
		{
			usbRegisters->INTCLRR1 = pContext->dwIntSourceL;
		}

		if(pContext->dwIntSourceH != FALSE)
		{
			usbRegisters->INTCLRR2 = pContext->dwIntSourceH;
		}

		/* Reset interrupt */
		if(pContext->dwIntSourceH & CSL_USB_GBL_INT_RESET)
		{
			usbRegisters->INDEX_TESTMODE = usbRegisters->INDEX_TESTMODE & 0x00ff;

			if(usbBulkOutEpObj.epNum == CSL_USB_IN_EP1)
			{
				CSL_FINS(usbRegisters->INDEX_TESTMODE,
						 USB_INDEX_TESTMODE_EPSEL, CSL_USB_EP1);
				CSL_FINS(usbRegisters->PERI_CSR0_INDX,
				         USB_PERI_CSR0_INDX_RXPKTRDY, TRUE);
			}
			else
			{
				CSL_FINS(usbRegisters->INDEX_TESTMODE,
						 USB_INDEX_TESTMODE_EPSEL, CSL_USB_EP2);
				CSL_FINS(usbRegisters->PERI_CSR0_INDX,
				         USB_PERI_CSR0_INDX_RXPKTRDY, TRUE);
			}
		}

		/* Resume interrupt */
		if(pContext->dwIntSourceH & CSL_USB_GBL_INT_RESUME)
		{
			USB_setRemoteWakeup(CSL_USB0, CSL_USB_TRUE);
			status = USB_issueRemoteWakeup(CSL_USB0, TRUE);
			/* Give 10 msecs delay before resetting resume bit */
			USB_delay(CSL_USB_WAKEUP_DELAY);
			status = USB_issueRemoteWakeup(CSL_USB0, FALSE);
			if(status != CSL_SOK)
			{
				printf("USB Resume failed\n");
   /////INSTRUMENTATION FOR BATCH TESTING -- Part 2 --   
   /////  Reseting PaSs_StAtE to 0 if error detected here.
        PaSs_StAtE = 0x0000; // Was intialized to 1 at declaration.
   /////
			}
		}

		/* Check End point0 interrupts */
		if(pContext->dwIntSourceL & CSL_USB_TX_RX_INT_EP0)
		{
			saveIndex = usbRegisters->INDEX_TESTMODE;
				CSL_FINS(usbRegisters->INDEX_TESTMODE,
						 USB_INDEX_TESTMODE_EPSEL, CSL_USB_EP0);

			USB_getSetupPacket(CSL_USB0, &usbSetup, TRUE);

			if((usbRegisters->PERI_CSR0_INDX & CSL_USB_PERI_CSR0_INDX_RXPKTRDY_MASK)
					== CSL_USB_PERI_CSR0_INDX_RXPKTRDY_MASK)
			{
				/* Service the RXPKTRDY after reading the FIFO */
				CSL_FINS(usbRegisters->PERI_CSR0_INDX,
				         USB_PERI_CSR0_INDX_SERV_RXPKTRDY, TRUE);

				/* GET DESCRIPTOR Req */
				switch(usbSetup.bRequest)
				{
					/* zero data */
					case CSL_USB_SET_FEATURE:
						switch(usbSetup.wValue)
						{
							case CSL_USB_FEATURE_ENDPOINT_STALL:
								/* updated set and clear endpoint stall
								 * to work with logical endpoint num
								 */
								endpt = (usbSetup.wIndex) & 0xFF;
								hEPx = USB_epNumToHandle(CSL_USB0, endpt);
								if(!(USB_getEndptStall(hEPx, &status)))
								{
									USB_stallEndpt(hEPx);
								}
								break;

							case CSL_USB_FEATURE_REMOTE_WAKEUP:
								if(!(USB_getRemoteWakeupStat(CSL_USB0)))
								{
									USB_setRemoteWakeup(CSL_USB0, CSL_USB_TRUE);
								}
								break;

							default:
								break;
						}

						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_SERV_RXPKTRDY, TRUE);
						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_DATAEND, TRUE);
						break;

					case CSL_USB_CLEAR_FEATURE:
						switch(usbSetup.wValue)
						{
							case CSL_USB_FEATURE_ENDPOINT_STALL:
								endpt = (usbSetup.wIndex) & 0xFF;
								hEPx = USB_epNumToHandle(CSL_USB0, endpt);
								if(USB_getEndptStall(hEPx, &status))
								{
									USB_clearEndptStall(hEPx);
								}
								break;

							case CSL_USB_FEATURE_REMOTE_WAKEUP:
								if(USB_getRemoteWakeupStat(CSL_USB0))
								{
									USB_setRemoteWakeup(CSL_USB0,
									                    CSL_USB_FALSE);
								}
								break;

							default:
								 break;
						}
						break;

					case CSL_USB_SET_CONFIGURATION :
					case CSL_USB_SET_INTERFACE:
						endpt = (usbSetup.wIndex) & 0xFF;
						hEPx = USB_epNumToHandle(CSL_USB0, endpt);
						USB_postTransaction(hEPx, 0, NULL,
						                    CSL_USB_IOFLAG_NONE);

						/* DataEnd + ServicedRxPktRdy */
						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_SERV_RXPKTRDY, TRUE);
						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_DATAEND, TRUE);

						break;

					case CSL_USB_GET_DESCRIPTOR :

						switch(usbSetup.wValue >> 8)
						{
							case CSL_USB_DEVICE_DESCRIPTOR_TYPE:
								deviceDescPtr = (Uint16 *)deviceDesc;
								status = USB_postTransaction(hEpObjArray[1],
								                 deviceDesc[0]&0xFF, deviceDescPtr,
								                 CSL_USB_IN_TRANSFER);
								break;

							case CSL_USB_CONFIGURATION_DESCRIPTOR_TYPE:
								if(usbSetup.wLength == 0x0009)
								{
									cfgDescPtr = cfgDesc;
									status = USB_postTransaction(hEpObjArray[1],
									                 9, cfgDescPtr,
									                 CSL_USB_IN_TRANSFER);
								}
								else
								{
									cfgDescPtr = cfgDesc;
									status = USB_postTransaction(hEpObjArray[1],
									                 cfgDesc[1], cfgDescPtr,
									                 CSL_USB_IN_TRANSFER);
								}

								break;

							case CSL_USB_STRING_DESCRIPTOR_TYPE:
								if((usbSetup.wValue & 0xFF) == 0x00)
								{
									strDescPtr = (Uint16 *)strDesc[0];
									status = USB_postTransaction(hEpObjArray[1],
									                 strDesc[0][0]&0xFF, strDescPtr,
									                 CSL_USB_IN_TRANSFER);
								}
								if((usbSetup.wValue & 0xFF) == 0x01)
								{
									strDescPtr = (Uint16 *)strDesc[1];
									status = USB_postTransaction(hEpObjArray[1],
									                 strDesc[1][0]&0xFF, strDescPtr,
									                 CSL_USB_IN_TRANSFER);
								}
								if((usbSetup.wValue & 0xFF) == 0x02)
								{
									strDescPtr = (Uint16 *)strDesc[2];
									status = USB_postTransaction(hEpObjArray[1],
									                 strDesc[2][0]&0xFF, strDescPtr,
									                 CSL_USB_IN_TRANSFER);
								}
								if((usbSetup.wValue & 0xFF) == 0x03)
								{
									strDescPtr = (Uint16 *)strDesc[3];
									status = USB_postTransaction(hEpObjArray[1],
									                 strDesc[3][0]&0xFF, strDescPtr,
									                 CSL_USB_IN_TRANSFER);
								}
								break;

							default:
								break;
						}

						deviceDescPtr = (Uint16 *)deviceDesc;
						cfgDescPtr    = (Uint16 *)cfgDesc;
						strDescPtr    = (Uint16 *)strDesc[0];

						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_TXPKTRDY, TRUE);
						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_DATAEND, TRUE);
						break;

					case CSL_USB_SET_ADDRESS :
						devAddr = usbSetup.wValue;
						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_SERV_RXPKTRDY, TRUE);
						CSL_FINS(usbRegisters->PERI_CSR0_INDX,
						         USB_PERI_CSR0_INDX_DATAEND, TRUE);
						break;

					default:
						break;
				}
			}
			else
			{
				if(usbSetup.bRequest == 0x05)
Example #4
0
/**
 *  \brief  Tests USB interrupt mode operation
 *
 *  \param  none
 *
 *  \return Test result
 */
Int16 BoardUSB_init(void)
{
	Uint16 eventMask;
	Int16 looper;
	CSL_UsbConfig usbConfig;

	usbConfig.opMode             = CSL_USB_OPMODE_POLLED;
    usbConfig.devNum             = CSL_USB0;
	usbConfig.maxCurrent         = CSL_USB_MAX_CURRENT;
	usbConfig.appSuspendCallBack = (CSL_USB_APP_CALLBACK)NULL;
	usbConfig.appWakeupCallBack  = (CSL_USB_APP_CALLBACK)NULL;
	usbConfig.startTransferCallback  = CSL_startTransferCallback;
	usbConfig.completeTransferCallback = NULL;

	hEpObjArray[0] = &usbCtrlOutEpObj;
	hEpObjArray[1] = &usbCtrlInEpObj;
	hEpObjArray[2] = &usbBulkOutEpObj;
	hEpObjArray[3] = &usbBulkInEpObj;

	CSL_CPU_REGS->IER1 |= 0x0010;		// enable USB interrupt

	/* Initialize the USB module */
	status = USB_init(&usbConfig);	// never fail

	/* Reset the USB device */
	status = USB_resetDev(CSL_USB0);	// never fail when CSL_USB0

	/* Initialize the Control Endpoint OUT 0 */
	eventMask = CSL_USB_EVENT_RESET |
				CSL_USB_EVENT_SETUP |
				CSL_USB_EVENT_SUSPEND |
				CSL_USB_EVENT_RESUME |
				CSL_USB_EVENT_EOT;

	status = USB_initEndptObj(CSL_USB0, hEpObjArray[0], CSL_USB_OUT_EP0,
							  CSL_USB_CTRL, CSL_USB_EP0_PACKET_SIZE,
							  eventMask, NULL);
	if(status != CSL_SOK)	// USB End point init failed
		return status;

	/* Initialize the Control Endpoint IN 0 */
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[1], CSL_USB_IN_EP0,
							  CSL_USB_CTRL, CSL_USB_EP0_PACKET_SIZE,
							  CSL_USB_EVENT_EOT, NULL);
	if(status != CSL_SOK)	// USB End point init failed
		return status;

	/* Initialize the Bulk Endpoint IN 1 */
	eventMask = CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT;
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[2], CSL_USB_IN_EP1,
							  CSL_USB_BULK, CSL_USB_EP1_PACKET_SIZE_HS,
							  eventMask, NULL);
	if(status != CSL_SOK)	// USB End point init failed
		return status;

	/* Initialize the Bulk Endpoint OUT 2 */
	eventMask = CSL_USB_EVENT_RESET | CSL_USB_EVENT_EOT;
	status = USB_initEndptObj(CSL_USB0, hEpObjArray[3], CSL_USB_OUT_EP2,
							  CSL_USB_BULK, CSL_USB_EP2_PACKET_SIZE_HS,
							  eventMask, NULL);
	if(status != CSL_SOK)	//  USB End point init failed
		return status;

	/* Set the parameters */
	USB_setParams(CSL_USB0, hEpObjArray, TRUE);
/*
	for(looper = 0; looper < CSL_USB_ENDPOINT_COUNT; looper++) {
		gUsbEpHandle[looper] = hEpObjArray[looper];
		if(hEpObjArray[looper] == NULL)
			break;
	}
*/

	/* Connect the USB device */
	CSL_FINS(usbRegisters->FADDR_POWER, USB_FADDR_POWER_SOFTCONN, TRUE);

	return CSL_SOK;
}