Skip to content

bsim: nrf_hw_models: split GPIO backend and add FIFO backend - #17

Open
Yagoor wants to merge 1 commit into
BabbleSim:mainfrom
Yagoor:contrib/gpio_fifo
Open

bsim: nrf_hw_models: split GPIO backend and add FIFO backend#17
Yagoor wants to merge 1 commit into
BabbleSim:mainfrom
Yagoor:contrib/gpio_fifo

Conversation

@Yagoor

@Yagoor Yagoor commented Aug 11, 2026

Copy link
Copy Markdown

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.

This is heavily based on the UART FIFO implementation

* 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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@Yagoor
Yagoor force-pushed the contrib/gpio_fifo branch from f2e0384 to 0d1aba2 Compare August 11, 2026 14:30

@aescolar aescolar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is based on the UART FIFO backend model, but instead of UART bytes it

This does not really belong in a permanent comment

Comment thread docs/GPIO.md

### FIFO backend:

It is also possible to connect two simulated devices through GPIO FIFO files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Comment on lines +33 to +36
/*
* Backend-file helper kept public for backward compatibility.
* This logically belongs to the file backend implementation.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/*
* 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 :)

@Yagoor

Yagoor commented Aug 19, 2026

Copy link
Copy Markdown
Author

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.

Fair enough, I just made those assumptions but your explanation makes perfect sense.

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.

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.

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)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants