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 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** ACM CDC Class */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /* Include necessary system files. */
25
26 #define UX_SOURCE_CODE
27
28 #include "ux_api.h"
29 #include "ux_host_class_cdc_acm.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_cdc_acm_reception_stop PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function stops background reception previously started by */
46 /* ux_host_class_cdc_acm_reception_start. */
47 /* */
48 /* INPUT */
49 /* */
50 /* cdc_acm Pointer to cdc_acm class */
51 /* cdc_acm_reception Pointer to reception struct */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_host_stack_endpoint_transfer_abort */
60 /* Abort transfer */
61 /* _ux_host_semaphore_get Get semaphore */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
72 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
75 /* added standalone support, */
76 /* resulting in version 6.1.10 */
77 /* */
78 /**************************************************************************/
_ux_host_class_cdc_acm_reception_stop(UX_HOST_CLASS_CDC_ACM * cdc_acm,UX_HOST_CLASS_CDC_ACM_RECEPTION * cdc_acm_reception)79 UINT _ux_host_class_cdc_acm_reception_stop(UX_HOST_CLASS_CDC_ACM *cdc_acm,
80 UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception)
81 {
82
83 UX_TRANSFER *transfer_request;
84
85 /* If trace is enabled, insert this event into the trace buffer. */
86 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_RECEPTION_STOP, cdc_acm, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
87
88 /* Ensure the instance is valid. */
89 if (cdc_acm -> ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE)
90 {
91
92 /* Error trap. */
93 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
94
95 /* If trace is enabled, insert this event into the trace buffer. */
96 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
97
98 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
99 }
100
101 /* As further protection, we must ensure this instance of the interface is the data interface and not
102 the control interface ! */
103 if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass != UX_HOST_CLASS_CDC_DATA_CLASS)
104 {
105
106 /* Error trap. */
107 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
108
109 /* If trace is enabled, insert this event into the trace buffer. */
110 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
111
112 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
113 }
114
115 /* Check if we do have transfers for this application. If none, nothing to do. */
116 if (cdc_acm_reception -> ux_host_class_cdc_acm_reception_state == UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED)
117 return(UX_SUCCESS);
118
119 /* We need to abort transactions on the bulk In pipe. */
120 _ux_host_stack_endpoint_transfer_abort(cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint);
121
122 /* Declare the reception stopped. */
123 cdc_acm_reception -> ux_host_class_cdc_acm_reception_state = UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED;
124
125 /* Obtain pointer to transfer request. */
126 transfer_request = &cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint -> ux_endpoint_transfer_request;
127
128 /* Reset the completion callback function. */
129 transfer_request -> ux_transfer_request_completion_function = UX_NULL;
130
131 #if !defined(UX_HOST_STANDALONE)
132
133 /* Clear semaphore counts that were (incorrectly) increased during each transfer
134 completion. */
135 while (transfer_request -> ux_transfer_request_semaphore.tx_semaphore_count)
136 _ux_host_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, 0);
137 #endif
138
139 /* This function never really fails. */
140 return(UX_SUCCESS);
141 }
142
143