]> begriffs open source - cmsis-driver-validation/blob - Source/DV_USBH.c
Merge branch 'develop'
[cmsis-driver-validation] / Source / DV_USBH.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) Host Driver Validation tests
22  *
23  * -----------------------------------------------------------------------------
24  */
25
26
27 #include "cmsis_dv.h" 
28 #include "DV_USBH_Config.h"
29 #include "DV_Framework.h"
30 #include "Driver_USBH.h"
31 #include <stdio.h>
32 #include <stdlib.h> 
33 #include <string.h> 
34
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;  
39
40 // Event flags
41 static uint8_t volatile PortEvent;  
42 static uint8_t volatile PipeEvent; 
43
44 // USB Port event
45 static void USB_PortEvent (uint8_t port, uint32_t event) {
46   PortEvent |= event;
47 }
48
49 // USB Pipe event
50 static void USB_PipeEvent (ARM_USBH_PIPE_HANDLE pipe_hndl, uint32_t event) {
51   PipeEvent |= event;
52 }
53
54
55 /*-----------------------------------------------------------------------------
56  *      Tests
57  *----------------------------------------------------------------------------*/
58  
59 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
60 /**
61 \defgroup dv_usbh USB Host Validation
62 \brief USB Host driver validation
63 \details
64 The USB Host validation test checks the API interface compliance only.
65
66 \defgroup usbh_tests Tests
67 \ingroup dv_usbh
68
69 @{
70 */
71
72 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
73 /**
74 \brief Function: USBH_GetCapabilities
75 \details
76 The test function \b USBH_GetCapabilities verifies the function \b GetCapabilities.
77 */
78 void USBH_GetCapabilities (void) {                    
79   /* Get USBH capabilities */
80   capab = drv->GetCapabilities();
81   TEST_ASSERT(&capab != NULL); 
82 }
83
84 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
85 /**
86 \brief  Function: USBH_Initialization
87 \details
88 The test function \b USBH_Initialization verifies the USBH functions with the sequence:
89   - \b Initialize without callback
90   - \b Uninitialize
91   - \b Initialize with callback
92   - \b Uninitialize
93 */
94 void USBH_Initialization (void) { 
95
96   /* Initialize without callback */
97   TEST_ASSERT(drv->Initialize(NULL, NULL) == ARM_DRIVER_OK); 
98     
99   /* Uninitialize */
100   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
101   
102   /* Initialize with callback */
103   TEST_ASSERT(drv->Initialize(USB_PortEvent, USB_PipeEvent) == ARM_DRIVER_OK); 
104   
105   /* Uninitialize */
106   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
107 }
108
109 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
110 /**
111 \brief  Function: USBH_CheckInvalidInit
112 \details
113 The test function \b USBH_CheckInvalidInit verifies the driver behaviour when receiving an invalid initialization sequence:
114   - \b Uninitialize
115   - \b PowerControl with Power off
116   - \b PowerControl with Power on
117   - \b PowerControl with Power off
118   - \b Uninitialize
119 */
120 void USBH_CheckInvalidInit (void) { 
121
122   /* Uninitialize */
123   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
124   
125   /* Power off */
126   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
127   
128   /* Try to power on */
129   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) != ARM_DRIVER_OK); 
130   
131   /* Power off */
132   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
133   
134   /* Uninitialize */
135   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
136 }
137
138 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
139 /**
140 \brief  Function: USBH_PowerControl
141 \details
142 The test function \b USBH_PowerControl verifies the \b PowerControl function with the sequence:
143  - Initialize
144  - Power on
145  - Power low
146  - Power off
147  - Uninitialize 
148 */
149 void USBH_PowerControl (void) { 
150   int32_t val;
151   
152   /* Initialize with callback */
153   TEST_ASSERT(drv->Initialize(USB_PortEvent, USB_PipeEvent) == ARM_DRIVER_OK); 
154   
155   /* Power on */
156   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);  
157   
158   /* Power low */
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); }
162    
163   /* Power off */
164   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
165   
166   /* Uninitialize */
167   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
168 }
169
170 /**
171 @}
172 */ 
173 // end of group dv_usbh