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 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Device CDC ACM 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_cdc_acm.h" |
30 |
|
|
#include "ux_device_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_device_class_cdc_acm_deactivate PORTABLE C */ |
38 |
|
|
/* 6.1.12 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function deactivate an instance of the cdc_acm class. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* command Pointer to a class command */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* Completion Status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _ux_device_stack_transfer_all_request_abort Abort all transfers */ |
58 |
|
|
/* _ux_device_class_cdc_acm_ioctl IO control */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLED BY */ |
61 |
|
|
/* */ |
62 |
|
|
/* CDC Class */ |
63 |
|
|
/* */ |
64 |
|
|
/**************************************************************************/ |
65 |
|
73 |
UINT _ux_device_class_cdc_acm_deactivate(UX_SLAVE_CLASS_COMMAND *command) |
66 |
|
|
{ |
67 |
|
|
|
68 |
|
|
UX_SLAVE_INTERFACE *interface_ptr; |
69 |
|
|
UX_SLAVE_CLASS *class_ptr; |
70 |
|
|
UX_SLAVE_CLASS_CDC_ACM *cdc_acm; |
71 |
|
|
UX_SLAVE_ENDPOINT *endpoint_in; |
72 |
|
|
UX_SLAVE_ENDPOINT *endpoint_out; |
73 |
|
|
|
74 |
|
|
/* Get the class container. */ |
75 |
|
73 |
class_ptr = command -> ux_slave_class_command_class_ptr; |
76 |
|
|
|
77 |
|
|
/* Get the class instance in the container. */ |
78 |
|
73 |
cdc_acm = (UX_SLAVE_CLASS_CDC_ACM *) class_ptr -> ux_slave_class_instance; |
79 |
|
|
|
80 |
|
|
/* We need the interface to the class. */ |
81 |
|
73 |
interface_ptr = cdc_acm -> ux_slave_class_cdc_acm_interface; |
82 |
|
|
|
83 |
|
|
/* Locate the endpoints. */ |
84 |
|
73 |
endpoint_in = interface_ptr -> ux_slave_interface_first_endpoint; |
85 |
|
|
|
86 |
|
|
/* Check the endpoint direction, if IN we have the correct endpoint. */ |
87 |
✓✓ |
73 |
if ((endpoint_in -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
/* Wrong direction, we found the OUT endpoint first. */ |
91 |
|
27 |
endpoint_out = endpoint_in; |
92 |
|
|
|
93 |
|
|
/* So the next endpoint has to be the IN endpoint. */ |
94 |
|
27 |
endpoint_in = endpoint_out -> ux_slave_endpoint_next_endpoint; |
95 |
|
|
} |
96 |
|
|
else |
97 |
|
|
{ |
98 |
|
|
|
99 |
|
|
/* We found the endpoint IN first, so next endpoint is OUT. */ |
100 |
|
46 |
endpoint_out = endpoint_in -> ux_slave_endpoint_next_endpoint; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
/* Terminate the transactions pending on the endpoints. */ |
104 |
|
73 |
_ux_device_stack_transfer_all_request_abort(endpoint_in, UX_TRANSFER_BUS_RESET); |
105 |
|
73 |
_ux_device_stack_transfer_all_request_abort(endpoint_out, UX_TRANSFER_BUS_RESET); |
106 |
|
|
|
107 |
|
|
/* Terminate transmission and free resources. */ |
108 |
|
73 |
_ux_device_class_cdc_acm_ioctl(cdc_acm, UX_SLAVE_CLASS_CDC_ACM_IOCTL_TRANSMISSION_STOP, UX_NULL); |
109 |
|
|
|
110 |
|
|
/* If there is a deactivate function call it. */ |
111 |
✓✓ |
73 |
if (cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_instance_deactivate != UX_NULL) |
112 |
|
|
{ |
113 |
|
|
|
114 |
|
|
/* Invoke the application. */ |
115 |
|
72 |
cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_instance_deactivate(cdc_acm); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/* We need to reset the DTR and RTS values so they do not carry over to the |
119 |
|
|
next connection. */ |
120 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_data_dtr_state = 0; |
121 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_data_rts_state = 0; |
122 |
|
|
|
123 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_break_duration = 0; |
124 |
|
|
|
125 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
126 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_CDC_ACM_DEACTIVATE, cdc_acm, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0) |
127 |
|
|
|
128 |
|
|
/* If trace is enabled, register this object. */ |
129 |
|
|
UX_TRACE_OBJECT_UNREGISTER(cdc_acm); |
130 |
|
|
|
131 |
|
|
/* Return completion status. */ |
132 |
|
73 |
return(UX_SUCCESS); |
133 |
|
|
} |