-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
litex_sim: add inter-module messaging, external simulation control and controllable GPIO #1104
Draft
lschuermann
wants to merge
5
commits into
enjoy-digital:master
Choose a base branch
from
lschuermann:dev/litex-sim-ctrl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lschuermann
force-pushed
the
dev/litex-sim-ctrl
branch
from
November 17, 2021 12:20
2ddcb05
to
aad6e5f
Compare
@lschuermann: This looks great, thanks! (I'll review it very soon). |
lschuermann
force-pushed
the
dev/litex-sim-ctrl
branch
from
November 17, 2021 16:12
aad6e5f
to
f6bc50e
Compare
This introduces a generic, flexible and efficient inter-module message passing mechanism to allow for more advanced module behavior and interactions, as well as outside control of module behavior. Possible applications for this mechanism are outside control of emulated peripherals such as GPIO, simulated hardware attached to multiple independent subsystems (e.g. GPIO + SPI) and integration of the LiteX simulation in automated systems such as CI. The message passing mechanism does not impose any restrictions on the data exchanged between modules and each module is free to define its own interfaces through opcodes >= 256. Opcodes < 256 are reserved for globally defined operations. These global operations include auto-announcement of instantiated module sessions in the simulation for discovery and a mechanism for interacting with outside applications (called "simctrl"). These operations are well documented in `modules.h`. This further introduces a few functions which expose basic information about and control of the simulation, such as querying the current simulation time and state, and requesting the simulation to halt or resume operation. Signed-off-by: Leon Schuermann <leon@is.currently.online>
This is required for modules to be able to call globally defined symbols to interact with other parts of the simulation, for example to send inter-module messages, query the simulation time or request the simulation to halt / resume. Signed-off-by: Leon Schuermann <leon@is.currently.online>
lschuermann
force-pushed
the
dev/litex-sim-ctrl
branch
from
January 11, 2024 22:04
f6bc50e
to
f82cb5f
Compare
Adds a module implementing the "simctrl"-style control & status interface for the LiteX simulation. It uses a ZeroMQ/JSON-based transport for the control, status and module messages. However, modules are free to define their own format. The passed messages make use of ZeroMQ multipart messages, for instance to carry payloads to simctrl-supported modules in the simulation. Thus, this module takes messages which contain a "simctrl header" and a payload forwarded to the destination module. Furthermore, the module implements some basic standalone status & control functionality. It can be used to query the current wall clock time, simulation time and instantiated module sessions. It can furthermore halt and resume the simulation. Signed-off-by: Leon Schuermann <leon@is.currently.online>
Adds a GPIO controller module, which is exposed through simctrl. Supports driving GPIO pins, as well as querying the current pin state (input/output) and signal state. Exposes a JSON-based interface through the simctrl payload. Signed-off-by: Leon Schuermann <leon@is.currently.online>
lschuermann
force-pushed
the
dev/litex-sim-ctrl
branch
from
January 11, 2024 22:07
f82cb5f
to
8fb6fc9
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is quite a large changeset. It introduces three major components as outlined below, which all depend on each other. I recommend reviewing the individual commits over the very large diff.
This is still lacking some external interface documentation and examples in the form of a Markdown (non-code) document. Furthermore, it would be nice to have a user-friendly application upstream to control the simulation. I have written a small Rust library and application for that. I'm not sure whether Rust will be accepted upstream or I should rewrite it in Python.
Components / mechanisms introduced
Inter-module message passing mechanism
This introduces a generic, flexible and efficient inter-module message passing mechanism to allow for more advanced module behavior and interactions, as well as outside control of module behavior.
Possible applications for this mechanism are outside control of emulated peripherals such as GPIO, simulated hardware attached to multiple independent subsystems (e.g. GPIO + SPI) and integration of the LiteX simulation in automated systems such as CI.
The message passing mechanism does not impose any restrictions on the data exchanged between modules and each module is free to define its own interfaces through opcodes >= 256. Opcodes < 256 are reserved for globally defined operations.
These global operations include auto-announcement of instantiated module sessions in the simulation for discovery and a mechanism for interacting with outside applications (called "simctrl"). These operations are well documented in
modules.h
.This further introduces a few functions which expose basic information about and control of the simulation, such as querying the current simulation time and state, and requesting the simulation to halt or resume operation.
Externally-accessible ZeroMQ/JSON based simctrl interface
On top of this generic inter-module message passing interface, an module for external communication through the "simctrl" interface based on ZeroMQ/JSON is introduced. While modules are free to define their own payload format, this introduces a standard way of talking to the simulation from an external application.
The passed messages make use of ZeroMQ multipart messages, for instance to carry payloads to simctrl-supported modules in the simulation. Thus, this module takes messages which contain a "simctrl header" and a payload forwarded to the destination module.
Furthermore, the module implements some basic standalone status & control functionality. It can be used to query the current wall clock time, simulation time and instantiated module sessions. It can halt and resume the simulation.
Controllable GPIO controller
Finally, this adds a GPIO controller module, which is exposed through simctrl. Supports driving GPIO pins, as well as querying the current pin state (input/output) and signal state. Exposes a JSON-based interface through the simctrl payload.
End result
With these changes, we have a simulation which can be used in rich CI setups, such as the one built using this infrastructure for the Tock operating system (tock/tock#2801):
Furthermore, with an appropriate control binary, users have a friendly interface to interact with their simulation:
A demo of the Rust client can be seen here: https://asciinema.org/a/SiQ7Byeco0qa5ELueltiAPQqS