Skip to content

Commit 417a9fe

Browse files
author
Seppo Takalo
authored
Merge pull request #11074 from fkjagodzinski/pinmap-gpio_irq
Add a gpio-irq pinmap
2 parents 9affeb8 + 8448640 commit 417a9fe

File tree

7 files changed

+88
-47
lines changed

7 files changed

+88
-47
lines changed

TESTS/mbed_hal/pinmap/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using namespace utest::v1;
2222

2323
#include "gpio_api.h"
24+
#include "gpio_irq_api.h"
2425
#include "analogin_api.h"
2526
#include "analogout_api.h"
2627
#include "can_api.h"
@@ -40,6 +41,9 @@ typedef struct {
4041

4142
const pinmap_info_t pinmap_functions[] = {
4243
PINMAP_TEST_ENTRY(gpio_pinmap),
44+
#if DEVICE_INTERRUPTIN
45+
PINMAP_TEST_ENTRY(gpio_irq_pinmap),
46+
#endif
4347
#if DEVICE_ANALOGIN
4448
PINMAP_TEST_ENTRY(analogin_pinmap),
4549
#endif

TESTS/mbed_hal_fpga_ci_test_shield/gpio_irq/main.cpp

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,38 @@
3030

3131
using namespace utest::v1;
3232

33-
#include "mbed.h"
3433
#include "MbedTester.h"
3534
#include "pinmap.h"
35+
#include "test_utils.h"
36+
37+
MbedTester tester(DefaultFormFactor::pins(), DefaultFormFactor::restricted_pins());
3638

37-
static uint32_t call_counter;
39+
static volatile uint32_t call_counter;
3840
void test_gpio_irq_handler(uint32_t id, gpio_irq_event event)
3941
{
4042
call_counter++;
4143
}
4244

43-
const PinList *form_factor = pinmap_ff_default_pins();
44-
const PinList *restricted = pinmap_restricted_pins();
45-
MbedTester tester(form_factor, restricted);
46-
4745
#define WAIT() wait_us(10)
4846

49-
5047
void gpio_irq_test(PinName pin)
5148
{
49+
// Reset everything and set all tester pins to hi-Z.
50+
tester.reset();
51+
52+
// Map pins for test.
53+
tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0);
54+
55+
// Select GPIO0.
56+
tester.select_peripheral(MbedTester::PeripheralGPIO);
57+
5258
gpio_t gpio;
5359
// configure pin as input
5460
gpio_init_in(&gpio, pin);
5561

5662
gpio_irq_t gpio_irq;
5763
uint32_t id = 123;
58-
gpio_irq_init(&gpio_irq, pin, test_gpio_irq_handler, id);
64+
TEST_ASSERT_EQUAL(0, gpio_irq_init(&gpio_irq, pin, test_gpio_irq_handler, id));
5965

6066
gpio_irq_set(&gpio_irq, IRQ_RISE, true);
6167
gpio_irq_enable(&gpio_irq);
@@ -241,51 +247,26 @@ void gpio_irq_test(PinName pin)
241247
WAIT();
242248
TEST_ASSERT_EQUAL(2, call_counter);
243249

244-
245250
gpio_irq_free(&gpio_irq);
246251
}
247252

248-
249-
void gpio_irq_test()
250-
{
251-
for (uint32_t i = 0; i < form_factor->count; i++) {
252-
const PinName test_pin = form_factor->pins[i];
253-
if (test_pin == NC) {
254-
continue;
255-
}
256-
if (pinmap_list_has_pin(restricted, test_pin)) {
257-
printf("Skipping gpio pin %s (%i)\r\n", pinmap_ff_default_pin_to_string(test_pin), test_pin);
258-
continue;
259-
}
260-
tester.pin_map_reset();
261-
tester.pin_map_set(test_pin, MbedTester::LogicalPinGPIO0);
262-
263-
printf("GPIO irq test on pin %3s (%3i)\r\n", pinmap_ff_default_pin_to_string(test_pin), test_pin);
264-
gpio_irq_test(test_pin);
265-
}
266-
}
267-
268-
utest::v1::status_t setup(const Case *const source, const size_t index_of_case)
269-
{
270-
tester.reset();
271-
tester.select_peripheral(MbedTester::PeripheralGPIO);
272-
273-
return greentea_case_setup_handler(source, index_of_case);
274-
}
275-
276-
utest::v1::status_t teardown(const Case *const source, const size_t passed, const size_t failed,
277-
const failure_t reason)
253+
void init_free_test(PinName pin)
278254
{
279-
return greentea_case_teardown_handler(source, passed, failed, reason);
255+
gpio_t gpio;
256+
gpio_irq_t gpio_irq;
257+
gpio_init_in(&gpio, pin);
258+
TEST_ASSERT_EQUAL(0, gpio_irq_init(&gpio_irq, pin, test_gpio_irq_handler, 123));
259+
gpio_irq_free(&gpio_irq);
280260
}
281261

282262
Case cases[] = {
283-
Case("GPIO - irq test", setup, gpio_irq_test, teardown)
263+
Case("init/free", all_ports<GPIOIRQPort, DefaultFormFactor, init_free_test>),
264+
Case("rising & falling edge", all_ports<GPIOIRQPort, DefaultFormFactor, gpio_irq_test>),
284265
};
285266

286267
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
287268
{
288-
GREENTEA_SETUP(10, "default_auto");
269+
GREENTEA_SETUP(60, "default_auto");
289270
return greentea_test_setup_handler(number_of_cases);
290271
}
291272

components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,19 @@ const char *const GPIOMaps::pin_type_names[] = { "IO" };
440440
const char *const GPIOMaps::name = "GPIO";
441441
typedef Port<1, GPIOMaps, DefaultFormFactor, TF1> GPIOPort;
442442

443+
#if DEVICE_INTERRUPTIN
444+
#include "gpio_irq_api.h"
445+
struct GPIOIRQMaps {
446+
static const PinMap *maps[];
447+
static const char *const pin_type_names[];
448+
static const char *const name;
449+
};
450+
const PinMap *GPIOIRQMaps::maps[] = { gpio_irq_pinmap() };
451+
const char *const GPIOIRQMaps::pin_type_names[] = { "IRQ_IN" };
452+
const char *const GPIOIRQMaps::name = "GPIO_IRQ";
453+
typedef Port<1, GPIOIRQMaps, DefaultFormFactor, TF1> GPIOIRQPort;
454+
#endif
455+
443456
#if DEVICE_SPI
444457
#include "spi_api.h"
445458
struct SPIMaps {

hal/gpio_irq_api.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define MBED_GPIO_IRQ_API_H
2222

2323
#include "device.h"
24+
#include "pinmap.h"
2425

2526
#if DEVICE_INTERRUPTIN
2627

@@ -85,6 +86,18 @@ void gpio_irq_enable(gpio_irq_t *obj);
8586
*/
8687
void gpio_irq_disable(gpio_irq_t *obj);
8788

89+
/** Get the pins that support all GPIO IRQ tests
90+
*
91+
* Return a PinMap array of pins that support GPIO IRQ.
92+
* The array is terminated with {NC, NC, 0}.
93+
*
94+
* Targets should override the weak implementation of this
95+
* function to provide the actual pinmap for GPIO IRQ testing.
96+
*
97+
* @return PinMap array
98+
*/
99+
const PinMap *gpio_irq_pinmap(void);
100+
88101
/**@}*/
89102

90103
#ifdef __cplusplus

hal/mbed_gpio_irq.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "hal/gpio_irq_api.h"
18+
19+
#if DEVICE_INTERRUPTIN
20+
21+
#include "platform/mbed_toolchain.h"
22+
#include "hal/gpio_api.h"
23+
24+
MBED_WEAK const PinMap *gpio_irq_pinmap()
25+
{
26+
// Targets should override this weak implementation to provide correct data.
27+
// By default, this is exactly the same as GPIO PinMap.
28+
return gpio_pinmap();
29+
}
30+
31+
#endif

targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/gpio_irq_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void gpio_irq_dispatcher(uint32_t port_id)
4949
MBED_ASSERT(obj);
5050
Cy_GPIO_ClearInterrupt(port, pin);
5151
event = (obj->mode == IRQ_FALL)? IRQ_FALL : IRQ_RISE;
52-
obj->handler(obj->id_arg, event);
52+
((gpio_irq_handler) obj->handler)(obj->id_arg, event);
5353
}
5454
}
5555
}
@@ -202,7 +202,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
202202
MBED_ASSERT("Invalid pin ID!");
203203
return (-1);
204204
}
205-
obj->handler = handler;
205+
obj->handler = (uint32_t) handler;
206206
obj->id_arg = id;
207207
return gpio_irq_setup_channel(obj);
208208
} else {

targets/TARGET_Cypress/TARGET_PSOC6_FUTURE/objects.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "PinNames.h"
2424
#include "PortNames.h"
2525

26-
#include "gpio_irq_api.h"
2726
#include "gpio_object.h"
2827
#include "cy_sysclk.h"
2928
#include "cy_syspm.h"
@@ -37,8 +36,8 @@ struct gpio_irq_s {
3736
GPIO_PRT_Type* port;
3837
uint32_t port_id;
3938
uint32_t pin;
40-
gpio_irq_event mode;
41-
gpio_irq_handler handler;
39+
uint32_t mode;
40+
uint32_t handler;
4241
uint32_t id_arg;
4342
#if defined (TARGET_MCU_PSOC6_M0)
4443
cy_en_intr_t cm0p_irq_src;

0 commit comments

Comments
 (0)