|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2019 ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "utest/utest.h" |
| 18 | +#include "unity/unity.h" |
| 19 | +#include "greentea-client/test_env.h" |
| 20 | + |
| 21 | +using namespace utest::v1; |
| 22 | + |
| 23 | +#include "analogin_api.h" |
| 24 | +#include "analogout_api.h" |
| 25 | +#include "can_api.h" |
| 26 | +#include "i2c_api.h" |
| 27 | +#include "pwmout_api.h" |
| 28 | +#include "qspi_api.h" |
| 29 | +#include "serial_api.h" |
| 30 | +#include "spi_api.h" |
| 31 | + |
| 32 | +#define PINMAP_TEST_ENTRY(function) {function, #function} |
| 33 | + |
| 34 | +typedef const PinMap *(*get_pinmap_func_t)(void); |
| 35 | +typedef struct { |
| 36 | + get_pinmap_func_t function; |
| 37 | + const char *name; |
| 38 | +} pinmap_info_t; |
| 39 | + |
| 40 | +const pinmap_info_t pinmap_functions[] = { |
| 41 | +#if DEVICE_ANALOGIN |
| 42 | + PINMAP_TEST_ENTRY(analogin_pinmap), |
| 43 | +#endif |
| 44 | +#if DEVICE_ANALOGOUT |
| 45 | + PINMAP_TEST_ENTRY(analogout_pinmap), |
| 46 | +#endif |
| 47 | +#if DEVICE_CAN |
| 48 | + PINMAP_TEST_ENTRY(can_rd_pinmap), |
| 49 | + PINMAP_TEST_ENTRY(can_td_pinmap), |
| 50 | +#endif |
| 51 | +#if DEVICE_I2C |
| 52 | + PINMAP_TEST_ENTRY(i2c_master_sda_pinmap), |
| 53 | + PINMAP_TEST_ENTRY(i2c_master_scl_pinmap), |
| 54 | +#if DEVICE_I2CSLAVE |
| 55 | + PINMAP_TEST_ENTRY(i2c_slave_sda_pinmap), |
| 56 | + PINMAP_TEST_ENTRY(i2c_slave_scl_pinmap), |
| 57 | +#endif |
| 58 | +#endif |
| 59 | +#if DEVICE_PWMOUT |
| 60 | + PINMAP_TEST_ENTRY(pwmout_pinmap), |
| 61 | +#endif |
| 62 | +#if DEVICE_QSPI |
| 63 | + PINMAP_TEST_ENTRY(qspi_master_sclk_pinmap), |
| 64 | + PINMAP_TEST_ENTRY(qspi_master_ssel_pinmap), |
| 65 | + PINMAP_TEST_ENTRY(qspi_master_data0_pinmap), |
| 66 | + PINMAP_TEST_ENTRY(qspi_master_data1_pinmap), |
| 67 | + PINMAP_TEST_ENTRY(qspi_master_data2_pinmap), |
| 68 | + PINMAP_TEST_ENTRY(qspi_master_data3_pinmap), |
| 69 | +#endif |
| 70 | +#if DEVICE_SERIAL |
| 71 | + PINMAP_TEST_ENTRY(serial_tx_pinmap), |
| 72 | + PINMAP_TEST_ENTRY(serial_rx_pinmap), |
| 73 | +#if DEVICE_SERIAL_FC |
| 74 | + PINMAP_TEST_ENTRY(serial_cts_pinmap), |
| 75 | + PINMAP_TEST_ENTRY(serial_rts_pinmap), |
| 76 | +#endif |
| 77 | +#endif |
| 78 | +#if DEVICE_SPI |
| 79 | + PINMAP_TEST_ENTRY(spi_master_mosi_pinmap), |
| 80 | + PINMAP_TEST_ENTRY(spi_master_miso_pinmap), |
| 81 | + PINMAP_TEST_ENTRY(spi_master_clk_pinmap), |
| 82 | + PINMAP_TEST_ENTRY(spi_master_cs_pinmap), |
| 83 | +#if DEVICE_SPISLAVE |
| 84 | + PINMAP_TEST_ENTRY(spi_slave_mosi_pinmap), |
| 85 | + PINMAP_TEST_ENTRY(spi_slave_miso_pinmap), |
| 86 | + PINMAP_TEST_ENTRY(spi_slave_clk_pinmap), |
| 87 | + PINMAP_TEST_ENTRY(spi_slave_cs_pinmap), |
| 88 | +#endif |
| 89 | +#endif |
| 90 | + {NULL, NULL} |
| 91 | +}; |
| 92 | + |
| 93 | +void pinmap_validation() |
| 94 | +{ |
| 95 | + for (size_t i = 0; i < sizeof(pinmap_functions) / sizeof(pinmap_functions[0]) - 1; i++) { |
| 96 | + printf("Testing pinmap %s\r\n", pinmap_functions[i].name); |
| 97 | + |
| 98 | + get_pinmap_func_t function = pinmap_functions[i].function; |
| 99 | + TEST_ASSERT_NOT_EQUAL(NULL, function); |
| 100 | + |
| 101 | + const PinMap *map = function(); |
| 102 | + TEST_ASSERT_NOT_EQUAL(NULL, map); |
| 103 | + |
| 104 | + while (map->pin != NC) { |
| 105 | + map++; |
| 106 | + } |
| 107 | + |
| 108 | + TEST_ASSERT_EQUAL(NC, map->peripheral); |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +Case cases[] = { |
| 113 | + Case("pinmap - validation", pinmap_validation) |
| 114 | +}; |
| 115 | + |
| 116 | +utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
| 117 | +{ |
| 118 | + GREENTEA_SETUP(20, "default_auto"); |
| 119 | + return greentea_test_setup_handler(number_of_cases); |
| 120 | +} |
| 121 | + |
| 122 | +Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
| 123 | + |
| 124 | +int main() |
| 125 | +{ |
| 126 | + Harness::run(specification); |
| 127 | +} |
0 commit comments