1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** USBX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** ACM CDC Class */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
/* Include necessary system files. */ |
24 |
|
|
|
25 |
|
|
#define UX_SOURCE_CODE |
26 |
|
|
|
27 |
|
|
#include "ux_api.h" |
28 |
|
|
#include "ux_host_class_cdc_acm.h" |
29 |
|
|
#include "ux_host_stack.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _ux_host_class_cdc_acm_reception_start PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function starts a reception with the ACM modem. This mechanism */ |
45 |
|
|
/* allows for non blocking calls based on a packet orientated round */ |
46 |
|
|
/* robbin buffer. When a packet is fully or partially received, an */ |
47 |
|
|
/* application callback function is invoked and a new transfer request */ |
48 |
|
|
/* is rescheduled. */ |
49 |
|
|
/* */ |
50 |
|
|
/* INPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* cdc_acm Pointer to cdc_acm class */ |
53 |
|
|
/* cdc_acm_reception Pointer to reception struct */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* Completion Status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* _ux_host_stack_transfer_request Process transfer request */ |
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 |
|
|
/* */ |
75 |
|
|
/**************************************************************************/ |
76 |
|
13 |
UINT _ux_host_class_cdc_acm_reception_start (UX_HOST_CLASS_CDC_ACM *cdc_acm, |
77 |
|
|
UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception) |
78 |
|
|
{ |
79 |
|
|
|
80 |
|
|
UX_TRANSFER *transfer_request; |
81 |
|
|
UINT status; |
82 |
|
|
|
83 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
84 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_RECEPTION_START, cdc_acm, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) |
85 |
|
|
|
86 |
|
|
/* Ensure the instance is valid. */ |
87 |
✓✓ |
13 |
if (cdc_acm -> ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
/* Error trap. */ |
91 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN); |
92 |
|
|
|
93 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
94 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0) |
95 |
|
|
|
96 |
|
1 |
return(UX_HOST_CLASS_INSTANCE_UNKNOWN); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/* As further protection, we must ensure this instance of the interface is the data interface and not |
100 |
|
|
the control interface ! */ |
101 |
✓✓ |
12 |
if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass != UX_HOST_CLASS_CDC_DATA_CLASS) |
102 |
|
|
{ |
103 |
|
|
|
104 |
|
|
/* Error trap. */ |
105 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN); |
106 |
|
|
|
107 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
108 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0) |
109 |
|
|
|
110 |
|
1 |
return(UX_HOST_CLASS_INSTANCE_UNKNOWN); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
/* Start by aligning the head and tail of buffers to the same address supplied by the application. */ |
114 |
|
11 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head = cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_buffer; |
115 |
|
11 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_tail = cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_buffer; |
116 |
|
|
|
117 |
|
|
/* Get the pointer to the bulk in endpoint in the transfer_request. */ |
118 |
|
11 |
transfer_request = &cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint -> ux_endpoint_transfer_request; |
119 |
|
|
|
120 |
|
|
/* Initialize the transfer request. */ |
121 |
|
11 |
transfer_request -> ux_transfer_request_class_instance = (VOID *) cdc_acm; |
122 |
|
11 |
transfer_request -> ux_transfer_request_data_pointer = cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head; |
123 |
|
11 |
transfer_request -> ux_transfer_request_requested_length = cdc_acm_reception -> ux_host_class_cdc_acm_reception_block_size; |
124 |
|
11 |
transfer_request -> ux_transfer_request_completion_function = _ux_host_class_cdc_acm_reception_callback; |
125 |
|
|
|
126 |
|
|
/* Save the acm reception structure in the acm structure. */ |
127 |
|
11 |
cdc_acm -> ux_host_class_cdc_acm_reception = cdc_acm_reception; |
128 |
|
|
|
129 |
|
|
/* And declare we have a transfer in progress. */ |
130 |
|
11 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_state = UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STARTED; |
131 |
|
|
|
132 |
|
|
/* Arm a first transfer on the bulk in endpoint. There is a callback to this function so we return to the caller |
133 |
|
|
right away. */ |
134 |
|
11 |
status = _ux_host_stack_transfer_request(transfer_request); |
135 |
|
|
|
136 |
|
|
/* We do not know if the first transfer was successful yet. If the status is not OK, we need to stop the transfer |
137 |
|
|
in progress flag. */ |
138 |
✓✓ |
11 |
if (status != UX_SUCCESS) |
139 |
|
1 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_state = UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED; |
140 |
|
|
|
141 |
|
11 |
return(status); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
|
145 |
|
|
/**************************************************************************/ |
146 |
|
|
/* */ |
147 |
|
|
/* FUNCTION RELEASE */ |
148 |
|
|
/* */ |
149 |
|
|
/* _uxe_host_class_cdc_acm_reception_start PORTABLE C */ |
150 |
|
|
/* 6.3.0 */ |
151 |
|
|
/* AUTHOR */ |
152 |
|
|
/* */ |
153 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
154 |
|
|
/* */ |
155 |
|
|
/* DESCRIPTION */ |
156 |
|
|
/* */ |
157 |
|
|
/* This function checks errors in CDC ACM reception function call. */ |
158 |
|
|
/* */ |
159 |
|
|
/* INPUT */ |
160 |
|
|
/* */ |
161 |
|
|
/* cdc_acm Pointer to CDC ACM class */ |
162 |
|
|
/* cdc_acm_reception Pointer to reception struct */ |
163 |
|
|
/* */ |
164 |
|
|
/* OUTPUT */ |
165 |
|
|
/* */ |
166 |
|
|
/* Status */ |
167 |
|
|
/* */ |
168 |
|
|
/* CALLS */ |
169 |
|
|
/* */ |
170 |
|
|
/* _ux_host_class_cdc_acm_reception_start */ |
171 |
|
|
/* CDC ACM reception start */ |
172 |
|
|
/* */ |
173 |
|
|
/* CALLED BY */ |
174 |
|
|
/* */ |
175 |
|
|
/* Application */ |
176 |
|
|
/* */ |
177 |
|
|
/* RELEASE HISTORY */ |
178 |
|
|
/* */ |
179 |
|
|
/* DATE NAME DESCRIPTION */ |
180 |
|
|
/* */ |
181 |
|
|
/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ |
182 |
|
|
/* */ |
183 |
|
|
/**************************************************************************/ |
184 |
|
|
UINT _uxe_host_class_cdc_acm_reception_start (UX_HOST_CLASS_CDC_ACM *cdc_acm, |
185 |
|
|
UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception) |
186 |
|
|
{ |
187 |
|
|
|
188 |
|
|
/* Sanity checks. */ |
189 |
|
|
if ((cdc_acm == UX_NULL) || (cdc_acm_reception == UX_NULL)) |
190 |
|
|
return(UX_INVALID_PARAMETER); |
191 |
|
|
|
192 |
|
|
/* Invoke CDC ACM reception start function. */ |
193 |
|
|
return(_ux_host_class_cdc_acm_reception_start(cdc_acm, cdc_acm_reception)); |
194 |
|
|
} |