Jump to content

virtual UART


Recommended Posts

I have a UART done in systemc/TLM2 with tx/rx etc, how can it interact with the host-os(e.g. Linux)? For example my OS is booting on the systemc-tlm2-simulator and I need a console to interact with it. I don't fully know how to get either one below to work in the code, e.g. how to make TLM2 model to talk with outside world. Typical use case includes UART for console, or Ethernet for internet. In the case of UART:

1. how to use a separate xterm window that somehow works with the simulator for printf/input.

2. how to use my current Linux console(where it launches the simulator) directly without a separate xterm, i.e. the console's current stdio and stdout will be owned by the simulator after it is launched, kind of like QEMU's `-serial stdio`, i.e redirect simulator's IO to current Linux console. It sometimes is called "virtual host IO"?

Any pointers are appreciated. Thanks!

Link to comment
Share on other sites

Several thoughts:

1. You could communicate with *NIX sockets or shared memory to another *NIX process. This will require coordinating use of shared buffers with semaphores and possibly mutexes to avoid collisions. The code will be tricky, but the results can be quite present. I would set software queues in both directions (in/out).

2. You could halt simulation when waiting for input, and just print output in the same window as the simulator. Simple, but impacts simulation speed and is potentially confusing.

3. A variation on #2 would be to use *NIX pipes to read/write to/from. You could use a separate terminal to write/read the pipes.

Link to comment
Share on other sites

Since you asked for pointers: a variation of 1. of @David Black would be the use of websockets. In the VP at  https://github.com/Minres/HIFIVE1-VP  this is used to implement a terminal (talking to the UART) which opens a websocket so that a web browser can be used to interact with the uart. The sources of the terminal can be found at https://github.com/Minres/HIFIVE1-VP/blob/master/platform/src/sysc/terminal.cpp and https://github.com/Minres/HIFIVE1-VP/blob/master/platform/incl/sysc/top/terminal.h respectively. The content served by the server (to be found at https://github.com/Minres/HIFIVE1-VP/blob/master/platform/incl/sysc/sc_comm_singleton.h and https://github.com/Minres/HIFIVE1-VP/blob/master/platform/src/sysc/sc_comm_singleton.cpp ) and shown by the client is located at https://github.com/Minres/HIFIVE1-VP/tree/master/html

Link to comment
Share on other sites

Thanks for the answers and pointers! I will look into these options along with figuring out how QEMU's `-serial stdio` worked. The goal is to make my TLM2 model's UART works just like QEMU's `-serial stdio` (no separate xterm, will reuse current console like QEMU does). There is another option using 'slirp' for both UART and Network but I have no clue how that works yet.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...