Skip to content

Commit e93cd47

Browse files
authored
Merge branch 'feature-public-headers' into feature-public-headers-cleanup
2 parents 7c0ced2 + 279f4cd commit e93cd47

File tree

101 files changed

+18967
-4675
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+18967
-4675
lines changed

TESTS/mbed_drivers/ticker/main.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ void ticker_callback_1(void)
7171
void ticker_callback_2(void)
7272
{
7373
++callback_trigger_count;
74-
switch_led2_state();
74+
if (LED2 != NC) {
75+
switch_led2_state();
76+
}
7577
}
7678

7779

@@ -110,7 +112,9 @@ void test_case_1x_ticker()
110112
Ticker ticker;
111113

112114
led1 = 1;
113-
led2 = 1;
115+
if (LED2 != NC) {
116+
led2 = 1;
117+
}
114118
callback_trigger_count = 0;
115119

116120
greentea_send_kv("timing_drift_check_start", 0);
@@ -151,7 +155,9 @@ void test_case_2x_ticker()
151155
Ticker ticker1, ticker2;
152156

153157
led1 = 0;
154-
led2 = 1;
158+
if (LED2 != NC) {
159+
led2 = 1;
160+
}
155161
callback_trigger_count = 0;
156162

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

0 commit comments

Comments
 (0)