Skip to content

Commit d3500b1

Browse files
author
Chris Trowbridge
committed
Merge remote-tracking branch 'upstream/master'
2 parents 3778424 + 7d15882 commit d3500b1

File tree

16 files changed

+405
-205
lines changed

16 files changed

+405
-205
lines changed

TESTS/mbed_hal_fpga_ci_test_shield/gpio/main.cpp

Lines changed: 165 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,75 +30,199 @@ using namespace utest::v1;
3030

3131
#include "MbedTester.h"
3232
#include "pinmap.h"
33+
#include "test_utils.h"
3334

34-
const PinList *form_factor = pinmap_ff_default_pins();
35-
const PinList *restricted = pinmap_restricted_pins();
36-
MbedTester tester(form_factor, restricted);
35+
// This delay is used when reading a floating input that has an internal pull-up
36+
// or pull-down resistor. The voltage response is much slower when the input
37+
// is not driven externally.
38+
#define HI_Z_READ_DELAY_US 5
3739

38-
void gpio_inout_test(PinName pin)
40+
MbedTester tester(DefaultFormFactor::pins(), DefaultFormFactor::restricted_pins());
41+
42+
/* Test basic input & output operations.
43+
*
44+
* Given a GPIO instance initialized with a generic gpio_init() function,
45+
* when basic input and output operations are performed,
46+
* then all operations succeed.
47+
*/
48+
void test_basic_input_output(PinName pin)
3949
{
40-
gpio_t gpio;
41-
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 0);
42-
TEST_ASSERT_EQUAL(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
50+
// Reset everything and set all tester pins to hi-Z.
51+
tester.reset();
4352

44-
/* Test GPIO output */
53+
// Map pins for test.
54+
tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0);
4555

46-
gpio_write(&gpio, 1);
47-
TEST_ASSERT_EQUAL(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
56+
// Select GPIO0.
57+
tester.select_peripheral(MbedTester::PeripheralGPIO);
4858

49-
gpio_write(&gpio, 0);
50-
TEST_ASSERT_EQUAL(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
59+
// Initialize GPIO pin with a generic init fun.
60+
gpio_t gpio;
61+
// Test gpio_is_connected() returned value.
62+
gpio_init(&gpio, NC);
63+
TEST_ASSERT_EQUAL_INT(0, gpio_is_connected(&gpio));
64+
gpio_init(&gpio, pin);
65+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
5166

67+
// Test GPIO used as an input.
5268
gpio_dir(&gpio, PIN_INPUT);
5369

54-
/* Test GPIO input */
55-
70+
// Test input, pull-up mode.
71+
gpio_mode(&gpio, PullUp);
72+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
73+
wait_us(HI_Z_READ_DELAY_US);
74+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
5675
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
57-
TEST_ASSERT_EQUAL(0, gpio_read(&gpio));
76+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio));
77+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
78+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio));
79+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
80+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio));
81+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
82+
wait_us(HI_Z_READ_DELAY_US);
83+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
5884

85+
// Test input, pull-down mode.
86+
gpio_mode(&gpio, PullDown);
87+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
88+
wait_us(HI_Z_READ_DELAY_US);
89+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
5990
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
60-
TEST_ASSERT_EQUAL(1, gpio_read(&gpio));
91+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio));
92+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
93+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio));
94+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
95+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio));
96+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
97+
wait_us(HI_Z_READ_DELAY_US);
98+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
6199

62-
/* Set gpio back to Hi-Z */
100+
// Test input, pull-none mode.
101+
gpio_mode(&gpio, PullNone);
102+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
103+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio));
104+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, true);
105+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio));
106+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true);
107+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio));
63108

109+
// Test GPIO used as an output.
64110
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
111+
gpio_dir(&gpio, PIN_OUTPUT);
112+
gpio_write(&gpio, 0);
113+
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
114+
gpio_write(&gpio, 1);
115+
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
116+
gpio_write(&gpio, 0);
117+
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
65118
}
66119

67-
void gpio_inout_test()
120+
/* Test explicit input initialization.
121+
*
122+
* Given a GPIO instance,
123+
* when additional parameters are passed to the input init function,
124+
* then the GPIO is correctly initialized as an input.
125+
*/
126+
void test_explicit_input(PinName pin)
68127
{
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-
}
128+
// Reset everything and set all tester pins to hi-Z.
129+
tester.reset();
130+
131+
// Map pins for test.
132+
tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0);
133+
134+
// Select GPIO0.
135+
tester.select_peripheral(MbedTester::PeripheralGPIO);
136+
137+
gpio_t gpio;
138+
139+
// Initialize GPIO pin as an input, pull-up mode.
140+
memset(&gpio, 0, sizeof gpio);
141+
gpio_init_in_ex(&gpio, pin, PullUp);
142+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
143+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
144+
wait_us(HI_Z_READ_DELAY_US);
145+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
146+
147+
// Initialize GPIO pin as an input, pull-down mode.
148+
memset(&gpio, 0, sizeof gpio);
149+
gpio_init_in_ex(&gpio, pin, PullDown);
150+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
151+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
152+
wait_us(HI_Z_READ_DELAY_US);
153+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
154+
155+
// Initialize GPIO pin as an input, pull-up mode.
156+
memset(&gpio, 0, sizeof gpio);
157+
gpio_init_inout(&gpio, pin, PIN_INPUT, PullUp, 0);
158+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
159+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
160+
wait_us(HI_Z_READ_DELAY_US);
161+
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
162+
163+
// Initialize GPIO pin as an input, pull-down mode.
164+
memset(&gpio, 0, sizeof gpio);
165+
gpio_init_inout(&gpio, pin, PIN_INPUT, PullDown, 0);
166+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
167+
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
168+
wait_us(HI_Z_READ_DELAY_US);
169+
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
84170
}
85171

86-
utest::v1::status_t setup(const Case *const source, const size_t index_of_case)
172+
/* Test explicit output initialization.
173+
*
174+
* Given a GPIO instance,
175+
* when additional parameters are passed to the output init function,
176+
* then the GPIO is correctly initialized as an output.
177+
*/
178+
void test_explicit_output(PinName pin)
87179
{
180+
// Reset everything and set all tester pins to hi-Z.
88181
tester.reset();
182+
183+
// Map pins for test.
184+
tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0);
185+
186+
// Select GPIO0.
89187
tester.select_peripheral(MbedTester::PeripheralGPIO);
90188

91-
return greentea_case_setup_handler(source, index_of_case);
92-
}
189+
gpio_t gpio;
93190

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);
191+
// Initialize GPIO pin as an output, output value = 0.
192+
memset(&gpio, 0, sizeof gpio);
193+
gpio_init_out(&gpio, pin);
194+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
195+
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
196+
197+
// Initialize GPIO pin as an output, output value = 1.
198+
memset(&gpio, 0, sizeof gpio);
199+
gpio_init_out_ex(&gpio, pin, 1);
200+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
201+
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
202+
203+
// Initialize GPIO pin as an output, output value = 0.
204+
memset(&gpio, 0, sizeof gpio);
205+
gpio_init_out_ex(&gpio, pin, 0);
206+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
207+
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
208+
209+
// Initialize GPIO pin as an output, output value = 1.
210+
memset(&gpio, 0, sizeof gpio);
211+
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 1);
212+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
213+
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
214+
215+
// Initialize GPIO pin as an output, output value = 0.
216+
memset(&gpio, 0, sizeof gpio);
217+
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 0);
218+
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
219+
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
98220
}
99221

100222
Case cases[] = {
101-
Case("GPIO - inout", setup, gpio_inout_test, teardown),
223+
Case("generic init, input & output", all_ports<GPIOPort, DefaultFormFactor, test_basic_input_output>),
224+
Case("explicit init, input", all_ports<GPIOPort, DefaultFormFactor, test_explicit_input>),
225+
Case("explicit init, output", all_ports<GPIOPort, DefaultFormFactor, test_explicit_output>),
102226
};
103227

104228
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ class DefaultFormFactor {
430430
* pin set to use for testing.
431431
*/
432432

433+
struct GPIOMaps {
434+
static const PinMap *maps[];
435+
static const char *const pin_type_names[];
436+
static const char *const name;
437+
};
438+
const PinMap *GPIOMaps::maps[] = { gpio_pinmap() };
439+
const char *const GPIOMaps::pin_type_names[] = { "IO" };
440+
const char *const GPIOMaps::name = "GPIO";
441+
typedef Port<1, GPIOMaps, DefaultFormFactor, TF1> GPIOPort;
442+
433443
#if DEVICE_SPI
434444
#include "spi_api.h"
435445
struct SPIMaps {

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,7 @@ void AT_CellularContext::check_and_deactivate_context()
741741
}
742742

743743
if (_new_context_set) {
744-
_at.clear_error();
745-
_at.at_cmd_discard("+CGDCONT", "=", "%d", _cid);
744+
delete_current_context();
746745
}
747746

748747
_at.restore_at_timeout();

features/frameworks/greentea-client/greentea-client/greentea_serial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#ifndef GREENTEA_SERIAL_H
55
#define GREENTEA_SERIAL_H
66

7+
#if DEVICE_SERIAL
8+
79
#include "RawSerial.h"
810
#include "SingletonPtr.h"
911

@@ -16,3 +18,4 @@ extern SingletonPtr<GreenteaSerial> greentea_serial;
1618
#endif
1719

1820
/** @}*/
21+
#endif

features/frameworks/greentea-client/source/greentea_serial.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "greentea-client/greentea_serial.h"
22

3+
#if DEVICE_SERIAL
4+
35
/**
46
* Macros for setting console flow control.
57
*/
@@ -21,3 +23,5 @@ GreenteaSerial::GreenteaSerial() : mbed::RawSerial(USBTX, USBRX, MBED_CONF_PLATF
2123
set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS);
2224
#endif
2325
}
26+
27+
#endif

features/frameworks/greentea-client/source/greentea_test_env.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
#if DEVICE_SERIAL
19+
1820
#include <ctype.h>
1921
#include <cstdio>
2022
#include <string.h>
@@ -780,3 +782,5 @@ static int HandleKV(char *out_key,
780782
getNextToken(0, 0);
781783
return 0;
782784
}
785+
786+
#endif

features/frameworks/utest/source/unity_handler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
#include "utest/utest_harness.h"
2020
#include "utest/utest_stack_trace.h"
2121
#include "utest/unity_handler.h"
22+
23+
#if DEVICE_SERIAL
2224
#include "greentea-client/greentea_serial.h"
25+
#endif
2326

2427
void utest_unity_assert_failure(void)
2528
{
@@ -33,9 +36,10 @@ void utest_unity_ignore_failure(void)
3336
utest::v1::Harness::raise_failure(utest::v1::failure_reason_t(utest::v1::REASON_ASSERTION | utest::v1::REASON_IGNORE));
3437
}
3538

39+
#if DEVICE_SERIAL
3640
void utest_safe_putc(int chr)
3741
{
3842
greentea_serial->putc(chr);
3943
}
40-
44+
#endif
4145

features/frameworks/utest/source/utest_default_handlers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
****************************************************************************
1717
*/
1818

19+
#if DEVICE_SERIAL
20+
1921
#include "utest/utest_default_handlers.h"
2022
#include "utest/utest_case.h"
2123
#include "utest/utest_stack_trace.h"
@@ -102,3 +104,5 @@ utest::v1::status_t utest::v1::verbose_case_failure_handler(const Case *const /*
102104
if (failure.reason & REASON_IGNORE) return STATUS_IGNORE;
103105
return STATUS_CONTINUE;
104106
}
107+
108+
#endif

features/frameworks/utest/utest/utest_serial.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
****************************************************************************
2020
*/
2121

22+
#if DEVICE_SERIAL
23+
2224
#ifndef UTEST_SERIAL_H
2325
#define UTEST_SERIAL_H
2426

@@ -29,3 +31,5 @@
2931
#endif // UTEST_SERIAL_H
3032

3133
/** @}*/
34+
35+
#endif

0 commit comments

Comments
 (0)