1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Device Data Pump Class */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define UX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "ux_api.h"
29 #include "ux_device_class_dpump.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_device_class_dpump_activate PORTABLE C */
37 /* 6.1.12 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function activates the USB dpump device. */
45 /* */
46 /* INPUT */
47 /* */
48 /* command Pointer to dpump command */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* Completion Status */
53 /* */
54 /* CALLS */
55 /* */
56 /* None */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Device Data Pump Class */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
67 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
68 /* resulting in version 6.1 */
69 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
70 /* added standalone support, */
71 /* resulting in version 6.1.10 */
72 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
73 /* fixed parameter/variable */
74 /* names conflict C++ keyword, */
75 /* resulting in version 6.1.12 */
76 /* */
77 /**************************************************************************/
_ux_device_class_dpump_activate(UX_SLAVE_CLASS_COMMAND * command)78 UINT _ux_device_class_dpump_activate(UX_SLAVE_CLASS_COMMAND *command)
79 {
80
81 UX_SLAVE_INTERFACE *interface_ptr;
82 UX_SLAVE_CLASS_DPUMP *dpump;
83 UX_SLAVE_CLASS *class_ptr;
84 UX_SLAVE_ENDPOINT *endpoint;
85
86 /* Get the class container. */
87 class_ptr = command -> ux_slave_class_command_class_ptr;
88
89 /* Store the class instance in the container. */
90 dpump = (UX_SLAVE_CLASS_DPUMP *) class_ptr -> ux_slave_class_instance;
91
92 /* Get the interface that owns this instance. */
93 interface_ptr = (UX_SLAVE_INTERFACE *) command -> ux_slave_class_command_interface;
94
95 /* Store the class instance into the interface. */
96 interface_ptr -> ux_slave_interface_class_instance = (VOID *)dpump;
97
98 /* Now the opposite, store the interface in the class instance. */
99 dpump -> ux_slave_class_dpump_interface = interface_ptr;
100
101 /* Locate the endpoints. Interrupt for Control and Bulk in/out for Data. */
102 endpoint = interface_ptr -> ux_slave_interface_first_endpoint;
103
104 /* Parse all endpoints. */
105 while (endpoint != UX_NULL)
106 {
107
108 /* Check the endpoint direction, and type. */
109 if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN)
110 {
111
112 /* Look at type. */
113 if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)
114
115 /* We have found the bulk in endpoint, save it. */
116 dpump -> ux_slave_class_dpump_bulkin_endpoint = endpoint;
117
118 }
119 else
120 {
121 /* Look at type for out endpoint. */
122 if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)
123
124 /* We have found the bulk out endpoint, save it. */
125 dpump -> ux_slave_class_dpump_bulkout_endpoint = endpoint;
126 }
127
128 /* Next endpoint. */
129 endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
130 }
131
132 #if defined(UX_DEVICE_STANDALONE)
133
134 /* Reset read/write states. */
135 dpump -> ux_device_class_dpump_read_state = 0;
136 dpump -> ux_device_class_dpump_write_state = 0;
137 #endif
138
139 /* If there is a activate function call it. */
140 if (dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_activate != UX_NULL)
141 {
142
143 /* Invoke the application. */
144 dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_activate(dpump);
145 }
146
147 /* If trace is enabled, insert this event into the trace buffer. */
148 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_DPUMP_ACTIVATE, dpump, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
149
150 /* If trace is enabled, register this object. */
151 UX_TRACE_OBJECT_REGISTER(UX_TRACE_DEVICE_OBJECT_TYPE_INTERFACE, dpump, 0, 0, 0)
152
153 /* Return completion status. */
154 return(UX_SUCCESS);
155 }
156
157