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 /** USBX Component */
15 /** */
16 /** Device CDC Class */
17 /** */
18 /**************************************************************************/
19 /**************************************************************************/
20
21 #define UX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "ux_api.h"
27 #include "ux_device_class_pima.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_pima_activate PORTABLE C */
36 /* 6.1.12 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function activates the USB Pima device. */
44 /* */
45 /* INPUT */
46 /* */
47 /* command Pointer to pima command */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* Completion Status */
52 /* */
53 /* CALLS */
54 /* */
55 /* _ux_device_thread_resume Resume thread */
56 /* */
57 /* CALLED BY */
58 /* */
59 /* USBX Source Code */
60 /* */
61 /* RELEASE HISTORY */
62 /* */
63 /* DATE NAME DESCRIPTION */
64 /* */
65 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
66 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
67 /* resulting in version 6.1 */
68 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
69 /* refined macros names, */
70 /* added variables initialize, */
71 /* resulting in version 6.1.10 */
72 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
73 /* fixed standalone compile, */
74 /* resulting in version 6.1.11 */
75 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
76 /* fixed parameter/variable */
77 /* names conflict C++ keyword, */
78 /* resulting in version 6.1.12 */
79 /* */
80 /**************************************************************************/
_ux_device_class_pima_activate(UX_SLAVE_CLASS_COMMAND * command)81 UINT _ux_device_class_pima_activate(UX_SLAVE_CLASS_COMMAND *command)
82 {
83
84 UX_SLAVE_INTERFACE *interface_ptr;
85 UX_SLAVE_CLASS *class_ptr;
86 UX_SLAVE_CLASS_PIMA *pima;
87 UX_SLAVE_ENDPOINT *endpoint_in;
88 UX_SLAVE_ENDPOINT *endpoint_out;
89 UX_SLAVE_ENDPOINT *endpoint_interrupt;
90
91
92 /* Get the class container. */
93 class_ptr = command -> ux_slave_class_command_class_ptr;
94
95 /* Store the class instance in the container. */
96 pima = (UX_SLAVE_CLASS_PIMA *) class_ptr -> ux_slave_class_instance;
97
98 /* Get the interface that owns this instance. */
99 interface_ptr = (UX_SLAVE_INTERFACE *) command -> ux_slave_class_command_interface;
100
101 /* Store the class instance into the interface. */
102 interface_ptr -> ux_slave_interface_class_instance = (VOID *)pima;
103
104 /* Now the opposite, store the interface in the class instance. */
105 pima -> ux_slave_class_pima_interface = interface_ptr;
106
107 /* Locate the endpoints. */
108 endpoint_in = interface_ptr -> ux_slave_interface_first_endpoint;
109
110 /* Check the endpoint direction, if IN we have the correct endpoint. */
111 if ((endpoint_in -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_OUT)
112 {
113
114 /* Wrong direction, we found the OUT endpoint first. */
115 endpoint_out = endpoint_in;
116
117 /* So the next endpoint has to be the IN endpoint. */
118 endpoint_in = endpoint_out -> ux_slave_endpoint_next_endpoint;
119
120 /* And the endpoint after that interrupt. */
121 endpoint_interrupt = endpoint_in -> ux_slave_endpoint_next_endpoint;
122
123 }
124 else
125 {
126
127 /* We found the endpoint IN first, so next endpoint is OUT. */
128 endpoint_out = endpoint_in -> ux_slave_endpoint_next_endpoint;
129
130 /* And the endpoint after that interrupt. */
131 endpoint_interrupt = endpoint_out -> ux_slave_endpoint_next_endpoint;
132 }
133
134 /* Save the endpoints in the pima instance. */
135 pima -> ux_device_class_pima_bulk_in_endpoint = endpoint_in;
136 pima -> ux_device_class_pima_bulk_out_endpoint = endpoint_out;
137 pima -> ux_device_class_pima_interrupt_endpoint = endpoint_interrupt;
138
139 /* Initialize status code. */
140 pima -> ux_device_class_pima_state = UX_DEVICE_CLASS_PIMA_PHASE_IDLE;
141 pima -> ux_device_class_pima_session_id = 0;
142 pima -> ux_device_class_pima_device_status = UX_DEVICE_CLASS_PIMA_RC_OK;
143
144 /* Resume thread. */
145 _ux_device_thread_resume(&class_ptr -> ux_slave_class_thread);
146
147 /* If there is a activate function call it. */
148 if (pima -> ux_device_class_pima_instance_activate != UX_NULL)
149 {
150 /* Invoke the application. */
151 pima -> ux_device_class_pima_instance_activate(pima);
152 }
153
154 /* If trace is enabled, insert this event into the trace buffer. */
155 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_ACTIVATE, pima, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
156
157 /* If trace is enabled, register this object. */
158 UX_TRACE_OBJECT_REGISTER(UX_TRACE_DEVICE_OBJECT_TYPE_INTERFACE, pima, 0, 0, 0)
159
160 /* Return completion status. */
161 return(UX_SUCCESS);
162 }
163
164