25
25
#include " unity/unity.h"
26
26
#include " greentea-client/test_env.h"
27
27
#include " mbed.h"
28
-
29
- using namespace utest ::v1;
30
-
31
28
#include " MbedTester.h"
32
29
#include " pinmap.h"
33
30
#include " test_utils.h"
31
+ #include " gpio_fpga_test.h"
32
+
33
+ using namespace utest ::v1;
34
34
35
35
// This delay is used when reading a floating input that has an internal pull-up
36
36
// or pull-down resistor. The voltage response is much slower when the input
@@ -45,7 +45,7 @@ MbedTester tester(DefaultFormFactor::pins(), DefaultFormFactor::restricted_pins(
45
45
* when basic input and output operations are performed,
46
46
* then all operations succeed.
47
47
*/
48
- void test_basic_input_output (PinName pin)
48
+ void fpga_test_basic_input_output (PinName pin)
49
49
{
50
50
// Reset everything and set all tester pins to hi-Z.
51
51
tester.reset ();
@@ -61,6 +61,7 @@ void test_basic_input_output(PinName pin)
61
61
// Test gpio_is_connected() returned value.
62
62
gpio_init (&gpio, NC);
63
63
TEST_ASSERT_EQUAL_INT (0 , gpio_is_connected (&gpio));
64
+ gpio_free (&gpio);
64
65
gpio_init (&gpio, pin);
65
66
TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
66
67
@@ -120,6 +121,8 @@ void test_basic_input_output(PinName pin)
120
121
TEST_ASSERT_EQUAL_INT (1 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
121
122
gpio_write (&gpio, 0 );
122
123
TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
124
+
125
+ gpio_free (&gpio);
123
126
}
124
127
125
128
/* Test explicit input initialization.
@@ -128,7 +131,7 @@ void test_basic_input_output(PinName pin)
128
131
* when additional parameters are passed to the input init function,
129
132
* then the GPIO is correctly initialized as an input.
130
133
*/
131
- void test_explicit_input (PinName pin)
134
+ void fpga_test_explicit_input (PinName pin)
132
135
{
133
136
// Reset everything and set all tester pins to hi-Z.
134
137
tester.reset ();
@@ -148,6 +151,7 @@ void test_explicit_input(PinName pin)
148
151
tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
149
152
wait_us (HI_Z_READ_DELAY_US);
150
153
TEST_ASSERT_EQUAL_INT (1 , gpio_read (&gpio)); // hi-Z, pulled up
154
+ gpio_free (&gpio);
151
155
152
156
// Initialize GPIO pin as an input, pull-down mode.
153
157
memset (&gpio, 0 , sizeof gpio);
@@ -156,6 +160,7 @@ void test_explicit_input(PinName pin)
156
160
tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
157
161
wait_us (HI_Z_READ_DELAY_US);
158
162
TEST_ASSERT_EQUAL_INT (0 , gpio_read (&gpio)); // hi-Z, pulled down
163
+ gpio_free (&gpio);
159
164
160
165
// Initialize GPIO pin as an input, pull-up mode.
161
166
memset (&gpio, 0 , sizeof gpio);
@@ -164,6 +169,7 @@ void test_explicit_input(PinName pin)
164
169
tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
165
170
wait_us (HI_Z_READ_DELAY_US);
166
171
TEST_ASSERT_EQUAL_INT (1 , gpio_read (&gpio)); // hi-Z, pulled up
172
+ gpio_free (&gpio);
167
173
168
174
// Initialize GPIO pin as an input, pull-down mode.
169
175
memset (&gpio, 0 , sizeof gpio);
@@ -172,6 +178,7 @@ void test_explicit_input(PinName pin)
172
178
tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
173
179
wait_us (HI_Z_READ_DELAY_US);
174
180
TEST_ASSERT_EQUAL_INT (0 , gpio_read (&gpio)); // hi-Z, pulled down
181
+ gpio_free (&gpio);
175
182
}
176
183
177
184
/* Test explicit output initialization.
@@ -180,7 +187,7 @@ void test_explicit_input(PinName pin)
180
187
* when additional parameters are passed to the output init function,
181
188
* then the GPIO is correctly initialized as an output.
182
189
*/
183
- void test_explicit_output (PinName pin)
190
+ void fpga_test_explicit_output (PinName pin)
184
191
{
185
192
// Reset everything and set all tester pins to hi-Z.
186
193
tester.reset ();
@@ -198,41 +205,46 @@ void test_explicit_output(PinName pin)
198
205
gpio_init_out (&gpio, pin);
199
206
TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
200
207
TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
208
+ gpio_free (&gpio);
201
209
202
210
// Initialize GPIO pin as an output, output value = 1.
203
211
memset (&gpio, 0 , sizeof gpio);
204
212
gpio_init_out_ex (&gpio, pin, 1 );
205
213
TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
206
214
TEST_ASSERT_EQUAL_INT (1 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
215
+ gpio_free (&gpio);
207
216
208
217
// Initialize GPIO pin as an output, output value = 0.
209
218
memset (&gpio, 0 , sizeof gpio);
210
219
gpio_init_out_ex (&gpio, pin, 0 );
211
220
TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
212
221
TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
222
+ gpio_free (&gpio);
213
223
214
224
// Initialize GPIO pin as an output, output value = 1.
215
225
memset (&gpio, 0 , sizeof gpio);
216
226
gpio_init_inout (&gpio, pin, PIN_OUTPUT, PullNone, 1 );
217
227
TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
218
228
TEST_ASSERT_EQUAL_INT (1 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
229
+ gpio_free (&gpio);
219
230
220
231
// Initialize GPIO pin as an output, output value = 0.
221
232
memset (&gpio, 0 , sizeof gpio);
222
233
gpio_init_inout (&gpio, pin, PIN_OUTPUT, PullNone, 0 );
223
234
TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
224
235
TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
236
+ gpio_free (&gpio);
225
237
}
226
238
227
239
Case cases[] = {
228
- Case (" generic init, input & output" , all_ports<GPIOPort, DefaultFormFactor, test_basic_input_output >),
240
+ Case (" generic init, input & output" , all_ports<GPIOPort, DefaultFormFactor, fpga_test_basic_input_output >),
229
241
// Some targets don't support input pull mode.
230
242
#if !defined(TARGET_NANO100) && \
231
243
!defined (TARGET_NUC472) && \
232
244
!defined (TARGET_M451)
233
- Case (" explicit init, input" , all_ports<GPIOPort, DefaultFormFactor, test_explicit_input >),
245
+ Case (" explicit init, input" , all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_input >),
234
246
#endif
235
- Case (" explicit init, output" , all_ports<GPIOPort, DefaultFormFactor, test_explicit_output >),
247
+ Case (" explicit init, output" , all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_output >),
236
248
};
237
249
238
250
utest::v1::status_t greentea_test_setup (const size_t number_of_cases)
0 commit comments