1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** USBX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** Device CDC_ACM Class */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define UX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "ux_api.h" |
28 |
|
|
#include "ux_device_class_cdc_acm.h" |
29 |
|
|
#include "ux_device_stack.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
#if !defined(UX_DEVICE_CLASS_CDC_ACM_TRANSMISSION_DISABLE) && !defined(UX_DEVICE_STANDALONE) |
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_device_class_cdc_acm_bulkout_thread PORTABLE C */ |
38 |
|
|
/* 6.3.0 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is the thread of the cdc_acm bulk out endpoint. It */ |
46 |
|
|
/* is waiting for the host to send data on the bulk out endpoint to */ |
47 |
|
|
/* the device. */ |
48 |
|
|
/* */ |
49 |
|
|
/* It's for RTOS mode. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* cdc_acm_class Address of cdc_acm class */ |
54 |
|
|
/* container */ |
55 |
|
|
/* */ |
56 |
|
|
/* OUTPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* None */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* _ux_device_stack_transfer_request Request transfer */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* ThreadX */ |
67 |
|
|
/* */ |
68 |
|
|
/**************************************************************************/ |
69 |
|
2 |
VOID _ux_device_class_cdc_acm_bulkout_thread(ULONG cdc_acm_class) |
70 |
|
|
{ |
71 |
|
|
|
72 |
|
|
UX_SLAVE_CLASS_CDC_ACM *cdc_acm; |
73 |
|
|
UX_SLAVE_DEVICE *device; |
74 |
|
|
UX_SLAVE_ENDPOINT *endpoint; |
75 |
|
|
UX_SLAVE_INTERFACE *interface_ptr; |
76 |
|
|
UX_SLAVE_TRANSFER *transfer_request; |
77 |
|
|
UINT status; |
78 |
|
|
|
79 |
|
|
/* Cast properly the cdc_acm instance. */ |
80 |
|
2 |
UX_THREAD_EXTENSION_PTR_GET(cdc_acm, UX_SLAVE_CLASS_CDC_ACM, cdc_acm_class) |
81 |
|
|
|
82 |
|
|
/* Get the pointer to the device. */ |
83 |
|
2 |
device = &_ux_system_slave -> ux_system_slave_device; |
84 |
|
|
|
85 |
|
|
/* This is the first time we are activated. We need the interface to the class. */ |
86 |
|
2 |
interface_ptr = cdc_acm -> ux_slave_class_cdc_acm_interface; |
87 |
|
|
|
88 |
|
|
/* Locate the endpoints. */ |
89 |
|
2 |
endpoint = interface_ptr -> ux_slave_interface_first_endpoint; |
90 |
|
|
|
91 |
|
|
/* Check the endpoint direction, if OUT we have the correct endpoint. */ |
92 |
✓✓ |
2 |
if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_OUT) |
93 |
|
|
{ |
94 |
|
|
|
95 |
|
|
/* So the next endpoint has to be the OUT endpoint. */ |
96 |
|
1 |
endpoint = endpoint -> ux_slave_endpoint_next_endpoint; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/* This thread runs forever but can be suspended or resumed by the user application. */ |
100 |
|
|
while(1) |
101 |
|
|
{ |
102 |
|
|
|
103 |
|
|
/* Select the transfer request associated with BULK OUT endpoint. */ |
104 |
|
5 |
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request; |
105 |
|
|
|
106 |
|
|
/* As long as the device is in the CONFIGURED state. */ |
107 |
✓✓ |
17 |
while (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED) |
108 |
|
|
{ |
109 |
|
|
|
110 |
|
|
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1 |
111 |
|
|
|
112 |
|
|
/* Use class managed buffer. */ |
113 |
|
|
transfer_request -> ux_slave_transfer_request_data_pointer = |
114 |
|
|
UX_DEVICE_CLASS_CDC_ACM_READ_BUFFER(cdc_acm); |
115 |
|
|
#endif |
116 |
|
|
|
117 |
|
|
/* Send the request to the device controller. */ |
118 |
|
14 |
status = _ux_device_stack_transfer_request(transfer_request, endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize, |
119 |
|
14 |
endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize); |
120 |
|
|
|
121 |
|
|
/* Check the completion code. */ |
122 |
✓✓ |
12 |
if (status == UX_SUCCESS) |
123 |
|
|
{ |
124 |
|
|
|
125 |
|
|
/* Check the state of the transfer. If there is an error, we do not proceed with this report. */ |
126 |
✓✓ |
8 |
if (transfer_request -> ux_slave_transfer_request_completion_code == UX_SUCCESS) |
127 |
|
|
{ |
128 |
|
|
|
129 |
|
|
/* If there is a callback defined by the application, send the transaction event to it. */ |
130 |
✓✓ |
6 |
if (cdc_acm -> ux_device_class_cdc_acm_read_callback != UX_NULL) |
131 |
|
|
|
132 |
|
|
/* Callback exists. */ |
133 |
|
4 |
cdc_acm -> ux_device_class_cdc_acm_read_callback(cdc_acm, UX_SUCCESS, transfer_request -> ux_slave_transfer_request_data_pointer, |
134 |
|
|
transfer_request -> ux_slave_transfer_request_actual_length); |
135 |
|
|
|
136 |
|
|
} |
137 |
|
|
else |
138 |
|
|
{ |
139 |
|
|
|
140 |
|
|
/* We have an error. If there is a callback defined by the application, send the transaction event to it. */ |
141 |
✓✓ |
2 |
if (cdc_acm -> ux_device_class_cdc_acm_read_callback != UX_NULL) |
142 |
|
|
|
143 |
|
|
/* Callback exists. */ |
144 |
|
1 |
cdc_acm -> ux_device_class_cdc_acm_read_callback(cdc_acm, status, UX_NULL, 0); |
145 |
|
|
|
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/* We need to suspend ourselves. We will be resumed by the application if needed. */ |
151 |
|
3 |
_ux_device_thread_suspend(&cdc_acm -> ux_slave_class_cdc_acm_bulkout_thread); |
152 |
|
|
} |
153 |
|
|
} |
154 |
|
|
#endif |