23 #define UART_NAME         "UART"    24 #define UARTNOFC_NAME     "UART-no-FC"    25 #define ANALOGOUT_NAME    "DAC"    26 #define ANALOGIN_NAME     "ADC"    27 #define PWM_NAME          "PWM"    28 #define I2C_NAME          "I2C"    29 #define SPI_NAME          "SPI"    30 #define SPISLAVE_NAME     "SPISlave"    31 #define GPIO_NAME         "GPIO"    32 #define GPIO_IRQ_NAME     "GPIO_IRQ"    35 typedef void (*TF1)(PinName p0);
    36 typedef void (*TF2)(PinName p0, PinName p1);
    37 typedef void (*TF3)(PinName p0, PinName p1, PinName p2);
    38 typedef void (*TF4)(PinName p0, PinName p1, PinName p2, PinName p3);
    39 typedef void (*TF5)(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4);
    41 template<
typename PortType, 
typename FunctionType, FunctionType f>
    46 template<
typename PortType, TF1 f>
    48     void operator()(PortType &port)
    54 template<
typename PortType, TF2 f>
    56     void operator()(PortType &port)
    58         f(port.pins[0], port.pins[1]);
    62 template<
typename PortType, TF3 f>
    64     void operator()(PortType &port)
    66         f(port.pins[0], port.pins[1], port.pins[2]);
    70 template<
typename PortType, TF4 f>
    72     void operator()(PortType &port)
    74         f(port.pins[0], port.pins[1], port.pins[2], port.pins[3]);
    78 template<
typename PortType, TF5 f>
    80     void operator()(PortType &port)
    82         f(port.pins[0], port.pins[1], port.pins[2], port.pins[3], port.pins[4]);
    86 template <
typename PortType>
    87 bool peripheral_comparator(
const PortType &port1, 
const PortType &port2)
    89     return port1.peripheral == port2.peripheral;
    92 template <
typename PortType>
    93 bool peripheral_less(
const PortType &port1, 
const PortType &port2)
    95     return port1.peripheral < port2.peripheral;
    98 template<
typename PortType, 
typename FormFactorType>
    99 static bool find_port_pins(PortType &port)
   102                                        port.peripheral, PortType::PinMap::maps, port.ppins, PortType::pin_count);
   105 template<
typename PortType, 
typename FormFactorType>
   106 void find_ports(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
   109     for (uint32_t i = 0; i < PortType::pin_count; i++) {
   110         const PinMap *map = PortType::PinMap::maps[i];
   111         const char *pin_type = PortType::PinMap::pin_type_names[i];
   114         for (uint32_t j = 0; j <  FormFactorType::pins()->count; j++) {
   117             if (FormFactorType::pins()->pins[j] == NC) {
   122             port.pins[i] = FormFactorType::pins()->pins[j];
   123             port.peripheral = pinmap_find_peripheral(port.pins[i], map);
   127                 utest_printf(
"Skipping (restricted pin) %s pin %s (%i)\r\n", pin_type,
   128                              FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
   132             if (!strcmp(PortType::PinMap::name, GPIO_IRQ_NAME) || !strcmp(PortType::PinMap::name, GPIO_NAME)) {
   135                     utest_printf(
"Skipping (restricted gpio pin) %s pin %s (%i)\r\n", pin_type,
   136                                  FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
   142             if (!strcmp(PortType::PinMap::name, UART_NAME) || !strcmp(PortType::PinMap::name, UARTNOFC_NAME)) {
   144                     utest_printf(
"Skipping (restricted uart peripheral) %s peripheral 0x%x with pin %s (%x)\r\n", pin_type,
   145                                  port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
   152             if (PortType::pin_count > 1) {
   153                 find_port_pins<PortType, FormFactorType>(port);
   156                 not_matched_ports.push_back(port);
   158                 matched_ports.push_back(port);
   165 template<
typename PortType, 
typename FormFactorType, 
typename FunctionType, FunctionType f>
   166 void test_all_ports(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
   168     typedef typename std::list<PortType>::iterator Iter;
   169     utest_printf(
"***Testing %s on all form factor ports***\n", PortType::PinMap::name);
   170     const PinList *ff_pins = FormFactorType::pins();
   173     if (matched_ports.empty() && not_matched_ports.empty()) {
   174         utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
   178     for (uint32_t i = 0; i < ff_pins->count; i++) {
   179         if (ff_pins->pins[i] != NC) {
   180             for (Iter it = matched_ports.begin(); it != matched_ports.end(); ++it) {
   181                 PortType &port = *it;
   182                 for (uint32_t j = 0; j < PortType::pin_count; j++) {
   183                     if (ff_pins->pins[i] == port.pins[j]) {
   184                         utest_printf(
"%3s - %s pin tested on port: %s...", FormFactorType::pin_to_string(ff_pins->pins[i]),
   185                                      PortType::PinMap::pin_type_names[j], port.str());
   186                         if (port.status == PortType::StatusNotTested) {
   188                             port.status = PortType::StatusPass;
   190                             utest_printf(
"test already done...");
   192                         utest_printf(
"%s\n", port.status == PortType::StatusPass ? 
"succeeded" : 
"failed");
   193                         goto end_port_iteration;
   197             for (Iter it = not_matched_ports.begin(); it != not_matched_ports.end(); ++it) {
   198                 PortType &port = *it;
   199                 for (uint32_t j = 0; j < PortType::pin_count; j++) {
   200                     if (ff_pins->pins[i] == port.pins[j]) {
   201                         utest_printf(
"%3s - Could not find pins to test %s pin %s (%d)\n",
   202                                      FormFactorType::pin_to_string(ff_pins->pins[i]),
   203                                      PortType::PinMap::pin_type_names[j],
   204                                      FormFactorType::pin_to_string(ff_pins->pins[i]),
   206                         goto end_port_iteration;
   216 template<
typename PortType, 
typename FunctionType, FunctionType f>
   217 void test_peripheral(PortType &port)
   220         if (port.peripheral != NC) {
   221             utest_printf(
"0x%x - Could not find pins to test peripheral\n", port.peripheral);
   224         utest_printf(
"0x%x - peripheral tested on port: %s...", port.peripheral, port.str());
   225         if (port.status == PortType::StatusNotTested) {
   228             port.status = PortType::StatusPass;
   230         utest_printf(
"%s\n", port.status == PortType::StatusPass ? 
"succeeded" : 
"failed");
   234 template<
typename PortType, 
typename FunctionType, FunctionType f>
   235 void test_all_peripherals(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
   237     typedef typename std::list<PortType>::iterator Iter;
   238     utest_printf(
"***Testing all %s peripherals***\n", PortType::PinMap::name);
   240     if (matched_ports.empty() && not_matched_ports.empty()) {
   241         utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
   245     matched_ports.sort(peripheral_less<PortType>);
   246     not_matched_ports.sort(peripheral_less<PortType>);
   248     for (Iter m_it = matched_ports.begin(), nm_it = not_matched_ports.begin();
   249             m_it != matched_ports.end() || nm_it != not_matched_ports.end();) {
   250         if (m_it != matched_ports.end() && nm_it != not_matched_ports.end()) {
   251             if ((*m_it).peripheral < (*nm_it).peripheral) {
   252                 test_peripheral<PortType, FunctionType, f>(*m_it);
   255                 test_peripheral<PortType, FunctionType, f>(*nm_it);
   258         } 
else if (m_it != matched_ports.end()) {
   259             test_peripheral<PortType, FunctionType, f>(*m_it);
   261         } 
else if (nm_it != not_matched_ports.end()) {
   262             test_peripheral<PortType, FunctionType, f>(*nm_it);
   279 template<
typename PortType, 
typename FormFactorType, 
typename PortType::TestFunctionType f>
   282     std::list<PortType> matched_ports, not_matched_ports;
   283     find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
   284     matched_ports.unique();
   285     not_matched_ports.unique();
   286     test_all_ports<PortType, FormFactorType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
   300 template<
typename PortType, 
typename FormFactorType, 
typename PortType::TestFunctionType f>
   301 void all_peripherals()
   303     std::list<PortType> matched_ports, not_matched_ports;
   304     find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
   306     matched_ports.sort(peripheral_less<PortType>);
   307     not_matched_ports.sort(peripheral_less<PortType>);
   308     matched_ports.unique(peripheral_comparator<PortType>);
   309     not_matched_ports.unique(peripheral_comparator<PortType>);
   311     test_all_peripherals<PortType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
   325 template<
typename PortType, 
typename FormFactorType, 
typename PortType::TestFunctionType f>
   326 void one_peripheral()
   328 #ifdef FPGA_FORCE_ALL_PORTS   329     utest_printf(
"*** FPGA_FORCE_ALL_PORTS ***\n");
   330     all_ports<PortType, FormFactorType, f>();
   332     std::list<PortType> matched_ports, not_matched_ports;
   333     find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
   335     utest_printf(
"***Testing one %s pin configuration***\n", PortType::PinMap::name);
   336     if (matched_ports.empty()) {
   337         utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
   339         test_peripheral<PortType, typename PortType::TestFunctionType, f>(matched_ports.front());
   344 template <u
int32_t N, 
typename PinMapType, 
typename FormFactorType, 
typename TestFunctionType>
   347 template <u
int32_t N, 
typename PinMapType, 
typename FormFactorType, 
typename TestFunctionType>
   351 template <u
int32_t N, 
typename PinMapType, 
typename FormFactorType, 
typename FunctionType>
   358     static const uint32_t pin_count = N;
   359     typedef PinMapType 
PinMap;
   360     typedef FunctionType TestFunctionType;
   362     enum Status { StatusPass, StatusFail, StatusNotTested };
   365     Port(): peripheral(NC), status(StatusNotTested)
   378         for (uint32_t i = 0; i < N; i++) {
   384     void copy_from(
const Port &port)
   386         peripheral = port.peripheral;
   387         status = port.status;
   388         for (uint32_t i = 0; i < N; i++) {
   389             pins[i] = port.pins[i];
   395         if (peripheral == NC) {
   398         for (uint32_t i = 0; i < N; i++) {
   408         static char port_str[128];
   410         sprintf(port_str, 
"peripheral=(0x%x) ", peripheral);
   411         for (uint32_t i = 0; i < N; i++) {
   412             sprintf(pin_str, 
"%s=(%s) ", PinMap::pin_type_names[i], FormFactorType::pin_to_string(pins[i]));
   413             strcat(port_str, pin_str);
   421 template <u
int32_t N, 
typename PinMapType, 
typename FormFactorType, 
typename FunctionType>
   424 template <u
int32_t N, 
typename PinMapType, 
typename FormFactorType, 
typename FunctionType>
   427     if (port1.peripheral != port2.peripheral) {
   430     for (uint32_t i = 0; i < N; i++) {
   431         if (port1.pins[i] != port2.pins[i]) {
   449         return pinmap_ff_default_pins();
   452     static const PinList *restricted_pins()
   457     static const char *pin_to_string(PinName pin)
   459         return pinmap_ff_default_pin_to_string(pin);
   473     static const PinMap *maps[];
   474     static const char *
const pin_type_names[];
   475     static const char *
const name;
   477 const PinMap *GPIOMaps::maps[] = { 
gpio_pinmap() };
   478 const char *
const GPIOMaps::pin_type_names[] = { 
"IO" };
   479 const char *
const GPIOMaps::name = GPIO_NAME;
   482 #if DEVICE_INTERRUPTIN   483 #include "gpio_irq_api.h"   485     static const PinMap *maps[];
   486     static const char *
const pin_type_names[];
   487     static const char *
const name;
   490 const char *
const GPIOIRQMaps::pin_type_names[] = { 
"IRQ_IN" };
   491 const char *
const GPIOIRQMaps::name = GPIO_IRQ_NAME;
   498     static const PinMap *maps[];
   499     static const char *
const pin_type_names[];
   500     static const char *
const name;
   503 const char *
const SPIMaps::pin_type_names[] = { 
"MOSI", 
"MISO", 
"SCLK", 
"SSEL" };
   504 const char *
const SPIMaps::name = SPI_NAME;
   508     static const PinMap *maps[];
   509     static const char *
const pin_type_names[];
   510     static const char *
const name;
   513 const char *
const SPINoCSMaps::pin_type_names[] = { 
"MOSI", 
"MISO", 
"SCLK" };
   514 const char *
const SPINoCSMaps::name = SPI_NAME;
   518     static const PinMap *maps[];
   519     static const char *
const pin_type_names[];
   520     static const char *
const name;
   523 const char *
const SPISlaveMaps::pin_type_names[] = { 
"MOSI", 
"MISO", 
"SCLK", 
"SSEL" };
   524 const char *
const SPISlaveMaps::name = SPISLAVE_NAME;
   531     static const PinMap *maps[];
   532     static const char *
const pin_type_names[];
   533     static const char *
const name;
   536 const char *
const I2CMaps::pin_type_names[] = { 
"SDA", 
"SCL" };
   537 const char *
const I2CMaps::name = I2C_NAME;
   542 #include "pwmout_api.h"   544     static const PinMap *maps[];
   545     static const char *
const pin_type_names[];
   546     static const char *
const name;
   549 const char *
const PWMMaps::pin_type_names[] = { 
"PWM_OUT" };
   550 const char *
const PWMMaps::name = PWM_NAME;
   555 #include "analogin_api.h"   557     static const PinMap *maps[];
   558     static const char *
const pin_type_names[];
   559     static const char *
const name;
   562 const char *
const AnaloginMaps::pin_type_names[] = { 
"ADC_IN" };
   563 const char *
const AnaloginMaps::name = ANALOGIN_NAME;
   568 #include "analogout_api.h"   570     static const PinMap *maps[];
   571     static const char *
const pin_type_names[];
   572     static const char *
const name;
   575 const char *
const AnalogoutMaps::pin_type_names[] = { 
"DAC_OUT" };
   576 const char *
const AnalogoutMaps::name = ANALOGOUT_NAME;
   582 #include "hal/serial_api.h"   584     static const PinMap *maps[];
   585     static const char *
const pin_type_names[];
   586     static const char *
const name;
   589 const char *
const UARTMaps::pin_type_names[] = { 
"TX", 
"RX", 
"CTS", 
"RTS" };
   590 const char *
const UARTMaps::name = UART_NAME;
   595     static const PinMap *maps[];
   596     static const char *
const pin_type_names[];
   597     static const char *
const name;
   600 const char *
const UARTNoFCMaps::pin_type_names[] = { 
"TX", 
"RX" };
   601 const char *
const UARTNoFCMaps::name = UARTNOFC_NAME;
 
const PinMap * serial_tx_pinmap(void)
Get the pins that support Serial TX. 
const PinMap * i2c_master_scl_pinmap(void)
Get the pins that support I2C SCL. 
const PinMap * spi_master_mosi_pinmap(void)
Get the pins that support SPI MOSI. 
const PinMap * i2c_master_sda_pinmap(void)
Get the pins that support I2C SDA. 
bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral)
Check if the peripheral is in the list. 
const PinMap * gpio_pinmap(void)
Get the pins that support all GPIO tests. 
bool pinmap_find_peripheral_pins(const PinList *whitelist, const PinList *blacklist, int per, const PinMap *const *maps, PinName **pins, uint32_t count)
Find a combination of pins suitable for use given the constraints. 
const PinMap * serial_cts_pinmap(void)
Get the pins that support Serial CTS. 
const PinMap * spi_master_miso_pinmap(void)
Get the pins that support SPI MISO. 
const PinMap * spi_master_cs_pinmap(void)
Get the pins that support SPI CS. 
bool pinmap_list_has_pin(const PinList *list, PinName pin)
Check if the pin is in the list. 
const PinMap * spi_master_clk_pinmap(void)
Get the pins that support SPI CLK. 
const PinMap * gpio_irq_pinmap(void)
Get the pins that support all GPIO IRQ tests. 
const PinMap * pwmout_pinmap(void)
Get the pins that support PWM. 
const PinMap * serial_rts_pinmap(void)
Get the pins that support Serial RTS. 
const PinMap * serial_rx_pinmap(void)
Get the pins that support Serial RX. 
void operator==(const SafeBool< T > &lhs, const SafeBool< U > &rhs)
Avoid conversion to bool between different classes. 
const PinList * pinmap_gpio_restricted_pins(void)
Get the pin list of pins to avoid during GPIO/GPIO_IRQ testing. 
const PinMap * spi_slave_cs_pinmap(void)
Get the pins that support SPI CS. 
const PinMap * spi_slave_mosi_pinmap(void)
Get the pins that support SPI MOSI. 
const PinList * pinmap_restricted_pins(void)
Get the pin list of pins to avoid during testing. 
const PinMap * analogout_pinmap(void)
Get the pins that support analogout. 
const PeripheralList * pinmap_uart_restricted_peripherals(void)
Get the pin list of peripherals per interface to avoid during testing. 
const PinMap * spi_slave_clk_pinmap(void)
Get the pins that support SPI CLK. 
const PinMap * spi_slave_miso_pinmap(void)
Get the pins that support SPI MISO. 
const PinMap * analogin_pinmap(void)
Get the pins that support analogin.