Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_device_class_cdc_acm.h"
#include "ux_device_stack.h"
...
...
_ux_device_class_cdc_acm_bulkin_thread(ULONG)
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/usbx_device_classes/src/ux_device_class_cdc_acm_bulkin_thread.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** USBX Component */ /** */ /** Device CDC_ACM Class */ /** */... /**************************************************************************/ /**************************************************************************/ #define UX_SOURCE_CODE /* Include necessary system files. */ #include "ux_api.h" #include "ux_device_class_cdc_acm.h" #include "ux_device_stack.h" #if !defined(UX_DEVICE_CLASS_CDC_ACM_TRANSMISSION_DISABLE) && !defined(UX_DEVICE_STANDALONE)... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_device_class_cdc_acm_bulkin_thread PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function is the thread of the cdc_acm bulkin endpoint. The bulk*/ /* IN endpoint is used when the device wants to write data to be sent */ /* to the host. */ /* */ /* It's for RTOS mode. */ /* */ /* INPUT */ /* */ /* cdc_acm_class Address of cdc_acm class */ /* container */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* _ux_device_stack_transfer_request Request transfer */ /* */ /* CALLED BY */ /* */ /* ThreadX */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* verified memset and memcpy */ /* cases, used UX prefix to */ /* refer to TX symbols instead */ /* of using them directly, */ /* resulting in version 6.1 */ /* 04-02-2021 Chaoqiong Xiao Modified comment(s), */ /* added macro to disable */ /* transmission support, */ /* resulting in version 6.1.6 */ /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ /* refined macros names, */ /* resulting in version 6.1.10 */ /* */... /**************************************************************************/ VOID _ux_device_class_cdc_acm_bulkin_thread(ULONG cdc_acm_class) { UX_SLAVE_CLASS_CDC_ACM *cdc_acm; UX_SLAVE_DEVICE *device; UX_SLAVE_ENDPOINT *endpoint; UX_SLAVE_INTERFACE *interface; UX_SLAVE_TRANSFER *transfer_request; UINT status; ULONG actual_flags; ULONG transfer_length; ULONG total_length; ULONG sent_length; /* Get the cdc_acm instance from this class container. */ UX_THREAD_EXTENSION_PTR_GET(cdc_acm, UX_SLAVE_CLASS_CDC_ACM, cdc_acm_class) /* Get the pointer to the device. */ device = &_ux_system_slave -> ux_system_slave_device; /* This is the first time we are activated. We need the interface to the class. */ interface = cdc_acm -> ux_slave_class_cdc_acm_interface; /* Locate the endpoints. */ endpoint = interface -> ux_slave_interface_first_endpoint; /* Check the endpoint direction, if IN we have the correct endpoint. */ if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN) { /* So the next endpoint has to be the IN endpoint. */ endpoint = endpoint -> ux_slave_endpoint_next_endpoint; }if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN) { ... } /* This thread runs forever but can be suspended or resumed. */ while(1) { /* Get the transfer request for the bulk IN pipe. */ transfer_request = &endpoint -> ux_slave_endpoint_transfer_request; /* As long as the device is in the CONFIGURED state. */ while (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED) { /* Wait until we have a event sent by the application. */ status = _ux_utility_event_flags_get(&cdc_acm -> ux_slave_class_cdc_acm_event_flags_group, UX_DEVICE_CLASS_CDC_ACM_WRITE_EVENT, UX_OR_CLEAR, &actual_flags, UX_WAIT_FOREVER); /* Check the completion code. */ if (status == UX_SUCCESS) { /* Get the length of the entire buffer to send. */ total_length = cdc_acm -> ux_slave_class_cdc_acm_callback_total_length; /* Duplicate the data pointer to keep a current pointer. */ cdc_acm -> ux_slave_class_cdc_acm_callback_current_data_pointer = cdc_acm -> ux_slave_class_cdc_acm_callback_data_pointer; /* Reset sent length. */ sent_length = 0; /* Special ZLP case. */ if (total_length == 0) /* Send the zlp to the host. */ status = _ux_device_stack_transfer_request(transfer_request, 0, 0); else { /* We should send the total length. But we may have a case of ZLP. */ while (total_length) { /* Check the length remaining to send. */ if (total_length > endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize) /* We can't fit all the length. */ transfer_length = endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize; else /* We can send everything. */ transfer_length = total_length; /* Copy the payload locally. */ _ux_utility_memory_copy (transfer_request -> ux_slave_transfer_request_data_pointer, cdc_acm -> ux_slave_class_cdc_acm_callback_current_data_pointer, transfer_length); /* Use case of memcpy is verified. */ /* Send the acm payload to the host. */ status = _ux_device_stack_transfer_request(transfer_request, transfer_length, transfer_length); /* Check the status. */ if (status != UX_SUCCESS) { /* Reset total_length as we need to get out of loop. */ total_length = 0; }if (status != UX_SUCCESS) { ... } else { /* Update sent length. */ sent_length += transfer_length; /* Decrement length to be sent. */ total_length -= transfer_length; /* And update the current pointer. */ cdc_acm -> ux_slave_class_cdc_acm_callback_current_data_pointer += transfer_length; }else { ... } }while (total_length) { ... } }else { ... } /* Schedule of transmission was completed. */ cdc_acm -> ux_slave_class_cdc_acm_scheduled_write = UX_FALSE; /* We get here when the entire user data payload has been sent or if there is an error. */ /* If there is a callback defined by the application, send the transaction event to it. */ if (cdc_acm -> ux_device_class_cdc_acm_write_callback != UX_NULL) /* Callback exists. */ cdc_acm -> ux_device_class_cdc_acm_write_callback(cdc_acm, status, sent_length); /* Now we return to wait for an event from the application or the user to stop the transmission. */ }if (status == UX_SUCCESS) { ... } else { break; }else { ... } }while (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED) { ... } /* We need to suspend ourselves. We will be resumed by the device enumeration module or when a change of alternate setting happens. */ _ux_device_thread_suspend(&cdc_acm -> ux_slave_class_cdc_acm_bulkin_thread); }while (1) { ... } }{ ... } #endif...