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_ECM 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_ecm.h" |
29 |
|
|
#include "ux_device_stack.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
#if !defined(UX_DEVICE_STANDALONE) |
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_device_class_cdc_ecm_interrupt_thread PORTABLE C */ |
38 |
|
|
/* 6.1.11 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is the thread of the cdc_ecm interrupt endpoint */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* cdc_ecm_class Address of cdc_ecm class */ |
50 |
|
|
/* container */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* None */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_device_stack_transfer_request Request transfer */ |
59 |
|
|
/* _ux_utility_event_flags_get Get event flags */ |
60 |
|
|
/* _ux_utility_short_put Put 16-bit value to buffer */ |
61 |
|
|
/* _ux_device_thread_suspend Suspend thread */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* ThreadX */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
50 |
VOID _ux_device_class_cdc_ecm_interrupt_thread(ULONG cdc_ecm_class) |
69 |
|
|
{ |
70 |
|
|
|
71 |
|
|
UX_SLAVE_CLASS *class_ptr; |
72 |
|
|
UX_SLAVE_CLASS_CDC_ECM *cdc_ecm; |
73 |
|
|
UX_SLAVE_DEVICE *device; |
74 |
|
|
UX_SLAVE_TRANSFER *transfer_request; |
75 |
|
|
UINT status; |
76 |
|
|
ULONG actual_flags; |
77 |
|
|
UCHAR *notification_buffer; |
78 |
|
|
|
79 |
|
|
/* Cast properly the cdc_ecm instance. */ |
80 |
|
50 |
UX_THREAD_EXTENSION_PTR_GET(class_ptr, UX_SLAVE_CLASS, cdc_ecm_class) |
81 |
|
|
|
82 |
|
|
/* Get the cdc_ecm instance from this class container. */ |
83 |
|
50 |
cdc_ecm = (UX_SLAVE_CLASS_CDC_ECM *) class_ptr -> ux_slave_class_instance; |
84 |
|
|
|
85 |
|
|
/* Get the pointer to the device. */ |
86 |
|
50 |
device = &_ux_system_slave -> ux_system_slave_device; |
87 |
|
|
|
88 |
|
|
/* This thread runs forever but can be suspended or resumed. */ |
89 |
|
|
while(1) |
90 |
|
|
{ |
91 |
|
|
|
92 |
|
|
/* All CDC_ECM events are on the interrupt endpoint IN, from the host. */ |
93 |
|
82 |
transfer_request = &cdc_ecm -> ux_slave_class_cdc_ecm_interrupt_endpoint -> ux_slave_endpoint_transfer_request; |
94 |
|
|
|
95 |
|
|
/* As long as the device is in the CONFIGURED state. */ |
96 |
✓✓ |
192 |
while (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED) |
97 |
|
|
{ |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
/* Wait until we have a event sent by the application. We do not treat yet the case where a timeout based |
101 |
|
|
on the interrupt pipe frequency or a change in the idle state forces us to send an empty report. */ |
102 |
|
145 |
_ux_utility_event_flags_get(&cdc_ecm -> ux_slave_class_cdc_ecm_event_flags_group, |
103 |
|
|
UX_DEVICE_CLASS_CDC_ECM_NETWORK_NOTIFICATION_EVENT, |
104 |
|
|
UX_OR_CLEAR, &actual_flags, UX_WAIT_FOREVER); |
105 |
|
|
|
106 |
|
|
/* Build the Network Notification response. */ |
107 |
|
110 |
notification_buffer = transfer_request -> ux_slave_transfer_request_data_pointer; |
108 |
|
|
|
109 |
|
|
/* Set the request type. */ |
110 |
|
110 |
*(notification_buffer + UX_SETUP_REQUEST_TYPE) = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; |
111 |
|
|
|
112 |
|
|
/* Set the request itself. */ |
113 |
|
110 |
*(notification_buffer + UX_SETUP_REQUEST) = 0; |
114 |
|
|
|
115 |
|
|
/* Set the value. It is the network link. */ |
116 |
|
110 |
_ux_utility_short_put(notification_buffer + UX_SETUP_VALUE, (USHORT)(cdc_ecm -> ux_slave_class_cdc_ecm_link_state)); |
117 |
|
|
|
118 |
|
|
/* Set the Index. It is interface. The interface used is the DATA interface. Here we simply take the interface number of the CONTROL and add 1 to it |
119 |
|
|
as it is assumed the classes are contiguous in number. */ |
120 |
|
110 |
_ux_utility_short_put(notification_buffer + UX_SETUP_INDEX, (USHORT)(cdc_ecm -> ux_slave_class_cdc_ecm_interface -> ux_slave_interface_descriptor.bInterfaceNumber + 1)); |
121 |
|
|
|
122 |
|
|
/* And the length is zero. */ |
123 |
|
110 |
*(notification_buffer + UX_SETUP_LENGTH) = 0; |
124 |
|
|
|
125 |
|
|
/* Send the request to the device controller. */ |
126 |
|
110 |
status = _ux_device_stack_transfer_request(transfer_request, UX_DEVICE_CLASS_CDC_ECM_INTERRUPT_RESPONSE_LENGTH, |
127 |
|
|
UX_DEVICE_CLASS_CDC_ECM_INTERRUPT_RESPONSE_LENGTH); |
128 |
|
|
|
129 |
|
|
/* Check error code. */ |
130 |
✓✓ |
110 |
if (status != UX_SUCCESS) |
131 |
|
|
{ |
132 |
|
|
|
133 |
|
|
/* Since bus resets are expected, we do not treat it as an error. */ |
134 |
✓✓ |
49 |
if (status != UX_TRANSFER_BUS_RESET) |
135 |
|
|
{ |
136 |
|
|
|
137 |
|
|
/* Error trap. */ |
138 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, status); |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
/* We need to suspend ourselves. We will be resumed by the device enumeration module. */ |
144 |
|
47 |
_ux_device_thread_suspend(&cdc_ecm -> ux_slave_class_cdc_ecm_interrupt_thread); |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
#endif |