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 |
|
|
/** 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_callback PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is the callback from the USBX transfer functions, */ |
46 |
|
|
/* it is called when a full or partial transfer has been done for a */ |
47 |
|
|
/* bulk in transfer. It calls back the application. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* transfer_request Pointer to transfer request */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* None */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _ux_host_stack_transfer_request Process transfer request */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* Application */ |
64 |
|
|
/* */ |
65 |
|
|
/**************************************************************************/ |
66 |
|
430 |
VOID _ux_host_class_cdc_acm_reception_callback (UX_TRANSFER *transfer_request) |
67 |
|
|
{ |
68 |
|
|
|
69 |
|
|
UX_HOST_CLASS_CDC_ACM *cdc_acm; |
70 |
|
|
UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception; |
71 |
|
|
|
72 |
|
|
/* Get the class instance for this transfer request. */ |
73 |
|
430 |
cdc_acm = (UX_HOST_CLASS_CDC_ACM *) transfer_request -> ux_transfer_request_class_instance; |
74 |
|
|
|
75 |
|
|
/* Get the pointer to the acm reception structure. */ |
76 |
|
430 |
cdc_acm_reception = cdc_acm -> ux_host_class_cdc_acm_reception; |
77 |
|
|
|
78 |
|
|
/* Check the state of the transfer. If there is an error, we do not proceed with this report. */ |
79 |
✓✓ |
430 |
if (transfer_request -> ux_transfer_request_completion_code != UX_SUCCESS) |
80 |
|
|
{ |
81 |
|
|
|
82 |
|
|
/* The reception is stopped. */ |
83 |
|
8 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_state = UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED; |
84 |
|
|
|
85 |
|
|
/* We do not proceed. */ |
86 |
|
8 |
return; |
87 |
|
|
|
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
/* Move to the next reception buffer. Check if we are at the end of the application buffer. */ |
91 |
|
422 |
if (cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head + cdc_acm_reception -> ux_host_class_cdc_acm_reception_block_size >= |
92 |
✓✓ |
422 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_buffer + cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_buffer_size) |
93 |
|
|
|
94 |
|
|
/* Program the head to be at the beginning of the application buffer. */ |
95 |
|
48 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head = cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_buffer; |
96 |
|
|
|
97 |
|
|
else |
98 |
|
|
|
99 |
|
|
/* Program the head to be after the current buffer. */ |
100 |
|
374 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head += cdc_acm_reception -> ux_host_class_cdc_acm_reception_block_size; |
101 |
|
|
|
102 |
|
|
/* OVERFLOW check: if the head reaches the tail buffer that contains reception data */ |
103 |
✓✓ |
422 |
if (cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_tail == cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head) |
104 |
|
|
{ |
105 |
|
|
|
106 |
|
|
/* Error trap. */ |
107 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_BUFFER_OVERFLOW); |
108 |
|
|
|
109 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
110 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_BUFFER_OVERFLOW, transfer_request, 0, 0, UX_TRACE_ERRORS, 0, 0) |
111 |
|
|
|
112 |
|
|
/* We have an overflow. We cannot continue. Report to the application. */ |
113 |
|
1 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_callback(cdc_acm, UX_BUFFER_OVERFLOW, UX_NULL, 0); |
114 |
|
|
|
115 |
|
|
/* And stop the transfer in progress flag. */ |
116 |
|
1 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_state = UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED; |
117 |
|
|
|
118 |
|
1 |
return; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
/* We need to report this transfer to the application. */ |
122 |
|
421 |
cdc_acm_reception -> ux_host_class_cdc_acm_reception_callback(cdc_acm, |
123 |
|
|
transfer_request -> ux_transfer_request_completion_code, |
124 |
|
|
transfer_request -> ux_transfer_request_data_pointer, |
125 |
|
|
transfer_request -> ux_transfer_request_actual_length); |
126 |
|
|
|
127 |
|
|
/* Set data pointer to the next reception buffer. */ |
128 |
|
421 |
transfer_request -> ux_transfer_request_data_pointer = cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head; |
129 |
|
|
|
130 |
|
|
/* Arm another transfer. */ |
131 |
|
421 |
_ux_host_stack_transfer_request(transfer_request); |
132 |
|
|
|
133 |
|
|
/* There is no status to be reported back to the stack. */ |
134 |
|
421 |
return; |
135 |
|
|
} |
136 |
|
|
|