Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > USB Controllers

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



pls help v urgent
Moderator:
RSKV

Post Reply
Follow this topic



pls help v urgent

aksjain20 posted on 17 Nov 2009 6:08 AM PST

1 Forum Post


this is regarding cypress cy7c68013.





in this i m using a code in which loopback is happening as in a file from the pc is going to cypress=> from cypress it is going to the fpga which is spartan xc 3s 2000=>from fpga which has a fifo(ip core) dout it is going back to the cypress(ep6) and=> from cypress it is going back to the pc.

this is as per the original code now i want to modify it in such a way

that data from fpga itself (by assigning soe values to fifo ip core ie in the vhdl part) and this data from fpga board should go to cypress(ep6)and from cypress it should go the pc where as per the code i have created a write file usb_out.dat.



for this wht changes should i make in the code ,i m not understanding.

what i tried was.

i removed the browse part





well this is the code ..



//////////////////////////////////////////

#include "stdafx.h"

#include "Cypress.h"

#include "CypressDlg.h"

#include

#include

#include

#include

#include

#include

#include

#include"utility.h"



long FileSize=0;

class CAboutDlg : public CDialog

{

public:

CAboutDlg();



// Dialog Data

//{{AFX_DATA(CAboutDlg)

enum { IDD = IDD_ABOUTBOX };

//}}AFX_DATA



// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL



// Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};



CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}



void CAboutDlg:oDataExchange(CDataExchange* pDX)

{

CDialog:oDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}



BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

// No message handlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()



/////////////////////////////////////////////////////////////////////////////

// CCypressDlg dialog



CCypressDlg::CCypressDlg(CWnd* pParent /*=NULL*/)

: CDialog(CCypressDlg::IDD, pParent)

{

//{{AFX_DATA_INIT(CCypressDlg)

m_browse = _T("");

m_noofbyte = 0;

m_BYTE = 0;

m_HEX = 0;

m_CompTime = _T("");

m_AppTime = _T("");

m_vendor = _T("");

//}}AFX_DATA_INIT

// Note that LoadIcon does not require a subsequent DestroyIcon in Win32

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}



void CCypressDlg:oDataExchange(CDataExchange* pDX)

{

CDialog:oDataExchange(pDX);

//{{AFX_DATA_MAP(CCypressDlg)

DDX_Text(pDX, IDC_EBROWSE, m_browse);

DDX_Text(pDX, IDC_EREADBYTE, m_BYTE);



//}}AFX_DATA_MAP

}



BEGIN_MESSAGE_MAP(CCypressDlg, CDialog)

//{{AFX_MSG_MAP(CCypressDlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BROWSE, OnBrowse)

ON_BN_CLICKED(IDC_BEXIT, OnBexit)

ON_BN_CLICKED(IDC_BLOOPBACK, OnBloopback)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()



/////////////////////////////////////////////////////////////////////////////

// CCypressDlg message handlers



BOOL CCypressDlg:nInitDialog()

{

CDialog:nInitDialog();



// Add "About..." menu item to system menu.



// IDM_ABOUTBOX must be in the system command range.

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX < 0xF000);



CMenu* pSysMenu = GetSystemMenu(FALSE);

if (pSysMenu != NULL)

{

CString strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if (!strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

}

}



// Set the icon for this dialog. The framework does this automatically

// when the application's main window is not a dialog

SetIcon(m_hIcon, TRUE); // Set big icon

SetIcon(m_hIcon, FALSE); // Set small icon



// TODO: Add extra initialization here

UpdateData(TRUE);

// CompTime = GetTickCount();

// SetTimer(1, 100, NULL);

GetDlgItem(IDC_BLOOPBACK)->EnableWindow(FALSE);

// m_vendor="0xB1";



UpdateData(FALSE);

return TRUE; // return TRUE unless you set the focus to a control

}



void CCypressDlg:nSysCommand(UINT nID, LPARAM lParam)

{

if ((nID & 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog:nSysCommand(nID, lParam);

}

}



// If you add a minimize button to your dialog, you will need the code below

// to draw the icon. For MFC applications using the document/view model,

// this is automatically done for you by the framework.



void CCypressDlg:nPaint()

{

if (IsIconic())

{

CPaintDC dc(this); // device context for painting



SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);



// Center icon in client rectangle

int cxIcon = GetSystemMetrics(SM_CXICON);

int cyIcon = GetSystemMetrics(SM_CYICON);

CRect rect;

GetClientRect(&rect);

int x = (rect.Width() - cxIcon 1) / 2;

int y = (rect.Height() - cyIcon 1) / 2;



// Draw the icon

dc.DrawIcon(x, y, m_hIcon);

}

else

{

CDialog:nPaint();

}

}



// The system calls this to obtain the cursor to display while the user drags

// the minimized window.

HCURSOR CCypressDlg:nQueryDragIcon()

{

return (HCURSOR) m_hIcon;

}



void CCypressDlg:nBrowse()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

CFileDialog filename(TRUE, 0, 0,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"AllFiles (*.*)|*.*||");

if(filename.DoModal()==IDOK) //on commenting this if loop the dubufg fail error comes after the window appaers as in cypress window

{

m_browse=filename.GetPathName();

}







FILE *fp=fopen(m_browse,"rb ");

fseek(fp,0,SEEK_END);

int size=ftell(fp);

m_BYTE=size;

UpdateData(FALSE);

fclose(fp); //if i just commeneted this fclose then nothing actually happened

if(size%512==0)

{

GetDlgItem(IDC_BLOOPBACK)->EnableWindow(TRUE);// if this if loop is commented then the loopback button is not activated

}

else

{

AfxMessageBox("Please select file Whose Size Sholud be in Multiple of 512", MB_ICONSTOP| MB_OK);

return;



}



UpdateData(FALSE);



}



//aksend



void CCypressDlg:nBexit()

{

// TODO: Add your control notification handler code here



OnOK();



}

/*

void CCypressDlg:nBvendor()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

DWORD nBytes;

VENDOR_REQUEST_IN req;



int ret;

char *deep;

int request;

int bResult;





VENDOR_OR_CLASS_REQUEST_CONTROL myRequest;



char *buffer;

ULONG bufferSize = 0;









if(strcmp(m_vendor,"0xB1")==0||strcmp(m_vendor,"0xB2")==0||strcmp(m_vendor,"0xB3")==0||strcmp(m_vendor,"0xB4")==0||strcmp(m_vendor,"0xB5")==0)

{

if(strcmp(m_vendor,"0xB1")==0)

{

request=0xB1;



}





if(strcmp(m_vendor,"0xB2")==0)

{

request=0xB2;



}



if(strcmp(m_vendor,"0xB3")==0)

{

request=0xB3;



}





if(strcmp(m_vendor,"0xB4")==0)

{

request=0xB4;



}



if(strcmp(m_vendor,"0xB5")==0)

{

request=0xB5;



}

if(strcmp(m_vendor,"0xA0")==0)

{

request=0xA0;



}



}

else

{

AfxMessageBox("Please Fill proper value", MB_ICONSTOP| MB_OK);

return;

}







myRequest.request = request;

myRequest.value = 0xE600;

myRequest.index = 0x0000;

myRequest.direction = 0x00;

myRequest.requestType=2; // vendor specific request type (2)

myRequest.recepient=0; // recepient is device (0)









HANDLE outDevice = NULL;



if(!openUSBDevice(&outDevice))

{

AfxMessageBox("Couldn't open the USB device for IN operation.", MB_ICONSTOP| MB_OK);

exit(1);

}





if (outDevice != NULL)

{

bResult = DeviceIoControl (outDevice,

IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,

&myRequest,

sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),

buffer,

bufferSize,

(unsigned long *)&nBytes,

NULL);

}/* if valid driver handle















if(strcmp(m_vendor,"0xB1")==0||strcmp(m_vendor,"0xB2")==0||strcmp(m_vendor,"0xB3")==0||strcmp(m_vendor,"0xB4")==0||strcmp(m_vendor,"0xB5")==0)

{

if(strcmp(m_vendor,"0xB1")==0)

{

request=0xB1;



}



if(strcmp(m_vendor,"0xB2")==0)

{

request=0xB2;



}



if(strcmp(m_vendor,"0xB3")==0)

{

request=0xB3;



}





if(strcmp(m_vendor,"0xB4")==0)

{

request=0xB4;



}



if(strcmp(m_vendor,"0xB5")==0)

{

request=0xB5;



}

if(strcmp(m_vendor,"0xA0")==0)

{

request=0xA0;



}



}

else

{

AfxMessageBox("Please Fill proper value", MB_ICONSTOP| MB_OK);

return;

}



req.bRequest = request;

req.wValue = 0xE600; // using CPUCS.0 in FX2

req.wIndex = 0x00;

req.wLength = 0x01;

req.bData = 1;

req.direction = 0x00;*/



/*

if (!bResult)

{

MessageBox("Vendor Request Fail");

}

else

{

MessageBox("Vendor Request SuccessFull");

}



UpdateData(FALSE);

}

/*



void CCypressDlg:nBread()

{

// TODO: Add your control notification handler code here



UpdateData(TRUE);

HANDLE outDevice = NULL;

HANDLE inDevice = NULL;

if(!openUSBDevice(&inDevice))

{

AfxMessageBox("Couldn't open the USB device for IN operation.", MB_ICONSTOP| MB_OK);

exit(1);

}

int outPipeNum, inPipeNum;

outPipeNum=0;

inPipeNum=1;

BOOLEAN bResult=FALSE;

unsigned long nBytes=0;

UCHAR outBuffer[512],inBuffer[512];

BULK_TRANSFER_CONTROL bulkControl;

bulkControl.pipeNum = inPipeNum;

FILE *fp=fopen("USB_OUT.dat","wb ");



if(m_BYTE<=512)

{



DeviceIoControl (inDevice,IOCTL_EZUSB_BULK_READ,&bulkControl,sizeof(BULK_TRANSFER_CONTROL),

&inBuffer[0], m_BYTE,&nBytes,NULL);

fwrite(inBuffer,1,m_BYTE,fp);

}

else

{

while(m_BYTE<512)

{

DeviceIoControl (inDevice,IOCTL_EZUSB_BULK_READ,&bulkControl,sizeof(BULK_TRANSFER_CONTROL),

&inBuffer[0], 512,&nBytes,NULL);

fwrite(inBuffer,1,512,fp);

m_BYTE=m_BYTE-512;

}



DeviceIoControl (inDevice,IOCTL_EZUSB_BULK_READ,&bulkControl,sizeof(BULK_TRANSFER_CONTROL),

&inBuffer[0], m_BYTE,&nBytes,NULL);

fwrite(inBuffer,1,m_BYTE,fp);

}



MessageBox("Read is Complete");

fclose(fp);

FileSize=0;

UpdateData(FALSE);

}*/



/*void CCypressDlg:nBwrite()

{

// TODO: Add your control notification handler code here



UpdateData(TRUE);

HANDLE outDevice = NULL;

HANDLE inDevice = NULL;

int outPipeNum, inPipeNum;

outPipeNum=0,inPipeNum=1;



BOOLEAN bResult = FALSE;

unsigned long nBytes = 0;

UCHAR outBuffer[512], inBuffer[512];

BULK_TRANSFER_CONTROL bulkControl;

bulkControl.pipeNum = outPipeNum;



if(!openUSBDevice(&outDevice))

{

AfxMessageBox("Couldn't open the USB device for OUT operation.", MB_ICONSTOP| MB_OK);

exit(1);

}



FILE *fp=fopen(m_browse,"rb ");

fseek(fp,0,SEEK_END);

int size=ftell(fp);

m_BYTE=size;

fclose(fp);

fp=fopen(m_browse,"rb ");



if(size<=512)

{

fread(outBuffer,1,size,fp);

DeviceIoControl (outDevice,IOCTL_EZUSB_BULK_WRITE,&bulkControl,sizeof(BULK_TRANSFER_CONTROL),

&outBuffer[0], size,&nBytes,NULL);

}

else

{



while(!feof(fp))

{



size=size-512;

if(size<=0)

{

size=size 512;

break;

}





FileSize=FileSize 512;

fread(outBuffer,1,512,fp);

DeviceIoControl (outDevice,IOCTL_EZUSB_BULK_WRITE,&bulkControl,sizeof(BULK_TRANSFER_CONTROL),

&outBuffer[0], 512,&nBytes,NULL);

}

FileSize=FileSize size;

// size=size 512;

fread(outBuffer,1,size,fp);

DeviceIoControl (outDevice,IOCTL_EZUSB_BULK_WRITE,&bulkControl,sizeof(BULK_TRANSFER_CONTROL),

&outBuffer[0], size,&nBytes,NULL);



}

fclose(fp);

MessageBox("Write is Complete");



UpdateData(FALSE);





}

*/





bool openUSBDevice(HANDLE* hDevice)

{

char completeDeviceName[64] = "";



unsigned short devNum = 0;

for(devNum=0; devNum<10; devNum)

{

// Create the complete device name.

sprintf(completeDeviceName,"\\\\.\\EZUSB-%d",devNum);



// Open the device.

*hDevice = CreateFile(completeDeviceName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);



if(*hDevice==INVALID_HANDLE_VALUE)

{

continue;

}

else

{

break;

}

}



if(*hDevice==INVALID_HANDLE_VALUE)

{

return false;

}

else

{

return true;

}

}







void CCypressDlg:nBloopback()

{

// TODO: Add your control notification handler code here





UpdateData(TRUE);



CompTime = GetTickCount();

// SetTimer(1, 1, NULL);

HANDLE outDevice = NULL;

HANDLE inDevice = NULL;

int outPipeNum, inPipeNum;

outPipeNum=0,inPipeNum=1;





BOOLEAN bResult = FALSE;

unsigned long nBytes = 0;

UCHAR inBuffer[512],outBuffer[512];

BULK_TRANSFER_CONTROL bulkControl1,bulkControl2;

bulkControl1.pipeNum = outPipeNum;

bulkControl2.pipeNum = inPipeNum;





if(!openUSBDevice(&outDevice))

{

AfxMessageBox("Couldn't open the USB device for OUT operation.", MB_ICONSTOP| MB_OK);

exit(1);

}



if(!openUSBDevice(&inDevice))

{

AfxMessageBox("Couldn't open the USB device for IN operation.", MB_ICONSTOP| MB_OK);

exit(1);

}







FILE *fp=fopen(m_browse,"rb ");

fseek(fp,0,SEEK_END);

int size=ftell(fp);

fclose(fp);

fp=fopen(m_browse,"rb ");

FILE *fp1=fopen("USB_OUT.dat","wb ");



if(size<=512)

{

fread(outBuffer,1,size,fp);

DeviceIoControl (outDevice,IOCTL_EZUSB_BULK_WRITE,&bulkControl1,sizeof(BULK_TRANSFER_CONTROL),

&outBuffer[0], size,&nBytes,NULL);



DeviceIoControl (inDevice,IOCTL_EZUSB_BULK_READ,&bulkControl2,sizeof(BULK_TRANSFER_CONTROL),

&inBuffer[0], 512,&nBytes,NULL);

fwrite(inBuffer,1,512,fp1);





}









while(!feof(fp))

{



size=size-512;

if(size<=0)

{

size=size 512;

break;

}





FileSize=FileSize 512;

fread(outBuffer,1,512,fp);

DeviceIoControl (outDevice,IOCTL_EZUSB_BULK_WRITE,&bulkControl1,sizeof(BULK_TRANSFER_CONTROL),

&outBuffer[0], 512,&nBytes,NULL);

for(long i=0;i<999999;i );

DeviceIoControl (inDevice,IOCTL_EZUSB_BULK_READ,&bulkControl2,sizeof(BULK_TRANSFER_CONTROL),

&inBuffer[0], 512,&nBytes,NULL);

fwrite(inBuffer,1,512,fp1);//commenting this part makes tge op file less than the input





}

fread(outBuffer,1,size,fp);

DeviceIoControl (outDevice,IOCTL_EZUSB_BULK_WRITE,&bulkControl1,sizeof(BULK_TRANSFER_CONTROL),//here no change as such aftr commenting except tht msgloopback comment karne ke baad the displayof loopback complete doesnt come

&outBuffer[0], size,&nBytes,NULL);

DeviceIoControl (inDevice,IOCTL_EZUSB_BULK_READ,&bulkControl2,sizeof(BULK_TRANSFER_CONTROL),

&inBuffer[0], 512,&nBytes,NULL);

fwrite(inBuffer,1,512,fp1);



fclose(fp);

fclose(fp1);

MessageBox("LoopBack is over");

UpdateData(FALSE);



}



/*

void CCypressDlg:nTimer(UINT nIDEvent)

{

// TODO: Add your message handler code here and/or call default



unsigned long CurTickValue = GetTickCount();

unsigned int Difference = CurTickValue - CompTime;



unsigned int ComputerHours, ComputerMinutes, ComputerSeconds;

unsigned int ApplicationHours, ApplicationMinutes, ApplicationSeconds;



ComputerHours = (CurTickValue / (3600 * 999)) % 24;

ComputerMinutes = (CurTickValue / (60 * 999)) % 60;

ComputerSeconds = (CurTickValue / 999) % 60;

ApplicationHours = (Difference / (3600 * 999)) % 24;

ApplicationMinutes = (Difference / (60 * 999)) % 60;

ApplicationSeconds = (Difference / 999) % 60;



m_CompTime.Format("This computer has been ON for %d hours, %d minutes %d seconds",

ComputerHours, ComputerMinutes, ComputerSeconds);

m_AppTime.Format("This application has been running for %d hours, %d minutes %d seconds",

ApplicationHours, ApplicationMinutes, ApplicationSeconds);



UpdateData(FALSE);

KillTimer(1);

MessageBox("LpBack is complete");

CDialog:nTimer(nIDEvent);

}

*/











pls suggest me some idea so taht i could get a trigger to get my objective going in the right direction.



thanks

akanksha








ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20