Altera_Forum
Honored Contributor
14 years agoHow to implement a C routine to VHDL?
Hi,
I am trying to rewrite C routine for ethernet (sending of a packet) to VHDL. And I would like to know, how can I write command for setting up some configuration in ethernet driver registry. For example I have this function in C:
void iow(unsigned int reg, unsigned int data) {
IOWR(DM9000A_BASE,IO_addr,reg);
usleep(STD_DELAY);
IOWR(DM9000A_BASE,IO_data,data);
}
Specifically without constant:
void iow(unsigned int reg, unsigned int data) {
IOWR(0x11000,0,0x01);
usleep(20); //us
IOWR(0x11000,1,0xFF);
}
In the datasheet for DM9000A there are pins: iow (write), cs (chipselect), cmd (commad - index or data), sd0~7 (data) In compare with C: iow = IOWR cmd = IO_ADDR or IO_DATA sd0~7 = reg or data in argument of function So VHDL should be:
iow <= '0' -- active in low for writting
cs <= '0' -- active in low
cmd <= '0' -- i want to write index
... -- delay 10ns
sd <= x"01" -- i want registry with offset 0x01
.. -- delay 20us
cmd <= '1' -- i want to write data
... -- delay 10ns
sd <= x"FF" -- i want set registry to value 0xFF
And my questions are: What is correct way to implement this? How can I implement a delay like usleep() in C? Can I put this sequence in VHDL to some procedure? I would be glad for your advice