Skip to content

Bring FPGA-Test-Shield tests into Mbed-os master. #10820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions TESTS/mbed_hal_fpga_ci_test_shield/analogin/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if !DEVICE_ANALOGIN
#error [NOT_SUPPORTED] Analog in not supported for this target
#elif !COMPONENT_FPGA_CI_TEST_SHIELD
#error [NOT_SUPPORTED] FPGA CI Test Shield is needed to run this test
#else

#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"

#include "mbed.h"
#include "pinmap.h"
#include "test_utils.h"
#include "MbedTester.h"

using namespace utest::v1;

#define analogin_debug_printf(...)

#define DELTA_FLOAT 0.03f // 3%
#define DELTA_U16 1965 // 3%

const PinList *form_factor = pinmap_ff_default_pins();
const PinList *restricted = pinmap_restricted_pins();

MbedTester tester(form_factor, restricted);

void analogin_init(PinName pin)
{
analogin_t analogin;

analogin_init(&analogin, pin);
}

void analogin_test(PinName pin)
{
tester.reset();
tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0);
tester.select_peripheral(MbedTester::PeripheralGPIO);

/* Test analog input */

analogin_t analogin;
analogin_init(&analogin, pin);

tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, 1.0f, analogin_read(&analogin));
TEST_ASSERT_UINT16_WITHIN(DELTA_U16, 65535, analogin_read_u16(&analogin));

tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, 0.0f, analogin_read(&analogin));
TEST_ASSERT_UINT16_WITHIN(DELTA_U16, 0, analogin_read_u16(&analogin));

/* Set gpio back to Hi-Z */
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
}

Case cases[] = {
// This will be run for all pins
Case("AnalogIn - init test", all_ports<AnaloginPort, DefaultFormFactor, analogin_init>),
// This will be run for single pin
Case("AnalogIn - read test", all_ports<AnaloginPort, DefaultFormFactor, analogin_test>),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(120, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}

Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);

int main()
{
Harness::run(specification);
}

#endif /* !DEVICE_ANALOGIN */
131 changes: 131 additions & 0 deletions TESTS/mbed_hal_fpga_ci_test_shield/analogout/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if !DEVICE_ANALOGOUT
#error [NOT_SUPPORTED] Analog out not supported for this target
#elif !COMPONENT_FPGA_CI_TEST_SHIELD
#error [NOT_SUPPORTED] FPGA CI Test Shield is needed to run this test
#else

#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include <inttypes.h>
#include "mbed.h"

using namespace utest::v1;

#include "MbedTester.h"
#include "pinmap.h"
#include "test_utils.h"

#if !DEVICE_ANALOGOUT
#error [NOT_SUPPORTED] Analog out not supported for this target
#endif

#define analogout_debug_printf(...)

#define DELTA_FLOAT 0.03f // 3%

/* Enable for power analysis */
#define DEBUG 0

const PinList *form_factor = pinmap_ff_default_pins();
const PinList *restricted = pinmap_restricted_pins();

MbedTester tester(form_factor, restricted);

void analogout_init_free(PinName pin)
{
dac_t analogout;

analogout_debug_printf("Analog output init/free test on pin=%s (%i)\r\n", pinmap_ff_default_pin_to_string(pin), pin);

analogout_init(&analogout, pin);
analogout_free(&analogout);
}

void analogout_test(PinName pin)
{
analogout_debug_printf("Analog input test on pin %s (%i)\r\n", pinmap_ff_default_pin_to_string(pin), pin);

tester.reset();
tester.peripherals_reset();

/* Test analog input */

dac_t analogout;
analogout_init(&analogout, pin);

tester.set_sample_adc(true);//begin ADC sampling on the FPGA

float anin;
float i;
for (i = 0.0f; i < 0.304f; i += 0.0303f) {//0V-1V, float
analogout_write(&analogout, i);
anin = tester.get_analog_in();
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, (i * 3.3f), anin);
}

i = 0.0f;
for (uint16_t i_d16 = 0; i_d16 < 19851; i_d16 += 1985) {//0V-1V, 16-bit
analogout_write_u16(&analogout, i_d16);
anin = tester.get_analog_in();
TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, (i * 3.3f), anin);
i += 0.0303f;
}

analogout_free(&analogout);

tester.set_sample_adc(false);//stop ADC sampling on the FPGA

#if DEBUG
// power analysis
uint64_t sum;
uint32_t samples;
uint64_t cycles;
tester.get_anin_sum_samples_cycles(0, &sum, &samples, &cycles);
printf("ANIN0\r\n");
printf("Sum: %llu\r\n", sum);
printf("Num power samples: %d\r\n", samples);
printf("Num power cycles: %llu\r\n", cycles);
printf("ANIN0 voltage: %.6fV\r\n", tester.get_anin_voltage(0));
#endif
}

Case cases[] = {
// This will be run for all pins
Case("Analogout - init test", all_ports<AnalogoutPort, DefaultFormFactor, analogout_init_free>),

// This will be run for single pin
Case("Analogout - write/read test", all_ports<AnalogoutPort, DefaultFormFactor, analogout_test>),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(120, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}

Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);

int main()
{
Harness::run(specification);
}

#endif /* !DEVICE_ANALOGOUT */
112 changes: 112 additions & 0 deletions TESTS/mbed_hal_fpga_ci_test_shield/gpio/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if !COMPONENT_FPGA_CI_TEST_SHIELD
#error [NOT_SUPPORTED] FPGA CI Test Shield is needed to run this test
#else

#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "mbed.h"

using namespace utest::v1;

#include "MbedTester.h"
#include "pinmap.h"

const PinList *form_factor = pinmap_ff_default_pins();
const PinList *restricted = pinmap_restricted_pins();
MbedTester tester(form_factor, restricted);

void gpio_inout_test(PinName pin)
{
gpio_t gpio;
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 0);
TEST_ASSERT_EQUAL(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));

/* Test GPIO output */

gpio_write(&gpio, 1);
TEST_ASSERT_EQUAL(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));

gpio_write(&gpio, 0);
TEST_ASSERT_EQUAL(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));

gpio_dir(&gpio, PIN_INPUT);

/* Test GPIO input */

tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
TEST_ASSERT_EQUAL(0, gpio_read(&gpio));

tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
TEST_ASSERT_EQUAL(1, gpio_read(&gpio));

/* Set gpio back to Hi-Z */

tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
}

void gpio_inout_test()
{
for (int i = 0; i < form_factor->count; i++) {
const PinName test_pin = form_factor->pins[i];
if (pinmap_list_has_pin(restricted, test_pin)) {
printf("Skipping gpio pin %s (%i)\r\n", pinmap_ff_default_pin_to_string(test_pin), test_pin);
continue;
}
tester.pin_map_reset();
tester.pin_map_set(test_pin, MbedTester::LogicalPinGPIO0);

printf("GPIO test on pin %s (%i)\r\n", pinmap_ff_default_pin_to_string(test_pin), test_pin);
gpio_inout_test(test_pin);
}
}

utest::v1::status_t setup(const Case *const source, const size_t index_of_case)
{
tester.reset();
tester.select_peripheral(MbedTester::PeripheralGPIO);

return greentea_case_setup_handler(source, index_of_case);
}

utest::v1::status_t teardown(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason)
{
return greentea_case_teardown_handler(source, passed, failed, reason);
}

Case cases[] = {
Case("GPIO - inout", setup, gpio_inout_test, teardown),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(60, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}

Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);

int main()
{
Harness::run(specification);
}

#endif /* !COMPONENT_FPGA_CI_TEST_SHIELD */
Loading