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 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 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _ux_device_class_cdc_acm_entry PORTABLE C */ |
37 |
|
|
/* 6.x */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function is the entry point of the cdc_acm class. It */ |
45 |
|
|
/* will be called by the device stack enumeration module when the */ |
46 |
|
|
/* host has sent a SET_CONFIGURATION command and the cdc_acm interface */ |
47 |
|
|
/* needs to be mounted. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* command Pointer to class command */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* Completion Status */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _ux_device_class_cdc_acm_initialize Initialize cdc_acm class */ |
60 |
|
|
/* _ux_device_class_cdc_acm_uninitialize Uninitialize cdc_acm class*/ |
61 |
|
|
/* _ux_device_class_cdc_acm_activate Activate cdc_acm class */ |
62 |
|
|
/* _ux_device_class_cdc_acm_deactivate Deactivate cdc_acm class */ |
63 |
|
|
/* _ux_device_class_cdc_acm_control_request Request control */ |
64 |
|
|
/* */ |
65 |
|
|
/* CALLED BY */ |
66 |
|
|
/* */ |
67 |
|
|
/* CDC Class */ |
68 |
|
|
/* */ |
69 |
|
|
/**************************************************************************/ |
70 |
|
691 |
UINT _ux_device_class_cdc_acm_entry(UX_SLAVE_CLASS_COMMAND *command) |
71 |
|
|
{ |
72 |
|
|
|
73 |
|
|
UINT status; |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
/* The command request will tell us we need to do here, either a enumeration |
77 |
|
|
query, an activation or a deactivation. */ |
78 |
✓✓✓✓ ✓✓✓ |
691 |
switch (command -> ux_slave_class_command_request) |
79 |
|
|
{ |
80 |
|
|
|
81 |
|
68 |
case UX_SLAVE_CLASS_COMMAND_INITIALIZE: |
82 |
|
|
|
83 |
|
|
/* Call the init function of the CDC ACM class. */ |
84 |
|
68 |
status = _ux_device_class_cdc_acm_initialize(command); |
85 |
|
|
|
86 |
|
|
/* Return the completion status. */ |
87 |
|
68 |
return(status); |
88 |
|
|
|
89 |
|
50 |
case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE: |
90 |
|
|
|
91 |
|
|
/* Call the uninit function of the CDC ACM class. */ |
92 |
|
50 |
status = _ux_device_class_cdc_acm_uninitialize(command); |
93 |
|
|
|
94 |
|
|
/* Return the completion status. */ |
95 |
|
50 |
return(status); |
96 |
|
|
|
97 |
|
182 |
case UX_SLAVE_CLASS_COMMAND_QUERY: |
98 |
|
|
|
99 |
|
|
/* Check the CLASS definition in the interface descriptor. */ |
100 |
✓✓ |
182 |
if (command -> ux_slave_class_command_class == UX_SLAVE_CLASS_CDC_ACM_CLASS) |
101 |
|
90 |
return(UX_SUCCESS); |
102 |
|
|
else |
103 |
|
92 |
return(UX_NO_CLASS_MATCH); |
104 |
|
|
|
105 |
|
90 |
case UX_SLAVE_CLASS_COMMAND_ACTIVATE: |
106 |
|
|
|
107 |
|
|
/* The activate command is used when the host has sent a SET_CONFIGURATION command |
108 |
|
|
and this interface has to be mounted. Both Bulk endpoints have to be mounted |
109 |
|
|
and the cdc_acm thread needs to be activated. */ |
110 |
|
90 |
status = _ux_device_class_cdc_acm_activate(command); |
111 |
|
|
|
112 |
|
|
/* Return the completion status. */ |
113 |
|
90 |
return(status); |
114 |
|
|
|
115 |
|
73 |
case UX_SLAVE_CLASS_COMMAND_DEACTIVATE: |
116 |
|
|
|
117 |
|
|
/* The deactivate command is used when the device has been extracted. |
118 |
|
|
The device endpoints have to be dismounted and the cdc_acm thread canceled. */ |
119 |
|
73 |
status = _ux_device_class_cdc_acm_deactivate(command); |
120 |
|
|
|
121 |
|
|
/* Return the completion status. */ |
122 |
|
73 |
return(status); |
123 |
|
|
|
124 |
|
227 |
case UX_SLAVE_CLASS_COMMAND_REQUEST: |
125 |
|
|
|
126 |
|
|
/* The request command is used when the host sends a command on the control endpoint. */ |
127 |
|
227 |
status = _ux_device_class_cdc_acm_control_request(command); |
128 |
|
|
|
129 |
|
|
/* Return the completion status. */ |
130 |
|
227 |
return(status); |
131 |
|
|
|
132 |
|
1 |
default: |
133 |
|
|
|
134 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
135 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0) |
136 |
|
|
|
137 |
|
|
/* Return an error. */ |
138 |
|
1 |
return(UX_FUNCTION_NOT_SUPPORTED); |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|