2 * Copyright (c) 2023 Arm Limited. All rights reserved.
\r
4 * SPDX-License-Identifier: Apache-2.0
\r
6 * Licensed under the Apache License, Version 2.0 (the License); you may
\r
7 * not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
\r
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
18 * -----------------------------------------------------------------------------
\r
20 * Project: CMSIS-Driver Validation
\r
21 * Title: General-purpose Input Output (GPIO) Driver Validation tests
\r
23 * -----------------------------------------------------------------------------
\r
26 #ifndef __DOXYGEN__ // Exclude form the documentation
\r
32 #include "cmsis_dv.h"
\r
33 #include "DV_GPIO_Config.h"
\r
34 #include "DV_Framework.h"
\r
36 #include "Driver_GPIO.h"
\r
38 // Register Driver_GPIO#
\r
39 extern ARM_DRIVER_GPIO CREATE_SYMBOL(Driver_GPIO, DRV_GPIO);
\r
40 static ARM_DRIVER_GPIO *drv = &CREATE_SYMBOL(Driver_GPIO, DRV_GPIO);
\r
42 // Global variables (used in this module only)
\r
43 static volatile uint32_t event;
\r
44 static volatile ARM_GPIO_Pin_t event_pin;
\r
45 static volatile uint32_t event_cnt;
\r
47 static char msg_buf[256];
\r
50 static void GPIO_DrvEvent (ARM_GPIO_Pin_t pin, uint32_t evt);
\r
51 static int32_t PinUnderTestIsAvailable (void);
\r
52 static void PinUnderTestInit (void);
\r
53 static void PinUnderTestUninit (void);
\r
54 static int32_t AuxiliaryPinIsAvailable (void);
\r
55 static void AuxiliaryPinInit (void);
\r
56 static void AuxiliaryPinUninit (void);
\r
57 static void AuxiliaryPinConfigInput (void);
\r
58 static void AuxiliaryPinConfigOutput(void);
\r
59 static void AuxiliaryPinSetOutput (uint32_t val);
\r
64 \fn static void GPIO_DrvEvent (ARM_GPIO_Pin_t pin, uint32_t evt)
\r
65 \brief Store event(s) into a global variables.
\r
66 \detail This is a callback function called by the driver upon an event(s).
\r
67 \param[in] pin GPIO pin
\r
68 \param[in] evt GPIO event
\r
71 static void GPIO_DrvEvent (ARM_GPIO_Pin_t pin, uint32_t evt) {
\r
78 \fn static int32_t PinUnderTestIsAvailable (void)
\r
79 \brief Check if Pin Under Test is available.
\r
80 \detail This function is used to skip executing a test if Pin Under Test is not available.
\r
81 \return execution status
\r
82 - EXIT_SUCCESS: Pin Under Test is available
\r
83 - EXIT_FAILURE: Pin Under Test is not available
\r
85 static int32_t PinUnderTestIsAvailable (void) {
\r
87 if (drv->Setup(GPIO_CFG_PIN_UNDER_TEST, NULL) == ARM_DRIVER_OK) {
\r
88 return EXIT_SUCCESS;
\r
90 TEST_MESSAGE("[FAILED] Pin Under Test is not available!");
\r
91 return EXIT_FAILURE;
\r
96 \fn static void PinUnderTestInit (void)
\r
97 \brief Initialize Pin Under Test.
\r
101 static void PinUnderTestInit (void) {
\r
103 (void)drv->Setup(GPIO_CFG_PIN_UNDER_TEST, NULL);
\r
107 \fn static void PinUnderTestUninit (void)
\r
108 \brief Uninitialize Pin Under Test.
\r
112 static void PinUnderTestUninit (void) {
\r
114 (void)drv->SetDirection(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_INPUT);
\r
115 (void)drv->Setup (GPIO_CFG_PIN_UNDER_TEST, NULL);
\r
119 \fn static int32_t AuxiliaryPinIsAvailable (void)
\r
120 \brief Check if Auxiliary Pin is available.
\r
121 \detail This function is used to skip executing a test if Auxiliary Pin is not available.
\r
122 \return execution status
\r
123 - EXIT_SUCCESS: Auxiliary Pin is available
\r
124 - EXIT_FAILURE: Auxiliary Pin is not available
\r
126 static int32_t AuxiliaryPinIsAvailable (void) {
\r
128 if (drv->Setup(GPIO_CFG_PIN_AUX, NULL) == ARM_DRIVER_OK) {
\r
129 return EXIT_SUCCESS;
\r
131 TEST_MESSAGE("[FAILED] Auxiliary Pin is not available!");
\r
132 return EXIT_FAILURE;
\r
137 \fn static void AuxiliaryPinInit (void)
\r
138 \brief Initialize Auxiliary Pin.
\r
142 static void AuxiliaryPinInit (void) {
\r
144 (void)drv->Setup(GPIO_CFG_PIN_AUX, NULL);
\r
148 \fn static void AuxiliaryPinUninit (void)
\r
149 \brief Uninitialize Auxiliary Pin.
\r
153 static void AuxiliaryPinUninit (void) {
\r
155 (void)drv->SetDirection(GPIO_CFG_PIN_AUX, ARM_GPIO_INPUT);
\r
156 (void)drv->Setup (GPIO_CFG_PIN_AUX, NULL);
\r
160 \fn static void AuxiliaryPinConfigInput (void)
\r
161 \brief Configure Auxiliary Pin as Input.
\r
165 static void AuxiliaryPinConfigInput (void) {
\r
167 (void)drv->SetDirection(GPIO_CFG_PIN_AUX, ARM_GPIO_INPUT);
\r
171 \fn static void AuxiliaryPinConfigOutput (void)
\r
172 \brief Configure Auxiliary Pin as Output with Push-pull Output mode.
\r
176 static void AuxiliaryPinConfigOutput (void) {
\r
178 (void)drv->SetOutputMode(GPIO_CFG_PIN_AUX, ARM_GPIO_PUSH_PULL);
\r
179 (void)drv->SetDirection (GPIO_CFG_PIN_AUX, ARM_GPIO_OUTPUT);
\r
183 \fn static void AuxiliaryPinSetOutput (uint32_t val)
\r
184 \brief Set Auxiliary Pin output level (0 or 1).
\r
185 \param[in] val Output level
\r
188 static void AuxiliaryPinSetOutput (uint32_t val) {
\r
190 drv->SetOutput(GPIO_CFG_PIN_AUX, val);
\r
191 (void)osDelay(2U); // Wait for voltage to stabilize
\r
194 #endif // End of exclude form the documentation
\r
196 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
198 \defgroup dv_gpio GPIO Validation
\r
199 \brief GPIO driver validation
\r
201 The GPIO validation performs the following tests:
\r
202 - API interface compliance
\r
203 - Functions operation
\r
206 To perform GPIO validation tests, it is required to select and configure two pins in the <b>DV_GPIO_Config.h</b> configuration file:
\r
207 - Pin Under Test: pin to be tested
\r
208 - Auxiliary Pin: pin with serial low resistance resistor connected to Pin Under Test (suggested resistance of this resistor is around 1 kOhm)
\r
210 \image html gpio_loopback.png
\r
213 - Pins (Pin Under Test and Auxiliary Pin) should not have any external resistors or any external devices connected to it except the low resistance resistor used for testing.
\r
215 \defgroup gpio_tests Tests
\r
220 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
222 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
224 \brief Function: GPIO_Setup
\r
226 The function \b GPIO_Setup verifies the \b Setup function.
\r
228 int32_t Setup (ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event);
\r
232 - Call Setup function (without callback specified) and assert that it returned ARM_DRIVER_OK status
\r
233 - Call Setup function (with callback specified) and assert that it returned ARM_DRIVER_OK status
\r
235 void GPIO_Setup (void) {
\r
237 if (PinUnderTestIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
239 // Call Setup function (without callback specified) and assert that it returned ARM_DRIVER_OK status
\r
240 TEST_ASSERT(drv->Setup(GPIO_CFG_PIN_UNDER_TEST, NULL) == ARM_DRIVER_OK);
\r
242 // Call Setup function (with callback specified) and assert that it returned ARM_DRIVER_OK status
\r
243 TEST_ASSERT(drv->Setup(GPIO_CFG_PIN_UNDER_TEST, GPIO_DrvEvent) == ARM_DRIVER_OK);
\r
245 PinUnderTestUninit();
\r
248 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
250 \brief Function: GPIO_SetDirection
\r
252 The function \b GPIO_SetDirection verifies the \b SetDirection function.
\r
254 int32_t ARM_GPIO_SetDirection (ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction);
\r
258 - Call SetDirection function (with Input direction) and assert that it returned ARM_DRIVER_OK status
\r
259 - Configure Auxiliary Pin as Output
\r
260 - Drive Auxiliary Pin low
\r
261 - Read Pin Under Test input level and assert that it returned 0
\r
262 - Drive Auxiliary Pin high
\r
263 - Read Pin Under Test input level and assert that it returned 1
\r
264 - Configure Auxiliary Pin as Input
\r
265 - Call SetDirection function (with Output direction) and assert that it returned ARM_DRIVER_OK status
\r
266 - Call SetOutput function and set output level low
\r
267 - Read Auxiliary Pin input level and assert that it returned 0
\r
268 - Call SetOutput function and set output level high
\r
269 - Read Auxiliary Pin input level and assert that it returned 1
\r
271 void GPIO_SetDirection (void) {
\r
273 if (PinUnderTestIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
274 if (AuxiliaryPinIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
276 PinUnderTestInit();
\r
277 AuxiliaryPinInit();
\r
279 // Call SetDirection function (with Input direction) and assert that it returned ARM_DRIVER_OK status
\r
280 TEST_ASSERT(drv->SetDirection(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_INPUT) == ARM_DRIVER_OK);
\r
282 // Configure Auxiliary Pin as Output
\r
283 AuxiliaryPinConfigOutput();
\r
285 // Drive Auxiliary Pin low
\r
286 AuxiliaryPinSetOutput(0U);
\r
288 // Read Pin Under Test input level and assert that it returned 0
\r
289 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 0U);
\r
291 // Drive Auxiliary Pin high
\r
292 AuxiliaryPinSetOutput(1U);
\r
294 // Read Pin Under Test input level and assert that it returned 1
\r
295 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 1U);
\r
297 // Configure Auxiliary Pin as Input
\r
298 AuxiliaryPinConfigInput();
\r
300 // Call SetDirection function (with Output direction) and assert that it returned ARM_DRIVER_OK status
\r
301 TEST_ASSERT(drv->SetDirection(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_OUTPUT) == ARM_DRIVER_OK);
\r
303 // Call SetOutput function and set output level low
\r
304 drv->SetOutput(GPIO_CFG_PIN_UNDER_TEST, 0U);
\r
308 // Read Auxiliary Pin input level and assert that it returned 0
\r
309 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_AUX) == 0U);
\r
311 // Call SetOutput function and set output level high
\r
312 drv->SetOutput(GPIO_CFG_PIN_UNDER_TEST, 1U);
\r
316 // Read Auxiliary Pin input level and assert that it returned 1
\r
317 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_AUX) == 1U);
\r
319 AuxiliaryPinUninit();
\r
320 PinUnderTestUninit();
\r
323 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
325 \brief Function: GPIO_SetOutputMode
\r
327 The function \b GPIO_SetOutputMode verifies the \b SetOutputMode function.
\r
329 int32_t ARM_GPIO_SetOutputMode (ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode);
\r
333 - Call SetDirection function (with Output direction) and assert that it returned ARM_DRIVER_OK status
\r
334 - Call SetOutputMode function (with Push-pull mode) and assert that it returned ARM_DRIVER_OK status
\r
335 - Configure Auxiliary Pin as Input
\r
336 - Call SetOutput function and set output level low
\r
337 - Read Auxiliary Pin input level and assert that it returned 0
\r
338 - Call SetOutput function and set output level high
\r
339 - Read Auxiliary Pin input level and assert that it returned 1
\r
340 - Call SetOutputMode function (with Open-drain mode) and assert that it returned ARM_DRIVER_OK status
\r
341 - Call SetOutput function and set output level low
\r
342 - Read Auxiliary Pin input level and assert that it returned 0
\r
344 void GPIO_SetOutputMode (void) {
\r
346 if (PinUnderTestIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
347 if (AuxiliaryPinIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
349 PinUnderTestInit();
\r
350 AuxiliaryPinInit();
\r
352 // Call SetDirection function (with Output direction) and assert that it returned ARM_DRIVER_OK status
\r
353 TEST_ASSERT(drv->SetDirection(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_OUTPUT) == ARM_DRIVER_OK);
\r
355 // Call SetOutputMode function (with Push-pull mode) and assert that it returned ARM_DRIVER_OK status
\r
356 TEST_ASSERT(drv->SetOutputMode(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_PUSH_PULL) == ARM_DRIVER_OK);
\r
358 // Configure Auxiliary Pin as Input
\r
359 AuxiliaryPinConfigInput();
\r
361 // Call SetOutput function and set output level low
\r
362 drv->SetOutput(GPIO_CFG_PIN_UNDER_TEST, 0U);
\r
366 // Read Auxiliary Pin input level and assert that it returned 0
\r
367 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_AUX) == 0U);
\r
369 // Call SetOutput function and set output level high
\r
370 drv->SetOutput(GPIO_CFG_PIN_UNDER_TEST, 1U);
\r
374 // Read Auxiliary Pin input level and assert that it returned 1
\r
375 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_AUX) == 1U);
\r
377 // Call SetOutputMode function (with Open-drain mode) and assert that it returned ARM_DRIVER_OK status
\r
378 TEST_ASSERT(drv->SetOutputMode(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_OPEN_DRAIN) == ARM_DRIVER_OK);
\r
380 // Call SetOutput function and set output level low
\r
381 drv->SetOutput(GPIO_CFG_PIN_UNDER_TEST, 0U);
\r
385 // Read Auxiliary Pin input level and assert that it returned 0
\r
386 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_AUX) == 0U);
\r
388 AuxiliaryPinUninit();
\r
389 PinUnderTestUninit();
\r
392 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
394 \brief Function: GPIO_SetPullResistor
\r
396 The function \b GPIO_SetPullResistor verifies the \b SetPullResistor function.
\r
398 int32_t ARM_GPIO_SetPullResistor (ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor);
\r
402 - Call SetDirection function (with Input direction) and assert that it returned ARM_DRIVER_OK status
\r
403 - Call SetPullResistor function (without resistor) and assert that it returned ARM_DRIVER_OK status
\r
404 - Configure Auxiliary Pin as Output
\r
405 - Drive Auxiliary Pin low
\r
406 - Read Pin Under Test input level and assert that it returned 0
\r
407 - Drive Auxiliary Pin high
\r
408 - Read Pin Under Test input level and assert that it returned 1
\r
409 - Configure Auxiliary Pin as Input
\r
410 - Call SetPullResistor function (with Pull-down resistor) and assert that it returned ARM_DRIVER_OK status
\r
411 - Read Pin Under Test input level and assert that it returned 0
\r
412 - Configure Auxiliary Pin as Output
\r
413 - Drive Auxiliary Pin high
\r
414 - Read Pin Under Test input level and assert that it returned 1
\r
415 - Configure Auxiliary Pin as Input
\r
416 - Call SetPullResistor function (with Pull-up resistor) and assert that it returned ARM_DRIVER_OK status
\r
417 - Read Pin Under Test input level and assert that it returned 1
\r
418 - Configure Auxiliary Pin as Output
\r
419 - Drive Auxiliary Pin low
\r
420 - Read Pin Under Test input level and assert that it returned 0
\r
422 void GPIO_SetPullResistor (void) {
\r
424 if (PinUnderTestIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
425 if (AuxiliaryPinIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
427 PinUnderTestInit();
\r
428 AuxiliaryPinInit();
\r
430 // Call SetDirection function (with Input direction) and assert that it returned ARM_DRIVER_OK status
\r
431 TEST_ASSERT(drv->SetDirection(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_INPUT) == ARM_DRIVER_OK);
\r
433 // Call SetPullResistor function (without resistor) and assert that it returned ARM_DRIVER_OK status
\r
434 TEST_ASSERT(drv->SetPullResistor(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_PULL_NONE) == ARM_DRIVER_OK);
\r
436 // Configure Auxiliary Pin as Output
\r
437 AuxiliaryPinConfigOutput();
\r
439 // Drive Auxiliary Pin low
\r
440 AuxiliaryPinSetOutput(0U);
\r
442 // Read Pin Under Test input level and assert that it returned 0
\r
443 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 0U);
\r
445 // Drive Auxiliary Pin high
\r
446 AuxiliaryPinSetOutput(1U);
\r
448 // Read Pin Under Test input level and assert that it returned 1
\r
449 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 1U);
\r
451 // Configure Auxiliary Pin as Input
\r
452 AuxiliaryPinConfigInput();
\r
456 // Call SetPullResistor function (with Pull-down resistor) and assert that it returned ARM_DRIVER_OK status
\r
457 TEST_ASSERT(drv->SetPullResistor(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_PULL_DOWN) == ARM_DRIVER_OK);
\r
461 // Read Pin Under Test input level and assert that it returned 0
\r
462 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 0U);
\r
464 // Configure Auxiliary Pin as Output
\r
465 AuxiliaryPinConfigOutput();
\r
467 // Drive Auxiliary Pin high
\r
468 AuxiliaryPinSetOutput(1U);
\r
470 // Read Pin Under Test input level and assert that it returned 1
\r
471 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 1U);
\r
473 // Configure Auxiliary Pin as Input
\r
474 AuxiliaryPinConfigInput();
\r
478 // Call SetPullResistor function (with Pull-up resistor) and assert that it returned ARM_DRIVER_OK status
\r
479 TEST_ASSERT(drv->SetPullResistor(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_PULL_UP) == ARM_DRIVER_OK);
\r
483 // Read Pin Under Test input level and assert that it returned 1
\r
484 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 1U);
\r
486 // Configure Auxiliary Pin as Output
\r
487 AuxiliaryPinConfigOutput();
\r
489 // Drive Auxiliary Pin low
\r
490 AuxiliaryPinSetOutput(0U);
\r
492 // Read Pin Under Test input level and assert that it returned 0
\r
493 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 0U);
\r
495 AuxiliaryPinUninit();
\r
496 PinUnderTestUninit();
\r
499 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
501 \brief Function: GPIO_SetEventTrigger
\r
503 The function \b GPIO_SetEventTrigger verifies the \b SetEventTrigger function.
\r
505 int32_t ARM_GPIO_SetEventTrigger (ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger);
\r
509 - Call Setup function (with callback specified) and assert that it returned ARM_DRIVER_OK status
\r
510 - Configure Auxiliary Pin as Output
\r
511 - Drive Auxiliary Pin low
\r
512 - Call SetEventTrigger function (configure trigger on Rising-edge) and assert that it returned ARM_DRIVER_OK status
\r
513 - Drive Auxiliary Pin high thus generate Rising-edge
\r
514 - Assert that event ARM_GPIO_EVENT_RISING_EDGE was signaled
\r
515 - Assert that event was signaled on Pin Under Test pin
\r
516 - Assert that only 1 event was signaled
\r
517 - Drive Auxiliary Pin low thus generate Falling-edge
\r
518 - Assert that event was not signaled
\r
519 - Drive Auxiliary Pin high
\r
520 - Call SetEventTrigger function (configure trigger on Falling-edge) and assert that it returned ARM_DRIVER_OK status
\r
521 - Drive Auxiliary Pin low thus generate Falling-edge
\r
522 - Assert that event ARM_GPIO_EVENT_FALLING_EDGE was signaled
\r
523 - Assert that event was signaled on Pin Under Test pin
\r
524 - Assert that only 1 event was signaled
\r
525 - Drive Auxiliary Pin high thus generate Rising-edge
\r
526 - Assert that event was not signaled
\r
527 - Drive Auxiliary Pin low
\r
528 - Call SetEventTrigger function (configure trigger on Either-edge) and assert that it returned ARM_DRIVER_OK status
\r
529 - Drive Auxiliary Pin high thus generate Rising-edge
\r
530 - Assert that event ARM_GPIO_EVENT_RISING_EDGE or ARM_GPIO_EVENT_EITHER_EDGE was signaled
\r
531 - Assert that event was signaled on Pin Under Test pin
\r
532 - Assert that only 1 event was signaled
\r
533 - Drive Auxiliary Pin low thus generate Falling-edge
\r
534 - Assert that event ARM_GPIO_EVENT_FALLING_EDGE or ARM_GPIO_EVENT_EITHER_EDGE was signaled
\r
535 - Assert that event was signaled on Pin Under Test pin
\r
536 - Assert that only 1 event was signaled
\r
537 - Drive Auxiliary Pin low
\r
538 - Call SetEventTrigger function (disable trigger) and assert that it returned ARM_DRIVER_OK status
\r
539 - Drive Auxiliary Pin high thus generate Rising-edge
\r
540 - Drive Auxiliary Pin low thus generate Falling-edge
\r
541 - Assert that event was not signaled
\r
543 void GPIO_SetEventTrigger (void) {
\r
545 if (PinUnderTestIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
546 if (AuxiliaryPinIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
548 PinUnderTestInit();
\r
549 AuxiliaryPinInit();
\r
551 // Call Setup function (with callback specified) and assert that it returned ARM_DRIVER_OK status
\r
552 TEST_ASSERT(drv->Setup(GPIO_CFG_PIN_UNDER_TEST, GPIO_DrvEvent) == ARM_DRIVER_OK);
\r
554 // Configure Auxiliary Pin as Output
\r
555 AuxiliaryPinConfigOutput();
\r
557 // Test Rising-edge
\r
558 // Drive Auxiliary Pin low
\r
559 AuxiliaryPinSetOutput(0U);
\r
565 // Call SetEventTrigger function (configure trigger on Rising-edge) and assert that it returned ARM_DRIVER_OK status
\r
566 TEST_ASSERT(drv->SetEventTrigger(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_TRIGGER_RISING_EDGE) == ARM_DRIVER_OK);
\r
568 // Drive Auxiliary Pin high thus generate Rising-edge
\r
569 AuxiliaryPinSetOutput(1U);
\r
571 // Assert that event ARM_GPIO_EVENT_RISING_EDGE was signaled
\r
572 TEST_ASSERT_MESSAGE(event == ARM_GPIO_EVENT_RISING_EDGE, "[FAILED] Event ARM_GPIO_EVENT_RISING_EDGE was not signaled!");
\r
574 // Assert that event was signaled on Pin Under Test pin
\r
575 TEST_ASSERT_MESSAGE(event_pin == (uint32_t)GPIO_CFG_PIN_UNDER_TEST, "[FAILED] Event was not signaled on Pin Under Test pin!");
\r
577 if (event_cnt != 1U) {
\r
578 // If number of events signaled was different than 1
\r
579 (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] Number of signaled events was %i! Expected number of events was 1!", event_cnt);
\r
581 // Assert that only 1 event was signaled
\r
582 TEST_ASSERT_MESSAGE(event_cnt == 1U, msg_buf);
\r
588 // Drive Auxiliary Pin low thus generate Falling-edge
\r
589 AuxiliaryPinSetOutput(0U);
\r
591 // Assert that event was not signaled
\r
592 TEST_ASSERT_MESSAGE(event_cnt == 0U, "[FAILED] Event was signaled on Pin Under Test pin! Event signaled on falling-edge for rising-edge trigger!");
\r
594 // Test Falling-edge
\r
595 // Drive Auxiliary Pin high
\r
596 AuxiliaryPinSetOutput(1U);
\r
602 // Call SetEventTrigger function (configure trigger on Falling-edge) and assert that it returned ARM_DRIVER_OK status
\r
603 TEST_ASSERT(drv->SetEventTrigger(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_TRIGGER_FALLING_EDGE) == ARM_DRIVER_OK);
\r
605 // Drive Auxiliary Pin low thus generate Falling-edge
\r
606 AuxiliaryPinSetOutput(0U);
\r
608 // Assert that event ARM_GPIO_EVENT_FALLING_EDGE was signaled
\r
609 TEST_ASSERT_MESSAGE(event == ARM_GPIO_EVENT_FALLING_EDGE, "[FAILED] Event ARM_GPIO_EVENT_FALLING_EDGE was not signaled!");
\r
611 // Assert that event was signaled on Pin Under Test pin
\r
612 TEST_ASSERT_MESSAGE(event_pin == (uint32_t)GPIO_CFG_PIN_UNDER_TEST, "[FAILED] Event was not signaled on Pin Under Test pin!");
\r
614 if (event_cnt != 1U) {
\r
615 // If number of events signaled was different than 1
\r
616 (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] Number of signaled events was %i! Expected number of events was 1!", event_cnt);
\r
618 // Assert that only 1 event was signaled
\r
619 TEST_ASSERT_MESSAGE(event_cnt == 1U, msg_buf);
\r
625 // Drive Auxiliary Pin high thus generate Rising-edge
\r
626 AuxiliaryPinSetOutput(0U);
\r
628 // Assert that event was not signaled
\r
629 TEST_ASSERT_MESSAGE(event_cnt == 0U, "[FAILED] Event was signaled on Pin Under Test pin! Event signaled on rising-edge for falling-edge trigger!");
\r
631 // Test Either-edge
\r
632 // Drive Auxiliary Pin low
\r
633 AuxiliaryPinSetOutput(0U);
\r
639 // Call SetEventTrigger function (configure trigger on Either-edge) and assert that it returned ARM_DRIVER_OK status
\r
640 TEST_ASSERT(drv->SetEventTrigger(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_TRIGGER_EITHER_EDGE) == ARM_DRIVER_OK);
\r
642 // Drive Auxiliary Pin high thus generate Rising-edge
\r
643 AuxiliaryPinSetOutput(1U);
\r
645 // Assert that event ARM_GPIO_EVENT_RISING_EDGE or ARM_GPIO_EVENT_EITHER_EDGE was signaled
\r
646 TEST_ASSERT_MESSAGE((event == ARM_GPIO_EVENT_RISING_EDGE) ||
\r
647 (event == ARM_GPIO_EVENT_EITHER_EDGE), "[FAILED] Event ARM_GPIO_EVENT_RISING_EDGE or ARM_GPIO_EVENT_EITHER_EDGE was not signaled!");
\r
649 // Assert that event was signaled on Pin Under Test pin
\r
650 TEST_ASSERT_MESSAGE(event_pin == (uint32_t)GPIO_CFG_PIN_UNDER_TEST, "[FAILED] Event was not signaled on Pin Under Test pin!");
\r
652 if (event_cnt != 1U) {
\r
653 // If number of events signaled was different than 1
\r
654 (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] Number of signaled events was %i! Expected number of events was 1!", event_cnt);
\r
656 // Assert that only 1 event was signaled
\r
657 TEST_ASSERT_MESSAGE(event_cnt == 1U, msg_buf);
\r
663 // Drive Auxiliary Pin low thus generate Falling-edge
\r
664 AuxiliaryPinSetOutput(0U);
\r
666 // Assert that event ARM_GPIO_EVENT_FALLING_EDGE or ARM_GPIO_EVENT_EITHER_EDGE was signaled
\r
667 TEST_ASSERT_MESSAGE((event == ARM_GPIO_EVENT_FALLING_EDGE) ||
\r
668 (event == ARM_GPIO_EVENT_EITHER_EDGE), "[FAILED] Event ARM_GPIO_EVENT_FALLING_EDGE or ARM_GPIO_EVENT_EITHER_EDGE was not signaled!");
\r
670 // Assert that event was signaled on Pin Under Test pin
\r
671 TEST_ASSERT_MESSAGE(event_pin == (uint32_t)GPIO_CFG_PIN_UNDER_TEST, "[FAILED] Event was not signaled on Pin Under Test pin!");
\r
673 if (event_cnt != 1U) {
\r
674 // If number of events signaled was different than 1
\r
675 (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] Number of signaled events was %i! Expected number of events was 1!", event_cnt);
\r
677 // Assert that only 1 event was signaled
\r
678 TEST_ASSERT_MESSAGE(event_cnt == 1U, msg_buf);
\r
680 // Test no trigger enabled functionality
\r
681 // Drive Auxiliary Pin low
\r
682 AuxiliaryPinSetOutput(0U);
\r
688 // Call SetEventTrigger function (disable trigger) and assert that it returned ARM_DRIVER_OK status
\r
689 TEST_ASSERT(drv->SetEventTrigger(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_TRIGGER_NONE) == ARM_DRIVER_OK);
\r
691 // Drive Auxiliary Pin high thus generate Rising-edge
\r
692 AuxiliaryPinSetOutput(1U);
\r
694 // Drive Auxiliary Pin low thus generate Falling-edge
\r
695 AuxiliaryPinSetOutput(0U);
\r
697 // Assert that event was not signaled
\r
698 TEST_ASSERT_MESSAGE(event_cnt == 0U, "[FAILED] Event was signaled on Pin Under Test pin with trigger functionality disabled!");
\r
700 AuxiliaryPinUninit();
\r
701 PinUnderTestUninit();
\r
704 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
706 \brief Function: GPIO_SetOutput
\r
708 The function \b GPIO_SetOutput verifies the \b SetOutput function.
\r
711 - Call SetDirection function (with Output direction) and assert that it returned ARM_DRIVER_OK status
\r
712 - Call SetOutputMode function (with Push-pull mode) and assert that it returned ARM_DRIVER_OK status
\r
713 - Configure Auxiliary Pin as Input
\r
714 - Call SetOutput function and set output level low
\r
715 - Read Auxiliary Pin input level and assert that it returned 0
\r
716 - Call SetOutput function and set output level high
\r
717 - Read Auxiliary Pin input level and assert that it returned 1
\r
719 void GPIO_SetOutput (void) {
\r
721 if (PinUnderTestIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
722 if (AuxiliaryPinIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
724 PinUnderTestInit();
\r
725 AuxiliaryPinInit();
\r
727 // Call SetDirection function (with Output direction) and assert that it returned ARM_DRIVER_OK status
\r
728 TEST_ASSERT(drv->SetDirection(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_OUTPUT) == ARM_DRIVER_OK);
\r
730 // Call SetOutputMode function (with Push-pull mode) and assert that it returned ARM_DRIVER_OK status
\r
731 TEST_ASSERT(drv->SetOutputMode(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_PUSH_PULL) == ARM_DRIVER_OK);
\r
733 // Configure Auxiliary Pin as Input
\r
734 AuxiliaryPinConfigInput();
\r
736 // Call SetOutput function and set output level low
\r
737 drv->SetOutput(GPIO_CFG_PIN_UNDER_TEST, 0U);
\r
741 // Read Auxiliary Pin input level and assert that it returned 0
\r
742 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_AUX) == 0U);
\r
744 // Call SetOutput function and set output level high
\r
745 drv->SetOutput(GPIO_CFG_PIN_UNDER_TEST, 1U);
\r
749 // Read Auxiliary Pin input level and assert that it returned 1
\r
750 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_AUX) == 1U);
\r
752 AuxiliaryPinUninit();
\r
753 PinUnderTestUninit();
\r
756 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
\r
758 \brief Function: GPIO_GetInput
\r
760 The function \b GPIO_GetInput verifies the \b GetInput function.
\r
763 - Call SetDirection function (with Input direction) and assert that it returned ARM_DRIVER_OK status
\r
764 - Configure Auxiliary Pin as Output
\r
765 - Drive Auxiliary Pin low
\r
766 - Read Pin Under Test input level and assert that it returned 0
\r
767 - Drive Auxiliary Pin high
\r
768 - Read Pin Under Test input level and assert that it returned 1
\r
770 void GPIO_GetInput (void) {
\r
772 if (PinUnderTestIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
773 if (AuxiliaryPinIsAvailable() != EXIT_SUCCESS) { TEST_FAIL(); return; }
\r
775 PinUnderTestInit();
\r
776 AuxiliaryPinInit();
\r
778 // Call SetDirection function (with Input direction) and assert that it returned ARM_DRIVER_OK status
\r
779 TEST_ASSERT(drv->SetDirection(GPIO_CFG_PIN_UNDER_TEST, ARM_GPIO_INPUT) == ARM_DRIVER_OK);
\r
781 // Configure Auxiliary Pin as Output
\r
782 AuxiliaryPinConfigOutput();
\r
784 // Drive Auxiliary Pin low
\r
785 AuxiliaryPinSetOutput(0U);
\r
789 // Read Pin Under Test input level and assert that it returned 0
\r
790 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 0U);
\r
792 // Drive Auxiliary Pin high
\r
793 AuxiliaryPinSetOutput(1U);
\r
797 // Read Pin Under Test input level and assert that it returned 1
\r
798 TEST_ASSERT(drv->GetInput(GPIO_CFG_PIN_UNDER_TEST) == 1U);
\r
800 AuxiliaryPinUninit();
\r
801 PinUnderTestUninit();
\r
807 // end of group dv_gpio
\r