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 CCID 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_ccid.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_ccid_activate PORTABLE C */
36 /* 6.2.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function activates the USB CCID device. */
44 /* */
45 /* INPUT */
46 /* */
47 /* command Pointer to ccid command */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* Completion Status */
52 /* */
53 /* CALLS */
54 /* */
55 /* None */
56 /* */
57 /* CALLED BY */
58 /* */
59 /* USBX Device CCID */
60 /* */
61 /* RELEASE HISTORY */
62 /* */
63 /* DATE NAME DESCRIPTION */
64 /* */
65 /* 04-25-2022 Chaoqiong Xiao Initial Version 6.1.11 */
66 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
67 /* fixed parameter/variable */
68 /* names conflict C++ keyword, */
69 /* resulting in version 6.1.12 */
70 /* 03-08-2023 Chaoqiong Xiao Modified comment(s), */
71 /* added standalone support, */
72 /* resulting in version 6.2.1 */
73 /* */
74 /**************************************************************************/
_ux_device_class_ccid_activate(UX_SLAVE_CLASS_COMMAND * command)75 UINT _ux_device_class_ccid_activate(UX_SLAVE_CLASS_COMMAND *command)
76 {
77
78 UX_SLAVE_INTERFACE *ccid_interface;
79 UX_SLAVE_CLASS *ccid_class;
80 UX_DEVICE_CLASS_CCID *ccid;
81 UX_SLAVE_ENDPOINT *endpoint;
82 ULONG endpoint_type;
83 #if !defined(UX_DEVICE_STANDALONE)
84 UINT i;
85 #endif
86
87 /* Get the class container. */
88 ccid_class = command -> ux_slave_class_command_class_ptr;
89
90 /* Get the class instance in the container. */
91 ccid = (UX_DEVICE_CLASS_CCID *) ccid_class -> ux_slave_class_instance;
92
93 /* Get the interface that owns this instance. */
94 ccid_interface = (UX_SLAVE_INTERFACE *) command -> ux_slave_class_command_interface;
95
96 /* Store the class instance into the interface. */
97 ccid_interface -> ux_slave_interface_class_instance = (VOID *)ccid;
98
99 /* Now the opposite, store the interface in the class instance. */
100 ccid -> ux_device_class_ccid_interface = ccid_interface;
101
102 /* Save endpoints. */
103 ccid -> ux_device_class_ccid_endpoint_notify = UX_NULL;
104 endpoint = ccid_interface -> ux_slave_interface_first_endpoint;
105 while(endpoint)
106 {
107 endpoint_type = endpoint -> ux_slave_endpoint_descriptor.bmAttributes;
108 endpoint_type &= UX_MASK_ENDPOINT_TYPE;
109 if (endpoint_type == UX_INTERRUPT_ENDPOINT)
110 {
111 ccid -> ux_device_class_ccid_endpoint_notify = endpoint;
112 }
113 if (endpoint_type == UX_BULK_ENDPOINT)
114 {
115 if (endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_IN)
116 ccid -> ux_device_class_ccid_endpoint_in = endpoint;
117 else
118 ccid -> ux_device_class_ccid_endpoint_out = endpoint;
119 }
120 endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
121 }
122
123 #if defined(UX_DEVICE_STANDALONE)
124
125 /* Initialize slots (optimized for 1 slot). */
126 ccid -> ux_device_class_ccid_slots -> ux_device_class_ccid_slot_runner = -1;
127 ccid -> ux_device_class_ccid_slots -> ux_device_class_ccid_slot_icc_status =
128 UX_DEVICE_CLASS_CCID_ICC_NOT_PRESENT;
129
130 /* Initialize task states. */
131 ccid -> ux_device_class_ccid_cmd_state = UX_DEVICE_CLASS_CCID_CMD_START;
132 ccid -> ux_device_class_ccid_rsp_state = UX_DEVICE_CLASS_CCID_RSP_IDLE;
133 ccid -> ux_device_class_ccid_notify_state = UX_DEVICE_CLASS_CCID_NOTIFY_IDLE;
134
135 /* Initialize runner task state (optimized for 1 slot). */
136 ccid -> ux_device_class_ccid_runners -> ux_device_class_ccid_runner_state = UX_DEVICE_CLASS_CCID_RUNNER_IDLE;
137 #else
138
139 /* Initialize slots. */
140 for (i = 0;
141 i < ccid -> ux_device_class_ccid_parameter.ux_device_class_ccid_max_n_slots;
142 i ++)
143 {
144 ccid -> ux_device_class_ccid_slots[i].ux_device_class_ccid_slot_runner = -1;
145 ccid -> ux_device_class_ccid_slots[i].ux_device_class_ccid_slot_icc_status =
146 UX_DEVICE_CLASS_CCID_ICC_NOT_PRESENT;
147 }
148
149 /* Activate thread for Bulk-OUT command messages. */
150 _ux_device_thread_resume(&ccid -> ux_device_class_ccid_thread);
151
152 /* Activate thread for Interrupt-IN notification messages. */
153 _ux_device_thread_resume(&ccid -> ux_device_class_ccid_notify_thread);
154
155 /* Activate threads for runners. */
156 for (i = 0;
157 i < ccid -> ux_device_class_ccid_parameter.ux_device_class_ccid_max_n_busy_slots;
158 i ++)
159 {
160 _ux_device_thread_resume(&ccid -> ux_device_class_ccid_runners[i].
161 ux_device_class_ccid_runner_thread);
162 }
163 #endif
164
165 /* If there is a activate function call it. */
166 if (ccid -> ux_device_class_ccid_parameter.ux_device_class_ccid_instance_activate != UX_NULL)
167 {
168
169 /* Invoke the application callback. */
170 ccid -> ux_device_class_ccid_parameter.ux_device_class_ccid_instance_activate(ccid);
171 }
172
173 /* If trace is enabled, insert this event into the trace buffer. */
174 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_CCID_ACTIVATE, ccid, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
175
176 /* If trace is enabled, register this object. */
177 UX_TRACE_OBJECT_REGISTER(UX_TRACE_DEVICE_OBJECT_TYPE_INTERFACE, ccid, 0, 0, 0)
178
179 /* Return completion status. */
180 return(UX_SUCCESS);
181 }
182