|
30 | 30 |
|
31 | 31 | using namespace utest::v1; |
32 | 32 |
|
33 | | -#include "mbed.h" |
34 | 33 | #include "MbedTester.h" |
35 | 34 | #include "pinmap.h" |
| 35 | +#include "test_utils.h" |
| 36 | + |
| 37 | +MbedTester tester(DefaultFormFactor::pins(), DefaultFormFactor::restricted_pins()); |
36 | 38 |
|
37 | | -static uint32_t call_counter; |
| 39 | +static volatile uint32_t call_counter; |
38 | 40 | void test_gpio_irq_handler(uint32_t id, gpio_irq_event event) |
39 | 41 | { |
40 | 42 | call_counter++; |
41 | 43 | } |
42 | 44 |
|
43 | | -const PinList *form_factor = pinmap_ff_default_pins(); |
44 | | -const PinList *restricted = pinmap_restricted_pins(); |
45 | | -MbedTester tester(form_factor, restricted); |
46 | | - |
47 | 45 | #define WAIT() wait_us(10) |
48 | 46 |
|
49 | | - |
50 | 47 | void gpio_irq_test(PinName pin) |
51 | 48 | { |
| 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 | + |
52 | 58 | gpio_t gpio; |
53 | 59 | // configure pin as input |
54 | 60 | gpio_init_in(&gpio, pin); |
55 | 61 |
|
56 | 62 | gpio_irq_t gpio_irq; |
57 | 63 | 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)); |
59 | 65 |
|
60 | 66 | gpio_irq_set(&gpio_irq, IRQ_RISE, true); |
61 | 67 | gpio_irq_enable(&gpio_irq); |
@@ -241,51 +247,26 @@ void gpio_irq_test(PinName pin) |
241 | 247 | WAIT(); |
242 | 248 | TEST_ASSERT_EQUAL(2, call_counter); |
243 | 249 |
|
244 | | - |
245 | 250 | gpio_irq_free(&gpio_irq); |
246 | 251 | } |
247 | 252 |
|
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) |
278 | 254 | { |
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); |
280 | 260 | } |
281 | 261 |
|
282 | 262 | 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>), |
284 | 265 | }; |
285 | 266 |
|
286 | 267 | utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
287 | 268 | { |
288 | | - GREENTEA_SETUP(10, "default_auto"); |
| 269 | + GREENTEA_SETUP(60, "default_auto"); |
289 | 270 | return greentea_test_setup_handler(number_of_cases); |
290 | 271 | } |
291 | 272 |
|
|
0 commit comments