Skip to content

Commit c709955

Browse files
authored
Merge pull request #10820 from mprse/bring_fpga_tests_master
Bring FPGA-Test-Shield tests into Mbed-os master.
2 parents d2e5941 + d2d3d5f commit c709955

File tree

8 files changed

+1768
-0
lines changed

8 files changed

+1768
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2019, Arm Limited and affiliates.
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+
18+
#if !DEVICE_ANALOGIN
19+
#error [NOT_SUPPORTED] Analog in not supported for this target
20+
#elif !COMPONENT_FPGA_CI_TEST_SHIELD
21+
#error [NOT_SUPPORTED] FPGA CI Test Shield is needed to run this test
22+
#else
23+
24+
#include "utest/utest.h"
25+
#include "unity/unity.h"
26+
#include "greentea-client/test_env.h"
27+
28+
#include "mbed.h"
29+
#include "pinmap.h"
30+
#include "test_utils.h"
31+
#include "MbedTester.h"
32+
33+
using namespace utest::v1;
34+
35+
#define analogin_debug_printf(...)
36+
37+
#define DELTA_FLOAT 0.03f // 3%
38+
#define DELTA_U16 1965 // 3%
39+
40+
const PinList *form_factor = pinmap_ff_default_pins();
41+
const PinList *restricted = pinmap_restricted_pins();
42+
43+
MbedTester tester(form_factor, restricted);
44+
45+
void analogin_init(PinName pin)
46+
{
47+
analogin_t analogin;
48+
49+
analogin_init(&analogin, pin);
50+
}
51+
52+
void analogin_test(PinName pin)
53+
{
54+
tester.reset();
55+
tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0);
56+
tester.select_peripheral(MbedTester::PeripheralGPIO);
57+
58+
/* Test analog input */
59+
60+
analogin_t analogin;
61+
analogin_init(&analogin, pin);
62+
63+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
64+
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, 1.0f, analogin_read(&analogin));
65+
TEST_ASSERT_UINT16_WITHIN(DELTA_U16, 65535, analogin_read_u16(&analogin));
66+
67+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
68+
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, 0.0f, analogin_read(&analogin));
69+
TEST_ASSERT_UINT16_WITHIN(DELTA_U16, 0, analogin_read_u16(&analogin));
70+
71+
/* Set gpio back to Hi-Z */
72+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
73+
}
74+
75+
Case cases[] = {
76+
// This will be run for all pins
77+
Case("AnalogIn - init test", all_ports<AnaloginPort, DefaultFormFactor, analogin_init>),
78+
// This will be run for single pin
79+
Case("AnalogIn - read test", all_ports<AnaloginPort, DefaultFormFactor, analogin_test>),
80+
};
81+
82+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
83+
{
84+
GREENTEA_SETUP(120, "default_auto");
85+
return greentea_test_setup_handler(number_of_cases);
86+
}
87+
88+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
89+
90+
int main()
91+
{
92+
Harness::run(specification);
93+
}
94+
95+
#endif /* !DEVICE_ANALOGIN */
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2019, Arm Limited and affiliates.
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+
18+
#if !DEVICE_ANALOGOUT
19+
#error [NOT_SUPPORTED] Analog out not supported for this target
20+
#elif !COMPONENT_FPGA_CI_TEST_SHIELD
21+
#error [NOT_SUPPORTED] FPGA CI Test Shield is needed to run this test
22+
#else
23+
24+
#include "utest/utest.h"
25+
#include "unity/unity.h"
26+
#include "greentea-client/test_env.h"
27+
#include <inttypes.h>
28+
#include "mbed.h"
29+
30+
using namespace utest::v1;
31+
32+
#include "MbedTester.h"
33+
#include "pinmap.h"
34+
#include "test_utils.h"
35+
36+
#if !DEVICE_ANALOGOUT
37+
#error [NOT_SUPPORTED] Analog out not supported for this target
38+
#endif
39+
40+
#define analogout_debug_printf(...)
41+
42+
#define DELTA_FLOAT 0.03f // 3%
43+
44+
/* Enable for power analysis */
45+
#define DEBUG 0
46+
47+
const PinList *form_factor = pinmap_ff_default_pins();
48+
const PinList *restricted = pinmap_restricted_pins();
49+
50+
MbedTester tester(form_factor, restricted);
51+
52+
void analogout_init_free(PinName pin)
53+
{
54+
dac_t analogout;
55+
56+
analogout_debug_printf("Analog output init/free test on pin=%s (%i)\r\n", pinmap_ff_default_pin_to_string(pin), pin);
57+
58+
analogout_init(&analogout, pin);
59+
analogout_free(&analogout);
60+
}
61+
62+
void analogout_test(PinName pin)
63+
{
64+
analogout_debug_printf("Analog input test on pin %s (%i)\r\n", pinmap_ff_default_pin_to_string(pin), pin);
65+
66+
tester.reset();
67+
tester.peripherals_reset();
68+
69+
/* Test analog input */
70+
71+
dac_t analogout;
72+
analogout_init(&analogout, pin);
73+
74+
tester.set_sample_adc(true);//begin ADC sampling on the FPGA
75+
76+
float anin;
77+
float i;
78+
for (i = 0.0f; i < 0.304f; i += 0.0303f) {//0V-1V, float
79+
analogout_write(&analogout, i);
80+
anin = tester.get_analog_in();
81+
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, (i * 3.3f), anin);
82+
}
83+
84+
i = 0.0f;
85+
for (uint16_t i_d16 = 0; i_d16 < 19851; i_d16 += 1985) {//0V-1V, 16-bit
86+
analogout_write_u16(&analogout, i_d16);
87+
anin = tester.get_analog_in();
88+
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, (i * 3.3f), anin);
89+
i += 0.0303f;
90+
}
91+
92+
analogout_free(&analogout);
93+
94+
tester.set_sample_adc(false);//stop ADC sampling on the FPGA
95+
96+
#if DEBUG
97+
// power analysis
98+
uint64_t sum;
99+
uint32_t samples;
100+
uint64_t cycles;
101+
tester.get_anin_sum_samples_cycles(0, &sum, &samples, &cycles);
102+
printf("ANIN0\r\n");
103+
printf("Sum: %llu\r\n", sum);
104+
printf("Num power samples: %d\r\n", samples);
105+
printf("Num power cycles: %llu\r\n", cycles);
106+
printf("ANIN0 voltage: %.6fV\r\n", tester.get_anin_voltage(0));
107+
#endif
108+
}
109+
110+
Case cases[] = {
111+
// This will be run for all pins
112+
Case("Analogout - init test", all_ports<AnalogoutPort, DefaultFormFactor, analogout_init_free>),
113+
114+
// This will be run for single pin
115+
Case("Analogout - write/read test", all_ports<AnalogoutPort, DefaultFormFactor, analogout_test>),
116+
};
117+
118+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
119+
{
120+
GREENTEA_SETUP(120, "default_auto");
121+
return greentea_test_setup_handler(number_of_cases);
122+
}
123+
124+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
125+
126+
int main()
127+
{
128+
Harness::run(specification);
129+
}
130+
131+
#endif /* !DEVICE_ANALOGOUT */
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2019, Arm Limited and affiliates.
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+
18+
#if !COMPONENT_FPGA_CI_TEST_SHIELD
19+
#error [NOT_SUPPORTED] FPGA CI Test Shield is needed to run this test
20+
#else
21+
22+
#include "utest/utest.h"
23+
#include "unity/unity.h"
24+
#include "greentea-client/test_env.h"
25+
#include "mbed.h"
26+
27+
using namespace utest::v1;
28+
29+
#include "MbedTester.h"
30+
#include "pinmap.h"
31+
32+
const PinList *form_factor = pinmap_ff_default_pins();
33+
const PinList *restricted = pinmap_restricted_pins();
34+
MbedTester tester(form_factor, restricted);
35+
36+
void gpio_inout_test(PinName pin)
37+
{
38+
gpio_t gpio;
39+
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 0);
40+
TEST_ASSERT_EQUAL(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
41+
42+
/* Test GPIO output */
43+
44+
gpio_write(&gpio, 1);
45+
TEST_ASSERT_EQUAL(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
46+
47+
gpio_write(&gpio, 0);
48+
TEST_ASSERT_EQUAL(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
49+
50+
gpio_dir(&gpio, PIN_INPUT);
51+
52+
/* Test GPIO input */
53+
54+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
55+
TEST_ASSERT_EQUAL(0, gpio_read(&gpio));
56+
57+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
58+
TEST_ASSERT_EQUAL(1, gpio_read(&gpio));
59+
60+
/* Set gpio back to Hi-Z */
61+
62+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
63+
}
64+
65+
void gpio_inout_test()
66+
{
67+
for (int i = 0; i < form_factor->count; i++) {
68+
const PinName test_pin = form_factor->pins[i];
69+
if (pinmap_list_has_pin(restricted, test_pin)) {
70+
printf("Skipping gpio pin %s (%i)\r\n", pinmap_ff_default_pin_to_string(test_pin), test_pin);
71+
continue;
72+
}
73+
tester.pin_map_reset();
74+
tester.pin_map_set(test_pin, MbedTester::LogicalPinGPIO0);
75+
76+
printf("GPIO test on pin %s (%i)\r\n", pinmap_ff_default_pin_to_string(test_pin), test_pin);
77+
gpio_inout_test(test_pin);
78+
}
79+
}
80+
81+
utest::v1::status_t setup(const Case *const source, const size_t index_of_case)
82+
{
83+
tester.reset();
84+
tester.select_peripheral(MbedTester::PeripheralGPIO);
85+
86+
return greentea_case_setup_handler(source, index_of_case);
87+
}
88+
89+
utest::v1::status_t teardown(const Case *const source, const size_t passed, const size_t failed,
90+
const failure_t reason)
91+
{
92+
return greentea_case_teardown_handler(source, passed, failed, reason);
93+
}
94+
95+
Case cases[] = {
96+
Case("GPIO - inout", setup, gpio_inout_test, teardown),
97+
};
98+
99+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
100+
{
101+
GREENTEA_SETUP(60, "default_auto");
102+
return greentea_test_setup_handler(number_of_cases);
103+
}
104+
105+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
106+
107+
int main()
108+
{
109+
Harness::run(specification);
110+
}
111+
112+
#endif /* !COMPONENT_FPGA_CI_TEST_SHIELD */

0 commit comments

Comments
 (0)