]> begriffs open source - cmsis-driver-validation/blob - Source/DV_USBD.c
Merge branch 'develop'
[cmsis-driver-validation] / Source / DV_USBD.c
1 /*
2  * Copyright (c) 2015-2020 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
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
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * -----------------------------------------------------------------------------
19  *
20  * Project:     CMSIS-Driver Validation
21  * Title:       Universal Serial Bus (USB) Device Driver Validation tests
22  *
23  * -----------------------------------------------------------------------------
24  */
25
26
27 #include "cmsis_dv.h" 
28 #include "DV_USBD_Config.h"
29 #include "DV_Framework.h"
30 #include "Driver_USBD.h"
31 #include <stdio.h>
32 #include <stdlib.h> 
33 #include <string.h> 
34
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;  
39
40 // Event flags
41 static uint8_t volatile DeviceEvent;  
42 static uint8_t volatile EndpointEvent; 
43
44 // USB Device event
45 static void USB_DeviceEvent (uint32_t event) {
46   DeviceEvent |= event;
47 }
48
49 // USB Endpoint event
50 static void USB_EndpointEvent (uint8_t endpoint, uint32_t event) {
51   (void) endpoint;
52   EndpointEvent |= event;
53 }
54
55
56 /*-----------------------------------------------------------------------------
57  *      Tests
58  *----------------------------------------------------------------------------*/
59  
60 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
61 /**
62 \defgroup dv_usbd USB Device Validation
63 \brief USB Device driver validation
64 \details
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.
68
69 \defgroup usbd_tests Tests
70 \ingroup dv_usbd
71
72 @{
73 */
74
75 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
76 /**
77 \brief Function: USBD_GetCapabilities
78 \details
79 The test function \b USBD_GetCapabilities verifies the function \b GetCapabilities.
80 */
81 void USBD_GetCapabilities (void) {                    
82   /* Get USBD capabilities */
83   capab = drv->GetCapabilities();
84   TEST_ASSERT(&capab != NULL); 
85 }
86
87 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
88 /**
89 \brief  Function: USBD_Initialization
90 \details
91 The test function \b USBD_Initialization verifies the USBD functions with the sequence:
92   - \b Initialize without callback
93   - \b Uninitialize
94   - \b Initialize with callback
95   - \b Uninitialize
96 */
97 void USBD_Initialization (void) { 
98
99   /* Initialize without callback */
100   TEST_ASSERT(drv->Initialize(NULL, NULL) == ARM_DRIVER_OK); 
101     
102   /* Uninitialize */
103   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
104   
105   /* Initialize with callback */
106   TEST_ASSERT(drv->Initialize(USB_DeviceEvent, USB_EndpointEvent) == ARM_DRIVER_OK); 
107   
108   /* Uninitialize */
109   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
110 }
111
112 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
113 /**
114 \brief  Function: USBD_CheckInvalidInit
115 \details
116 The test function \b USBD_CheckInvalidInit verifies the driver behaviour when receiving an invalid initialization sequence:
117   - \b Uninitialize
118   - \b PowerControl with Power off
119   - \b PowerControl with Power on
120   - \b PowerControl with Power off
121   - \b Uninitialize
122 */
123 void USBD_CheckInvalidInit (void) { 
124
125   /* Uninitialize */
126   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
127   
128   /* Power off */
129   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
130   
131   /* Try to power on */
132   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) != ARM_DRIVER_OK); 
133   
134   /* Power off */
135   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
136   
137   /* Uninitialize */
138   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
139 }
140
141 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
142 /**
143 \brief  Function: USBD_PowerControl
144 \details
145 The test function \b USBD_PowerControl verifies the \b PowerControl function with the sequence:
146  - Initialize
147  - Power on
148  - Power low
149  - Power off
150  - Uninitialize 
151 */
152 void USBD_PowerControl (void) { 
153   int32_t val;
154   
155   /* Initialize with callback */
156   TEST_ASSERT(drv->Initialize(USB_DeviceEvent, USB_EndpointEvent) == ARM_DRIVER_OK); 
157   
158   /* Power on */
159   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);  
160   
161   /* Power low */
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); }
165    
166   /* Power off */
167   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
168   
169   /* Uninitialize */
170   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
171 }
172
173 /**
174 @}
175 */ 
176 // end of group dv_usbd