GPIO: Add test API to be notified on output changes

Add a new API equivalent to nrf_gpio_test_register_in_callback()
but for output pin changes.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2024-03-14 10:05:04 +01:00
parent 0da91633f2
commit df94612a84
3 changed files with 24 additions and 2 deletions

View File

@ -32,6 +32,15 @@ For this just call the excutable with `-gpio_out_file=<path>`.
Any toggle in any pin configured as an output will be dumped to that file, following the
stimuli file format described below.
### Monitor inputs/outputs from test code:
Embedded test code specific for simulation can monitor the inputs and outputs changes
by registering a callback with `nrf_gpio_test_register_in_callback()` and
`nrf_gpio_test_register_out_callback()`.
With the first one, the callback will be called each time an *input gpio pin register* is modified.
With the second one, each time the output pin itself changes. That is, both will be called only
if the pin is connected/driven in that direction.
### Stimuli file format
This is a comma separated file (.csv), with 4 columns: time,port,pin,level. Where:

View File

@ -81,7 +81,9 @@ static uint32_t dir_override_set[NRF_GPIOS];
/* Callbacks for peripherals to be informed of input changes */
static nrf_gpio_input_callback_t per_intoggle_callbacks[NRF_GPIOS][NRF_GPIO_MAX_PINS_PER_PORT];
/* Callbacks for test code to be informed of input/output changes: */
static nrf_gpio_input_callback_t test_intoggle_callback;
static nrf_gpio_input_callback_t test_outtoggle_callback;
/*
* Initialize the GPIOs model
@ -116,6 +118,13 @@ void nrf_gpio_test_register_in_callback(nrf_gpio_input_callback_t fptr) {
test_intoggle_callback = fptr;
}
/*
* Register a test callback to be called whenever an *output* pin changes
*/
void nrf_gpio_test_register_out_callback(nrf_gpio_input_callback_t fptr) {
test_outtoggle_callback = fptr;
}
/*
* Change a pin input value
*
@ -388,6 +397,9 @@ void nrf_gpio_eval_input(unsigned int port, unsigned int n, bool value)
static void nrf_gpio_output_change_sideeffects(unsigned int port,unsigned int n, bool value)
{
nrf_gpio_backend_write_output_change(port, n, value);
if (test_outtoggle_callback != NULL) {
test_outtoggle_callback(port, n, value);
}
nrf_gpio_backend_short_propagate(port, n, value);
}

View File

@ -19,8 +19,8 @@ extern "C"{
#define NRF_GPIO_PORTS_PINS {32, 10} /* Number of IOs per port */
/*
* Callback another peripheral or tests can register if it wants to be called when an input
* is toggled.
* Callback another peripheral or tests can register if it wants to be called when an
* input/output is toggled.
*
* The callback will get as inputs:
* * port: the GPIO port which toggled,
@ -33,6 +33,7 @@ typedef void (*nrf_gpio_input_callback_t)(unsigned int port, unsigned int n, boo
unsigned int nrf_gpio_get_number_pins_in_port(int port);
void nrf_gpio_test_register_in_callback(nrf_gpio_input_callback_t fptr);
void nrf_gpio_test_register_out_callback(nrf_gpio_input_callback_t fptr);
void nrf_gpio_test_change_pin_level(unsigned int port, unsigned int n, bool value);
bool nrf_gpio_get_pin_level(unsigned int port, unsigned int n);