From 3c0982d9391f6fc206d6ec7aaf0a53c9b69e77c9 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Fri, 7 Feb 2020 10:30:59 +0100 Subject: [PATCH] Add pinmap_gpio_restricted_pins() to provide list of restricted GPIO 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. --- .../COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h | 15 +++++++++++++-- hal/mbed_pinmap_default.cpp | 11 +++++++++++ hal/pinmap.h | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h index 89e44f8886b..10086aa01c2 100644 --- a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h +++ b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h @@ -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); @@ -125,6 +127,15 @@ void find_ports(std::list &matched_ports, std::list ¬_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, @@ -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 @@ -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 diff --git a/hal/mbed_pinmap_default.cpp b/hal/mbed_pinmap_default.cpp index 3ae953557f3..a1ea453a9d0 100644 --- a/hal/mbed_pinmap_default.cpp +++ b/hal/mbed_pinmap_default.cpp @@ -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() { diff --git a/hal/pinmap.h b/hal/pinmap.h index 5ab10873137..abc3654585f 100644 --- a/hal/pinmap.h +++ b/hal/pinmap.h @@ -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 /**