]> begriffs open source - cmsis-driver-validation/blob - Source/DV_USBD.c
Changes:
[cmsis-driver-validation] / Source / DV_USBD.c
1 /*-----------------------------------------------------------------------------
2  *      Name:         DV_USBD.c
3  *      Purpose:      USB Device test cases
4  *----------------------------------------------------------------------------
5  *      Copyright(c) KEIL - An ARM Company
6  *----------------------------------------------------------------------------*/
7 #include "cmsis_dv.h" 
8 #include "DV_Config.h"
9 #include "DV_Framework.h"
10 #include "Driver_USBD.h"
11 #include <stdio.h>
12 #include <stdlib.h> 
13 #include <string.h> 
14
15 // Register Driver_USBD#
16 extern ARM_DRIVER_USBD CREATE_SYMBOL(Driver_USBD, DRV_USBD);
17 static ARM_DRIVER_USBD *drv = &CREATE_SYMBOL(Driver_USBD, DRV_USBD);
18 static ARM_USBD_CAPABILITIES capab;  
19
20 // Event flags
21 static uint8_t volatile DeviceEvent;  
22 static uint8_t volatile EndpointEvent; 
23
24 // USB Device event
25 static void USB_DeviceEvent (uint32_t event) {
26   DeviceEvent |= event;
27 }
28
29 // USB Endpoint event
30 static void USB_EndpointEvent (uint8_t endpoint, uint32_t event) {
31   (void) endpoint;
32   EndpointEvent |= event;
33 }
34
35
36 /*-----------------------------------------------------------------------------
37  *      Test cases
38  *----------------------------------------------------------------------------*/
39  
40 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
41 /**
42 \defgroup usbd_funcs USB Device Validation
43 \brief USB Device test cases
44 \details
45 The USB Device validation test checks the API interface compliance only. The section \ref usbd_comp_test explains how to run
46 the USB compliance tests. These tests check USB devices for conformance to the USB Device Framework which is required in
47 order to gain USB certification.
48 @{
49 */
50
51 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
52 /**
53 \brief Test case: USBD_GetCapabilities
54 \details
55 The test case \b USBD_GetCapabilities verifies the function \b GetCapabilities.
56 */
57 void USBD_GetCapabilities (void) {                    
58   /* Get USBD capabilities */
59   capab = drv->GetCapabilities();
60   TEST_ASSERT(&capab != NULL); 
61 }
62
63 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
64 /**
65 \brief  Test case: USBD_Initialization
66 \details
67 The test case \b USBD_Initialization verifies the USBD functions with the sequence:
68   - \b Initialize without callback
69   - \b Uninitialize
70   - \b Initialize with callback
71   - \b Uninitialize
72 */
73 void USBD_Initialization (void) { 
74     
75   /* Initialize without callback */
76   TEST_ASSERT(drv->Initialize(NULL, NULL) == ARM_DRIVER_OK); 
77     
78   /* Uninitialize */
79   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
80   
81   /* Initialize with callback */
82   TEST_ASSERT(drv->Initialize(USB_DeviceEvent, USB_EndpointEvent) == ARM_DRIVER_OK); 
83   
84   /* Uninitialize */
85   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
86 }
87
88 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
89 /**
90 \brief  Test case: USBD_CheckInvalidInit
91 \details
92 The test case \b USBD_CheckInvalidInit verifies the driver behaviour when receiving an invalid initialization sequence:
93   - \b Uninitialize
94   - \b PowerControl with Power off
95   - \b PowerControl with Power on
96   - \b PowerControl with Power off
97   - \b Uninitialize
98 */
99 void USBD_CheckInvalidInit (void) { 
100
101   /* Uninitialize */
102   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
103   
104   /* Power off */
105   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
106   
107   /* Try to power on */
108   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) != ARM_DRIVER_OK); 
109   
110   /* Power off */
111   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
112   
113   /* Uninitialize */
114   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
115 }
116
117 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
118 /**
119 \brief  Test case: USBD_PowerControl
120 \details
121 The test case \b USBD_PowerControl verifies the \b PowerControl function with the sequence:
122  - Initialize
123  - Power on
124  - Power low
125  - Power off
126  - Uninitialize 
127 */
128 void USBD_PowerControl (void) { 
129   int32_t val;
130   
131   /* Initialize with callback */
132   TEST_ASSERT(drv->Initialize(USB_DeviceEvent, USB_EndpointEvent) == ARM_DRIVER_OK); 
133   
134   /* Power on */
135   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);  
136   
137   /* Power low */
138   val = drv->PowerControl (ARM_POWER_LOW);
139   if (val == ARM_DRIVER_ERROR_UNSUPPORTED) { TEST_MESSAGE("[WARNING] Low power is not supported"); }
140   else { TEST_ASSERT(val == ARM_DRIVER_OK); }
141    
142   /* Power off */
143   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
144   
145   /* Uninitialize */
146   TEST_ASSERT(drv->Uninitialize() == ARM_DRIVER_OK); 
147 }
148
149 /**
150 @}
151 */ 
152 // end of group usbd_funcs