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) {
118 utest_printf(
"Skipping (NC pin) %s pin %s (%i)\r\n", pin_type,
119 FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
124 port.pins[i] = FormFactorType::pins()->pins[j];
125 port.peripheral = pinmap_find_peripheral(port.pins[i], map);
129 utest_printf(
"Skipping (restricted pin) %s pin %s (%i)\r\n", pin_type,
130 FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
134 if (!strcmp(PortType::PinMap::name, GPIO_IRQ_NAME) || !strcmp(PortType::PinMap::name, GPIO_NAME)) {
137 utest_printf(
"Skipping (restricted gpio pin) %s pin %s (%i)\r\n", pin_type,
138 FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
144 if (!strcmp(PortType::PinMap::name, UART_NAME) || !strcmp(PortType::PinMap::name, UARTNOFC_NAME)) {
146 utest_printf(
"Skipping (restricted uart peripheral) %s peripheral %i with pin %s (%i)\r\n", pin_type,
147 port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
154 if (PortType::pin_count > 1) {
155 find_port_pins<PortType, FormFactorType>(port);
158 not_matched_ports.push_back(port);
160 matched_ports.push_back(port);
167 template<
typename PortType,
typename FormFactorType,
typename FunctionType, FunctionType f>
168 void test_all_ports(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
170 typedef typename std::list<PortType>::iterator Iter;
171 utest_printf(
"***Testing %s on all form factor ports***\n", PortType::PinMap::name);
172 const PinList *ff_pins = FormFactorType::pins();
175 if (matched_ports.empty() && not_matched_ports.empty()) {
176 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
180 for (uint32_t i = 0; i < ff_pins->count; i++) {
181 for (Iter it = matched_ports.begin(); it != matched_ports.end(); ++it) {
182 PortType &port = *it;
183 for (uint32_t j = 0; j < PortType::pin_count; j++) {
184 if (ff_pins->pins[i] == port.pins[j]) {
185 utest_printf(
"%3s - %s pin tested on port: %s...", FormFactorType::pin_to_string(ff_pins->pins[i]),
186 PortType::PinMap::pin_type_names[j], port.str());
187 if (port.status == PortType::StatusNotTested) {
189 port.status = PortType::StatusPass;
191 utest_printf(
"%s\n", port.status == PortType::StatusPass ?
"succeeded" :
"failed");
192 goto end_port_iteration;
196 for (Iter it = not_matched_ports.begin(); it != not_matched_ports.end(); ++it) {
197 PortType &port = *it;
198 for (uint32_t j = 0; j < PortType::pin_count; j++) {
199 if (ff_pins->pins[i] == port.pins[j]) {
200 utest_printf(
"%3s - Could not find pins to test %s pin %s (%d)\n",
201 FormFactorType::pin_to_string(ff_pins->pins[i]),
202 PortType::PinMap::pin_type_names[j],
203 FormFactorType::pin_to_string(ff_pins->pins[i]),
205 goto end_port_iteration;
214 template<
typename PortType,
typename FunctionType, FunctionType f>
215 void test_peripheral(PortType &port)
218 utest_printf(
"%d - Could not find pins to test peripheral\n", port.peripheral);
220 utest_printf(
"%d - peripheral tested on port: %s...", port.peripheral, port.str());
221 if (port.status == PortType::StatusNotTested) {
224 port.status = PortType::StatusPass;
226 utest_printf(
"%s\n", port.status == PortType::StatusPass ?
"succeeded" :
"failed");
230 template<
typename PortType,
typename FunctionType, FunctionType f>
231 void test_all_peripherals(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
233 typedef typename std::list<PortType>::iterator Iter;
234 utest_printf(
"***Testing all %s peripherals***\n", PortType::PinMap::name);
236 if (matched_ports.empty() && not_matched_ports.empty()) {
237 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
241 matched_ports.sort(peripheral_less<PortType>);
242 not_matched_ports.sort(peripheral_less<PortType>);
244 for (Iter m_it = matched_ports.begin(), nm_it = not_matched_ports.begin();
245 m_it != matched_ports.end() || nm_it != not_matched_ports.end();) {
246 if (m_it != matched_ports.end() && nm_it != not_matched_ports.end()) {
247 if ((*m_it).peripheral < (*nm_it).peripheral) {
248 test_peripheral<PortType, FunctionType, f>(*m_it);
251 test_peripheral<PortType, FunctionType, f>(*nm_it);
254 }
else if (m_it != matched_ports.end()) {
255 test_peripheral<PortType, FunctionType, f>(*m_it);
257 }
else if (nm_it != not_matched_ports.end()) {
258 test_peripheral<PortType, FunctionType, f>(*nm_it);
275 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
278 std::list<PortType> matched_ports, not_matched_ports;
279 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
280 matched_ports.unique();
281 not_matched_ports.unique();
282 test_all_ports<PortType, FormFactorType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
296 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
297 void all_peripherals()
299 std::list<PortType> matched_ports, not_matched_ports;
300 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
302 matched_ports.sort(peripheral_less<PortType>);
303 not_matched_ports.sort(peripheral_less<PortType>);
304 matched_ports.unique(peripheral_comparator<PortType>);
305 not_matched_ports.unique(peripheral_comparator<PortType>);
307 test_all_peripherals<PortType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
321 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
322 void one_peripheral()
324 #ifdef FPGA_FORCE_ALL_PORTS 325 utest_printf(
"*** FPGA_FORCE_ALL_PORTS ***\n");
326 all_ports<PortType, FormFactorType, f>();
328 std::list<PortType> matched_ports, not_matched_ports;
329 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
331 utest_printf(
"***Testing one %s pin configuration***\n", PortType::PinMap::name);
332 if (matched_ports.empty()) {
333 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
335 test_peripheral<PortType, typename PortType::TestFunctionType, f>(matched_ports.front());
340 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename TestFunctionType>
343 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename TestFunctionType>
347 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
354 static const uint32_t pin_count = N;
355 typedef PinMapType
PinMap;
356 typedef FunctionType TestFunctionType;
358 enum Status { StatusPass, StatusFail, StatusNotTested };
361 Port(): peripheral(NC), status(StatusNotTested)
374 for (uint32_t i = 0; i < N; i++) {
380 void copy_from(
const Port &port)
382 peripheral = port.peripheral;
383 status = port.status;
384 for (uint32_t i = 0; i < N; i++) {
385 pins[i] = port.pins[i];
391 if (peripheral == NC) {
394 for (uint32_t i = 0; i < N; i++) {
404 static char port_str[128];
406 sprintf(port_str,
"peripheral=(%d) ", peripheral);
407 for (uint32_t i = 0; i < N; i++) {
408 sprintf(pin_str,
"%s=(%s) ", PinMap::pin_type_names[i], FormFactorType::pin_to_string(pins[i]));
409 strcat(port_str, pin_str);
417 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
420 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
423 if (port1.peripheral != port2.peripheral) {
426 for (uint32_t i = 0; i < N; i++) {
427 if (port1.pins[i] != port2.pins[i]) {
445 return pinmap_ff_default_pins();
448 static const PinList *restricted_pins()
453 static const char *pin_to_string(PinName pin)
455 return pinmap_ff_default_pin_to_string(pin);
469 static const PinMap *maps[];
470 static const char *
const pin_type_names[];
471 static const char *
const name;
473 const PinMap *GPIOMaps::maps[] = {
gpio_pinmap() };
474 const char *
const GPIOMaps::pin_type_names[] = {
"IO" };
475 const char *
const GPIOMaps::name = GPIO_NAME;
478 #if DEVICE_INTERRUPTIN 479 #include "gpio_irq_api.h" 481 static const PinMap *maps[];
482 static const char *
const pin_type_names[];
483 static const char *
const name;
486 const char *
const GPIOIRQMaps::pin_type_names[] = {
"IRQ_IN" };
487 const char *
const GPIOIRQMaps::name = GPIO_IRQ_NAME;
494 static const PinMap *maps[];
495 static const char *
const pin_type_names[];
496 static const char *
const name;
499 const char *
const SPIMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK",
"SSEL" };
500 const char *
const SPIMaps::name = SPI_NAME;
504 static const PinMap *maps[];
505 static const char *
const pin_type_names[];
506 static const char *
const name;
509 const char *
const SPINoCSMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK" };
510 const char *
const SPINoCSMaps::name = SPI_NAME;
514 static const PinMap *maps[];
515 static const char *
const pin_type_names[];
516 static const char *
const name;
519 const char *
const SPISlaveMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK",
"SSEL" };
520 const char *
const SPISlaveMaps::name = SPISLAVE_NAME;
527 static const PinMap *maps[];
528 static const char *
const pin_type_names[];
529 static const char *
const name;
532 const char *
const I2CMaps::pin_type_names[] = {
"SDA",
"SCL" };
533 const char *
const I2CMaps::name = I2C_NAME;
538 #include "pwmout_api.h" 540 static const PinMap *maps[];
541 static const char *
const pin_type_names[];
542 static const char *
const name;
545 const char *
const PWMMaps::pin_type_names[] = {
"PWM_OUT" };
546 const char *
const PWMMaps::name = PWM_NAME;
551 #include "analogin_api.h" 553 static const PinMap *maps[];
554 static const char *
const pin_type_names[];
555 static const char *
const name;
558 const char *
const AnaloginMaps::pin_type_names[] = {
"ADC_IN" };
559 const char *
const AnaloginMaps::name = ANALOGIN_NAME;
564 #include "analogout_api.h" 566 static const PinMap *maps[];
567 static const char *
const pin_type_names[];
568 static const char *
const name;
571 const char *
const AnalogoutMaps::pin_type_names[] = {
"DAC_OUT" };
572 const char *
const AnalogoutMaps::name = ANALOGOUT_NAME;
578 #include "hal/serial_api.h" 580 static const PinMap *maps[];
581 static const char *
const pin_type_names[];
582 static const char *
const name;
585 const char *
const UARTMaps::pin_type_names[] = {
"TX",
"RX",
"CLS",
"RTS" };
586 const char *
const UARTMaps::name = UART_NAME;
591 static const PinMap *maps[];
592 static const char *
const pin_type_names[];
593 static const char *
const name;
596 const char *
const UARTNoFCMaps::pin_type_names[] = {
"TX",
"RX" };
597 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.