On 27/02/14 08:02, Svenn Are Bjerkem wrote:
Hi,
this is probably slightly off-topic, but maybe related.

The FPGA I am programming with VHDL is to be tested. It communicates with the outside world through UART. I send a command, receive a command and react to that command by sending a different command, or in the case of error, resend the previous command. The commands are long ASN.1 coded octet strings.

Currently I use Tcl to have the serial port in an event loop to be able to react asynchronously to the results coming from the FPGA. Writing the state-machine is a bit awkward, and it frustrates me that I can write a hardware FSM fairly easy in VHDL, but not in any programming language that I know (c, tcl, python)



I'd have thought interfacing to a serial port using Tcl or Python would be easier than using VHDL. I can point you to some of my code that also uses the Tcl event loop with non-blocking IO, which _may_ help you. See line 595 (parseSerialReadData proc) of:

https://github.com/pdt/tfirmata/blob/master/src/tfirmata.tcl

The messaging there is for talking to an Arduino, but the principle is the same.


I guess it is not easy to bind a serial port to ghdl and rely on the concurrency in VHDL to read, interpret and send commands the way I do in FPGA hardware, so my question is if there is a programming language which would help me that I don't know about yet. Hopefully it should run on both windows and Linux, but Linux-only is fine. Windows-only is not so fine, but ok. Assume that I have only knowledge (and not deep knowledge) of c, tcl, python, vhdl and ghdl.



Maybe take a look at coroutines? Tcl8.6 has them, as does Python. You can use them to do concurrency in the same way as a VHDL simulator (cooperative multithreading), without the need for a simulator. Coroutines are a bit more flexible, in that VHDL threads are static, i.e. you get one thread per process, but with coroutines you can dynamically start new threads as well, so they're a superset of VHDL threads. In VHDL other threads get a chance to run when you do a wait, with coroutines other threads get a chance to run when you do a yield.


You can also abstract to a higher level than yield. For example I hooked up Tcl8.6 to GHDL using VHPI and implemented threads using coroutines for my testbenches. See the testbench examples at:

http://pdt.github.io/script-tb_examples.html

and in particular, the simpler binary and johnson counter examples. In those testbenches new threads are started with 'run', and yielding occurs inside the 'in' and 'at' commands.


But I don't think you really need coroutines though. I'd keep it simple and go with the Tcl event loop you described in your post, that should work just fine. There's always comp.lang.tcl if you need help with Tcl code.


Any comments welcome.

--
Svenn


_______________________________________________
Ghdl-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/ghdl-discuss

Reply via email to