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) Device Driver Validation tests
23 * -----------------------------------------------------------------------------
28 #include "DV_USBD_Config.h"
29 #include "DV_Framework.h"
30 #include "Driver_USBD.h"
35 // Register Driver_USBD#
36 extern ARM_DRIVER_USBD CREATE_SYMBOL(Driver_USBD, DRV_USBD);
37 static ARM_DRIVER_USBD *drv = &CREATE_SYMBOL(Driver_USBD, DRV_USBD);
38 static ARM_USBD_CAPABILITIES capab;
41 static uint8_t volatile DeviceEvent;
42 static uint8_t volatile EndpointEvent;
45 static void USB_DeviceEvent (uint32_t event) {
50 static void USB_EndpointEvent (uint8_t endpoint, uint32_t event) {
52 EndpointEvent |= event;
56 /*-----------------------------------------------------------------------------
58 *----------------------------------------------------------------------------*/
60 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
62 \defgroup dv_usbd USB Device Validation
63 \brief USB Device driver validation
65 The USB Device validation test checks the API interface compliance only.<br>
66 The section \ref usbd_comp_test explains how to run the USB compliance tests.<br>
67 These tests check USB device for conformance to the USB specification which is required in order to gain USB certification.
69 \defgroup usbd_tests Tests
75 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
77 \brief Function: USBD_GetCapabilities
79 The test function \b USBD_GetCapabilities verifies the function \b GetCapabilities.
81 void USBD_GetCapabilities (void) {
82 /* Get USBD capabilities */
83 capab = drv->GetCapabilities();
84 TEST_ASSERT(&capab != NULL);
87 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
89 \brief Function: USBD_Initialization
91 The test function \b USBD_Initialization verifies the USBD functions with the sequence:
92 - \b Initialize without callback
94 - \b Initialize with callback
97 void USBD_Initialization (void) {
99 /* Initialize without callback */
100 TEST_ASSERT(drv->Initialize(NULL, NULL) == ARM_DRIVER_OK);
103 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
105 /* Initialize with callback */
106 TEST_ASSERT(drv->Initialize(USB_DeviceEvent, USB_EndpointEvent) == ARM_DRIVER_OK);
109 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
112 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
114 \brief Function: USBD_CheckInvalidInit
116 The test function \b USBD_CheckInvalidInit verifies the driver behaviour when receiving an invalid initialization sequence:
118 - \b PowerControl with Power off
119 - \b PowerControl with Power on
120 - \b PowerControl with Power off
123 void USBD_CheckInvalidInit (void) {
126 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
129 TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
131 /* Try to power on */
132 TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) != ARM_DRIVER_OK);
135 TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
138 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
141 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
143 \brief Function: USBD_PowerControl
145 The test function \b USBD_PowerControl verifies the \b PowerControl function with the sequence:
152 void USBD_PowerControl (void) {
155 /* Initialize with callback */
156 TEST_ASSERT(drv->Initialize(USB_DeviceEvent, USB_EndpointEvent) == ARM_DRIVER_OK);
159 TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
162 val = drv->PowerControl (ARM_POWER_LOW);
163 if (val == ARM_DRIVER_ERROR_UNSUPPORTED) { TEST_MESSAGE("[WARNING] Low power is not supported"); }
164 else { TEST_ASSERT(val == ARM_DRIVER_OK); }
167 TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
170 TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK);
176 // end of group dv_usbd