Skip to content

Commit

Permalink
Add pinmap_gpio_restricted_pins() to provide list of restricted GPIO …
Browse files Browse the repository at this point in the history
…pins

This is a special case since targets do not provide by default GPIO pin-maps.
This extension is required for FPGA GPIO tests - if some pins have limitations (e.g. fixed pull-up) we need to skip these pins while testing.
To do that we were adding a dummy pin-map with commented out pins that can't be tested because of the limitations.
This solution is redundant and the proposition is to provide a list of restricted gpio pins if required (by default weak implementation is provided with an empty list).

This mechanism will be backward compatible, so the old method with dummy gpio pinmap will also work. The switch from dummy pin-maps to pinmap_gpio_restricted_pins() will be performed in separate commits/PRs.
  • Loading branch information
mprse committed Feb 7, 2020
1 parent a4e1354 commit 3c0982d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
15 changes: 13 additions & 2 deletions components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define I2C_NAME "I2C"
#define SPI_NAME "SPI"
#define SPISLAVE_NAME "SPISlave"
#define GPIO_NAME "GPIO"
#define GPIO_IRQ_NAME "GPIO_IRQ"

// test function prototypes
typedef void (*TF1)(PinName p0);
Expand Down Expand Up @@ -125,6 +127,15 @@ void find_ports(std::list<PortType> &matched_ports, std::list<PortType> &not_mat
continue;
}

if (!strcmp(PortType::PinMap::name, GPIO_IRQ_NAME) || !strcmp(PortType::PinMap::name, GPIO_NAME)) {
// Don't test restricted gpio pins
if (pinmap_list_has_pin(pinmap_gpio_restricted_pins(), port.pins[i])) {
utest_printf("Skipping %s pin %s (%i)\r\n", pin_type,
FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
continue;
}
}

if (!strcmp(PortType::PinMap::name, UART_NAME) || !strcmp(PortType::PinMap::name, UARTNOFC_NAME)) {
if (pinmap_list_has_peripheral(pinmap_uart_restricted_peripherals(), port.peripheral)) {
utest_printf("Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type,
Expand Down Expand Up @@ -455,7 +466,7 @@ struct GPIOMaps {
};
const PinMap *GPIOMaps::maps[] = { gpio_pinmap() };
const char *const GPIOMaps::pin_type_names[] = { "IO" };
const char *const GPIOMaps::name = "GPIO";
const char *const GPIOMaps::name = GPIO_NAME;
typedef Port<1, GPIOMaps, DefaultFormFactor, TF1> GPIOPort;

#if DEVICE_INTERRUPTIN
Expand All @@ -467,7 +478,7 @@ struct GPIOIRQMaps {
};
const PinMap *GPIOIRQMaps::maps[] = { gpio_irq_pinmap() };
const char *const GPIOIRQMaps::pin_type_names[] = { "IRQ_IN" };
const char *const GPIOIRQMaps::name = "GPIO_IRQ";
const char *const GPIOIRQMaps::name = GPIO_IRQ_NAME;
typedef Port<1, GPIOIRQMaps, DefaultFormFactor, TF1> GPIOIRQPort;
#endif

Expand Down
11 changes: 11 additions & 0 deletions hal/mbed_pinmap_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ MBED_WEAK const PinList *pinmap_restricted_pins()
return &pin_list;
}

//*** Default restricted gpio pins ***
// GPIO pins are special case because there are no pin-maps for GPIO
MBED_WEAK const PinList *pinmap_gpio_restricted_pins()
{
static const PinList pin_list = {
0,
0
};
return &pin_list;
}

//*** Default restricted peripherals ***
MBED_WEAK const PeripheralList *pinmap_uart_restricted_peripherals()
{
Expand Down
17 changes: 17 additions & 0 deletions hal/pinmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ const PinList *pinmap_restricted_pins(void);
*/
const PeripheralList *pinmap_uart_restricted_peripherals(void);

/**
* Get the pin list of pins to avoid during GPIO/GPIO_IRQ testing
*
* The GPIO restricted pin list is used to indicate to testing
* that a pin should be skipped due to some caveat about it.
*
* Targets should override the weak implementation of this
* function if they have peripherals which should be
* skipped during testing.
*
* @note This is special case only for GPIO/GPIO_IRQ tests because
* targets do not provide pin-maps for GPIO.
*
* @return Pointer to a peripheral list of peripheral to avoid
*/
const PinList *pinmap_gpio_restricted_pins(void);

#ifdef TARGET_FF_ARDUINO

/**
Expand Down

0 comments on commit 3c0982d

Please sign in to comment.