2525#include " unity/unity.h"
2626#include " greentea-client/test_env.h"
2727#include " mbed.h"
28-
29- using namespace utest ::v1;
30-
3128#include " MbedTester.h"
3229#include " pinmap.h"
3330#include " test_utils.h"
31+ #include " gpio_fpga_test.h"
32+
33+ using namespace utest ::v1;
3434
3535// This delay is used when reading a floating input that has an internal pull-up
3636// or pull-down resistor. The voltage response is much slower when the input
@@ -45,7 +45,7 @@ MbedTester tester(DefaultFormFactor::pins(), DefaultFormFactor::restricted_pins(
4545 * when basic input and output operations are performed,
4646 * then all operations succeed.
4747 */
48- void test_basic_input_output (PinName pin)
48+ void fpga_test_basic_input_output (PinName pin)
4949{
5050 // Reset everything and set all tester pins to hi-Z.
5151 tester.reset ();
@@ -61,6 +61,7 @@ void test_basic_input_output(PinName pin)
6161 // Test gpio_is_connected() returned value.
6262 gpio_init (&gpio, NC);
6363 TEST_ASSERT_EQUAL_INT (0 , gpio_is_connected (&gpio));
64+ gpio_free (&gpio);
6465 gpio_init (&gpio, pin);
6566 TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
6667
@@ -120,6 +121,8 @@ void test_basic_input_output(PinName pin)
120121 TEST_ASSERT_EQUAL_INT (1 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
121122 gpio_write (&gpio, 0 );
122123 TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
124+
125+ gpio_free (&gpio);
123126}
124127
125128/* Test explicit input initialization.
@@ -128,7 +131,7 @@ void test_basic_input_output(PinName pin)
128131 * when additional parameters are passed to the input init function,
129132 * then the GPIO is correctly initialized as an input.
130133 */
131- void test_explicit_input (PinName pin)
134+ void fpga_test_explicit_input (PinName pin)
132135{
133136 // Reset everything and set all tester pins to hi-Z.
134137 tester.reset ();
@@ -148,6 +151,7 @@ void test_explicit_input(PinName pin)
148151 tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
149152 wait_us (HI_Z_READ_DELAY_US);
150153 TEST_ASSERT_EQUAL_INT (1 , gpio_read (&gpio)); // hi-Z, pulled up
154+ gpio_free (&gpio);
151155
152156 // Initialize GPIO pin as an input, pull-down mode.
153157 memset (&gpio, 0 , sizeof gpio);
@@ -156,6 +160,7 @@ void test_explicit_input(PinName pin)
156160 tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
157161 wait_us (HI_Z_READ_DELAY_US);
158162 TEST_ASSERT_EQUAL_INT (0 , gpio_read (&gpio)); // hi-Z, pulled down
163+ gpio_free (&gpio);
159164
160165 // Initialize GPIO pin as an input, pull-up mode.
161166 memset (&gpio, 0 , sizeof gpio);
@@ -164,6 +169,7 @@ void test_explicit_input(PinName pin)
164169 tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
165170 wait_us (HI_Z_READ_DELAY_US);
166171 TEST_ASSERT_EQUAL_INT (1 , gpio_read (&gpio)); // hi-Z, pulled up
172+ gpio_free (&gpio);
167173
168174 // Initialize GPIO pin as an input, pull-down mode.
169175 memset (&gpio, 0 , sizeof gpio);
@@ -172,6 +178,7 @@ void test_explicit_input(PinName pin)
172178 tester.gpio_write (MbedTester::LogicalPinGPIO0, 0 , false );
173179 wait_us (HI_Z_READ_DELAY_US);
174180 TEST_ASSERT_EQUAL_INT (0 , gpio_read (&gpio)); // hi-Z, pulled down
181+ gpio_free (&gpio);
175182}
176183
177184/* Test explicit output initialization.
@@ -180,7 +187,7 @@ void test_explicit_input(PinName pin)
180187 * when additional parameters are passed to the output init function,
181188 * then the GPIO is correctly initialized as an output.
182189 */
183- void test_explicit_output (PinName pin)
190+ void fpga_test_explicit_output (PinName pin)
184191{
185192 // Reset everything and set all tester pins to hi-Z.
186193 tester.reset ();
@@ -198,41 +205,46 @@ void test_explicit_output(PinName pin)
198205 gpio_init_out (&gpio, pin);
199206 TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
200207 TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
208+ gpio_free (&gpio);
201209
202210 // Initialize GPIO pin as an output, output value = 1.
203211 memset (&gpio, 0 , sizeof gpio);
204212 gpio_init_out_ex (&gpio, pin, 1 );
205213 TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
206214 TEST_ASSERT_EQUAL_INT (1 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
215+ gpio_free (&gpio);
207216
208217 // Initialize GPIO pin as an output, output value = 0.
209218 memset (&gpio, 0 , sizeof gpio);
210219 gpio_init_out_ex (&gpio, pin, 0 );
211220 TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
212221 TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
222+ gpio_free (&gpio);
213223
214224 // Initialize GPIO pin as an output, output value = 1.
215225 memset (&gpio, 0 , sizeof gpio);
216226 gpio_init_inout (&gpio, pin, PIN_OUTPUT, PullNone, 1 );
217227 TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
218228 TEST_ASSERT_EQUAL_INT (1 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
229+ gpio_free (&gpio);
219230
220231 // Initialize GPIO pin as an output, output value = 0.
221232 memset (&gpio, 0 , sizeof gpio);
222233 gpio_init_inout (&gpio, pin, PIN_OUTPUT, PullNone, 0 );
223234 TEST_ASSERT_NOT_EQUAL (0 , gpio_is_connected (&gpio));
224235 TEST_ASSERT_EQUAL_INT (0 , tester.gpio_read (MbedTester::LogicalPinGPIO0));
236+ gpio_free (&gpio);
225237}
226238
227239Case 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 >),
229241 // Some targets don't support input pull mode.
230242#if !defined(TARGET_NANO100) && \
231243 !defined (TARGET_NUC472) && \
232244 !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 >),
234246#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 >),
236248};
237249
238250utest::v1::status_t greentea_test_setup (const size_t number_of_cases)
0 commit comments