2 * Copyright (c) 2015-2020 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * -----------------------------------------------------------------------------
20 * Project: CMSIS-Driver Validation
21 * Title: Universal Serial Bus (USB) Host Driver Validation tests
23 * -----------------------------------------------------------------------------
28 #include "DV_USBH_Config.h"
29 #include "DV_Framework.h"
30 #include "Driver_USBH.h"
35 // Register Driver_USBH#
36 extern ARM_DRIVER_USBH CREATE_SYMBOL(Driver_USBH, DRV_USBH);
37 static ARM_DRIVER_USBH *drv = &CREATE_SYMBOL(Driver_USBH, DRV_USBH);
38 static ARM_USBH_CAPABILITIES capab;
41 static uint8_t volatile PortEvent;
42 static uint8_t volatile PipeEvent;
45 static void USB_PortEvent (uint8_t port, uint32_t event) {
50 static void USB_PipeEvent (ARM_USBH_PIPE_HANDLE pipe_hndl, uint32_t event) {
55 /*-----------------------------------------------------------------------------
57 *----------------------------------------------------------------------------*/
59 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
61 \defgroup dv_usbh USB Host Validation
62 \brief USB Host driver validation
64 The USB Host validation test checks the API interface compliance only.
66 \defgroup usbh_tests Tests
72 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
74 \brief Function: USBH_GetCapabilities
76 The test function \b USBH_GetCapabilities verifies the function \b GetCapabilities.
78 void USBH_GetCapabilities (void) {
79 /* Get USBH capabilities */
80 capab = drv->GetCapabilities();
81 TEST_ASSERT(&capab != NULL);
84 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
86 \brief Function: USBH_Initialization
88 The test function \b USBH_Initialization verifies the USBH functions with the sequence:
89 - \b Initialize without callback
91 - \b Initialize with callback
94 void USBH_Initialization (void) {
96 /* Initialize without callback */
97 TEST_ASSERT(drv->Initialize(NULL, NULL) == ARM_DRIVER_OK);
100 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
102 /* Initialize with callback */
103 TEST_ASSERT(drv->Initialize(USB_PortEvent, USB_PipeEvent) == ARM_DRIVER_OK);
106 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
109 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
111 \brief Function: USBH_CheckInvalidInit
113 The test function \b USBH_CheckInvalidInit verifies the driver behaviour when receiving an invalid initialization sequence:
115 - \b PowerControl with Power off
116 - \b PowerControl with Power on
117 - \b PowerControl with Power off
120 void USBH_CheckInvalidInit (void) {
123 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
126 TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
128 /* Try to power on */
129 TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) != ARM_DRIVER_OK);
132 TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
135 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
138 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
140 \brief Function: USBH_PowerControl
142 The test function \b USBH_PowerControl verifies the \b PowerControl function with the sequence:
149 void USBH_PowerControl (void) {
152 /* Initialize with callback */
153 TEST_ASSERT(drv->Initialize(USB_PortEvent, USB_PipeEvent) == ARM_DRIVER_OK);
156 TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
159 val = drv->PowerControl (ARM_POWER_LOW);
160 if (val == ARM_DRIVER_ERROR_UNSUPPORTED) { TEST_MESSAGE("[WARNING] Low power is not supported"); }
161 else { TEST_ASSERT(val == ARM_DRIVER_OK); }
164 TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
167 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
173 // end of group dv_usbh