Example #1
0
void vUSBTask(void *pvParameters)
{
	uint16 usbsize;
	uint8 usbbuf[256];
	//uint8 usbbufsizes[100];
	CONTENTS stru[100];
	uint16 usbbufsizesCounter=0;
	bool st = false;
	/* The parameters are not used. */
	(void) pvParameters;
/*
	uint16_t bufff[20];
	bufff[0] = 0x555;
	bufff[1] = 0x444;
	bufff[2] = 0x333;
	bufff[3] = 0x222;
	bufff[4] = 0x111;

	FLASH_ErasePage(DEVICE_FLASHMEM_LOCATION);
	//FLASH_ProgramHalfWord(DEVICE_FLASHMEM_LOCATION,bufff[0]);

	//FLASH_ProgramHalfWord(DEVICE_FLASHMEM_LOCATION+0x02,bufff[1]);
	//FLASH_ProgramHalfWord(DEVICE_FLASHMEM_LOCATION+0x04,bufff[2]);
	//FLASH_ProgramHalfWord(DEVICE_FLASHMEM_LOCATION+0x06,bufff[3]);
	//FLASH_ProgramHalfWord(DEVICE_FLASHMEM_LOCATION+0x08,bufff[4]);
	WriteFlash( bufff,(void*)(DEVICE_FLASHMEM_LOCATION),  10);*/
	//vTaskDelay(15000);
	  Set_USBClock();
	  USB_Interrupts_Config();
	  USB_Init();
int heapSize = 0;
	  while (1)
	  {
			heapSize = xPortGetFreeHeapSize();
							heapSize +=0;
		  usbsize = UsbReceiveData(usbbuf,256);

		  if(usbsize > 0)
		  {

			  stru[usbbufsizesCounter].buf[0]=usbbuf[0];
			  stru[usbbufsizesCounter].buf[1]=usbbuf[1];
			  stru[usbbufsizesCounter].buf[2]=usbbuf[2];
			  stru[usbbufsizesCounter].buf[3]=usbbuf[3];
			  stru[usbbufsizesCounter].size = usbsize;
			  usbbufsizesCounter++;
			  if(usbbufsizesCounter>=100) usbbufsizesCounter = 0;
			  usbsize = RVnetSlaveProcess(usbbuf,usbsize,1);
			  if(usbsize > 0)
			  {
				  UsbSendData(usbbuf,usbsize);
			  }
		  }
		  vTaskDelay(1);
	  }
}
Example #2
0
int USBDevice::Disconnect()
{
    // Disconnect from the target device
    if (dev!=NULL)
    {
        // Issue disconnect command, ignore errors
        UsbSendData(dev, 2, NULL, 0, NULL, 0);
        UsbCloseDevice(dev);
    }

    dev = NULL;
    return 0;
}
Example #3
0
int USBDevice::Send(uchar command, uchar data1, uchar data2, uchar data3, uchar data4, uchar data5, uchar outBuffer[5])
{
    if (dev==NULL)
        return -1;

    uchar delay = 1; /// Delay = 1 * 320us
    uchar dataToSend[7] = {delay, command, data1, data2, data3, data4, data5};
    uchar replyBuffer[6];
    if (UsbSendData(dev, 3, dataToSend, 7, replyBuffer, 6)!=6)
    {
        Disconnect();
        return -2;
    }

    if (replyBuffer[0] != 0xA9)
    {
        // Incorrect reply: first should alwasy be 0xA9 (set in Tiny26 Receive Method)
        Disconnect();
        return -1;
    }

    if (outBuffer!=NULL)
    {
        for(int i=0; i<5; i++)
        {
            outBuffer[i] = replyBuffer[i+1];
        }
    }

    return 0;


/*
    reportOut.reportID = 1;
    reportOut.reportSize = 6;
    reportOut.command = 12;

    reportOut.data[0] = command;
    reportOut.data[1] = data1;
    reportOut.data[2] = data2;
    reportOut.data[3] = data3;
    reportOut.data[4] = data4;
    reportOut.data[5] = data5;

    if (!HidD_SetFeature(dev, (void*)&reportOut, sizeof(ReportOut_t)))
    {
        Disconnect();
        return -1;
    }

    reportIn.reportID = 1;
    if (!HidD_GetFeature(dev, (void*)&reportIn, sizeof(ReportIn_t)))
    {
        Disconnect();
        return -1;
    }

    if (outBuffer!=NULL)
    {
        int i =0;
        for (i=0; i<5; i++)
        {
            outBuffer[i] = reportIn.data[i+1]; // First data chunk isn't useful here (should always be 0xA9)
        }
    }

    */
}
Example #4
0
int USBDevice::Connect()
{
    //dev = UsbOpenDevice();
    if (UsbOpenDevice(&dev, 0x16c0, "beaversource.oregonstate.edu/projects/osuisp2", 0x05df, "OSUisp2"))
    {
        return -2;
    }
    if (dev==NULL)
        return -3;

    // Set clock speed
    /*reportOut.reportID = 1;
    reportOut.reportSize = 1;
    reportOut.command = 10;
    reportOut.data[0] = 5; // Clock Speed Index (higher for faster serial clock)
    if (!HidD_SetFeature(dev, (void*)&reportOut, sizeof(ReportOut_t)))
    {
        Disconnect();
        return -1;
    }
    reportIn.reportID = 1;
    if (!HidD_GetFeature(dev, (void*)&reportIn, sizeof(ReportIn_t)))
    {
        Disconnect();
        return -1;
    }
    if (reportIn.reportSize!=1 || reportIn.data[0] !=0)
    {
        Disconnect();
        return -1;
    }*/

    // Connect with the slowest clock option and do not maintain target device reset state
    uchar dataToSend[2] = {8, 0}; // Clock option = 8, maintainReset = false
    if (UsbSendData(dev, 1, dataToSend, 2, NULL, 0)!=1)
    {
        Disconnect();
        return -4;
    }

    // Initialize ISP
    /*reportOut.reportID = 1;
    reportOut.reportSize = 0;
    reportOut.command = 13;
    if (!HidD_SetFeature(dev, (void*)&reportOut, sizeof(ReportOut_t)))
    {
        Disconnect();
        return -1;
    }
    reportIn.reportID = 1;
    if (!HidD_GetFeature(dev, (void*)&reportIn, sizeof(ReportIn_t)))
    {
        Disconnect();
        return -1;
    }
    if (reportIn.reportSize!=1 || reportIn.data[0] !=0)
    {
        Disconnect();
        return -1;
    }*/

    // Wait for device to start up
    Sleep(100);

    uchar testData [7] = {1, 0, 0, 0, 0, 0, 0};
    uchar reply[6];
    if (UsbSendData(dev, 3, testData, 7, reply, 6)!=6)
    {
        Disconnect();
        return -5;
    }

    /*
    // Send some test data
    reportOut.reportID = 1;
    reportOut.reportSize = 6;
    reportOut.command = 12;

    reportOut.data[0] = 0;
    reportOut.data[1] = 0;
    reportOut.data[2] = 0;
    reportOut.data[3] = 0;
    reportOut.data[4] = 0;
    reportOut.data[5] = 0;

    if (!HidD_SetFeature(dev, (void*)&reportOut, sizeof(ReportOut_t)))
    {
        Disconnect();
        return -1;
    }

    reportIn.reportID = 1;
    if (!HidD_GetFeature(dev, (void*)&reportIn, sizeof(ReportIn_t)))
    {
        Disconnect();
        return -1;
    }
    */

    if (reply[0] !=0xA9)
    {
        Disconnect();
        return -6;
    }
    return 0;

}