bsim: nrf_hw_models: split GPIO backend and add FIFO backend - #17
Conversation
| * Backend-file helper kept public for backward compatibility. | ||
| * This logically belongs to the file backend implementation. | ||
| */ | ||
| void nrf_gpio_backend_register_short(uint8_t X, uint8_t x, uint8_t Y, uint8_t y); |
There was a problem hiding this comment.
This is needed because of https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/gpio/gpio_basic_api/src/main.c#L73
I didn't fully understand how that test works, so I kept it for simplicity
Refactor the GPIO backend into separate implementations and add a FIFO transport backend for cross-device GPIO signaling in simulation. - split the previous monolithic GPIO backend into: - common dispatcher (`NRF_GPIO_backend.c/.h`) - file backend (`NRF_GPIO_backend_file.c`) - FIFO backend (`NRF_GPIO_backend_fifo.c`) - update hw model source lists so the new backend files are built on all affected targets - add FIFO command-line options for tx/rx paths and keepalive timing - implement FIFO message handling for pin changes, NOP keepalives, and disconnect handling - keep file backend helper API public in the common header for backward compatibility - update GPIO backend documentation with FIFO backend usage This keeps file-based behavior available while enabling direct GPIO signal exchange between simulated devices. Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
f2e0384 to
0d1aba2
Compare
There was a problem hiding this comment.
Thanks @Yagoor
Overall:
- output file logging, is not a separate backend per se, but logging (for any backend)
- (just as input logging could equally be added (no need to do that in this PR, this is just an info comment))
- the configuration file, is a common utility (today it just has shortcuts configuration, but it was meant to allow for more)
- shortcuts are not really part of the file backend, but could be seen as a common utility.
=> I'll leave all these 3 in the general GPIO_backend.c, and only move the file gpio input from a file to a separate .c file.
Unlike UARTs, GPIO peripheral instances don't relate to how they are connected externally. Meaning, in reality one is not going to connect all GPIOs or all GPIOs of the same port to the same "partner" SoC/device)
So it feels that for the GPIO we should allow any arbitrary mapping to files/fifos..
So I'd allow N instances of the file input backend and M instances of the fifo backend.
(Even though the shortcuts handling could be handled as a separate backend, given that today the config file configures it directly, I'd just leave it as part of the general/overall backend code)
And I think I'd allow configuring both the input file and fifo backends instances either from the command line, or from the gpio configuration file.
Minor:
Moving the current input backend (adding the API) should better be one commit.
And adding the fifo backend another.
(and any trivial code polishing in another)
| #ifndef _NRF_HW_MODEL_GPIO_BACKEND_H | ||
| #define _NRF_HW_MODEL_GPIO_BACKEND_H | ||
|
|
||
| #include <stdint.h> |
There was a problem hiding this comment.
Please avoid any unnecessary change to minimize the diff, and ease the review, or ensure they are in a commit that does nothing else
|
|
||
| /* | ||
| * FIFO-backed backend for GPIO pin changes. | ||
| * This is based on the UART FIFO backend model, but instead of UART bytes it |
There was a problem hiding this comment.
This is based on the UART FIFO backend model, but instead of UART bytes it
This does not really belong in a permanent comment
|
|
||
| ### FIFO backend: | ||
|
|
||
| It is also possible to connect two simulated devices through GPIO FIFO files. |
There was a problem hiding this comment.
| It is also possible to connect two simulated devices through GPIO FIFO files. | |
| It is also possible to connect two simulated devices through GPIO FIFOs. |
Background: FIFOs are not really files. They have an inode in the filesystem so you can find them and play with their permissions, but beyond that they are just a kernel thing in memory (like unix sockets).
| /* | ||
| * Backend-file helper kept public for backward compatibility. | ||
| * This logically belongs to the file backend implementation. | ||
| */ |
There was a problem hiding this comment.
| /* | |
| * Backend-file helper kept public for backward compatibility. | |
| * This logically belongs to the file backend implementation. | |
| */ |
see general comment
| struct nrf_gpio_backend_if { | ||
| void (*init)(void); | ||
| void (*short_propagate)(unsigned int port, unsigned int n, bool value); | ||
| void (*write_output_change)(unsigned int port, unsigned int n, bool value); |
There was a problem hiding this comment.
| void (*write_output_change)(unsigned int port, unsigned int n, bool value); | |
| void (*change_output)(unsigned int port, unsigned int n, bool value); |
whatever that may need to do :)
Fair enough, I just made those assumptions but your explanation makes perfect sense.
I just tried to make it simple, meaning that I don't really expect more than two SoCs being interconnected in a simulation, but let me give it a try to make it more generic as your suggestion as it is for sure more complete.
This is something I can improve in general, I tend to move fast so it is difficult to break down my own work because I did more than what I intended to do at start. 😄 I will try to make multiple working commits instead of a single commit. Thank you for the inputs. I will address them. |
Refactor the GPIO backend into separate implementations and add a FIFO transport backend for cross-device GPIO signaling in simulation.
NRF_GPIO_backend.c/.h)NRF_GPIO_backend_file.c)NRF_GPIO_backend_fifo.c)This keeps file-based behavior available while enabling direct GPIO signal exchange between simulated devices.
This is heavily based on the UART FIFO implementation