FPGARelated.com
Forums

interfacing a PC based program with a FPGA

Started by Srinivas October 21, 2004
> Hi, > I'm looking to integrate a FPGA based program into a PC based > application. > I understand i need to write a serial interfacing code on the FPGA > side and an API on the PC side,considering i intend to use a RS 232 > serial interface bet'n the PC and the FPGA board. > I need help regarding the PC side API programming.I'll be using a 'C' > program and would like to call the FPGA based functions. > Can anyone suggest how i go about this?any references? >
perhaps this few lines of C can get you started (if you're using Windows): DCB dcb; HANDLE hCom; DWORD dwError; BOOL fSuccess; // // open serial line // hCom = CreateFile(argv[argc-1], GENERIC_READ | GENERIC_WRITE, 0, /* comm devices must be opened w/exclusive-access */ NULL, /* no security attrs */ OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */ 0, /* not overlapped I/O */ NULL /* hTemplate must be NULL for comm devices */ ); if (hCom == INVALID_HANDLE_VALUE) { dwError = GetLastError(); printf("error\n"); exit(-1); } fSuccess = GetCommState(hCom, &dcb); if (!fSuccess) { printf("error\n"); exit(-1); } // // set properties // dcb.BaudRate = 115200; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; /* use RTS/CTS handshake */ dcb.fOutxCtsFlow = TRUE; dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fOutxDsrFlow = FALSE; dcb.fDtrControl = DTR_CONTROL_DISABLE; dcb.fDsrSensitivity = FALSE; fSuccess = SetCommState(hCom, &dcb); if (!fSuccess) { printf("error in SetCommState\n"); exit(-1); } // write a single byte WriteFile(hCom, &data, 1, &cnt, NULL); // read a single byte ReadFile(hCom, &c, 1, &cnt, NULL); Martin ---------------------------------------------- JOP - a Java Processor core for FPGAs: http://www.jopdesign.com/
Thanks to all.
i'm using a win2000 system. but guess the same serial port code should
work for all Win based systems.
Martin,i've actualy written similar code after posting here last.
Thanks for your code(your's much neater :) )
i figured serial communication to be the easiet of all PC-FPGA
communication ,I could implement hence the choice.I intend to
"graduate" to others in due course of time.

rgds.
srinivas.