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 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _ux_device_class_cdc_ecm_write PORTABLE C */ |
37 |
|
|
/* 6.1.11 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function writes a packet into a queue for later thread */ |
45 |
|
|
/* processing. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* cdc_ecm Address of cdc_ecm class */ |
50 |
|
|
/* instance */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* None */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_device_stack_transfer_request Transfer request */ |
59 |
|
|
/* _ux_device_mutex_off Release mutex */ |
60 |
|
|
/* _ux_device_event_flags_set Set event flags */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLED BY */ |
63 |
|
|
/* */ |
64 |
|
|
/* ThreadX */ |
65 |
|
|
/* */ |
66 |
|
|
/**************************************************************************/ |
67 |
|
1092 |
UINT _ux_device_class_cdc_ecm_write(VOID *cdc_ecm_class, NX_PACKET *packet) |
68 |
|
|
{ |
69 |
|
|
#if defined(UX_DEVICE_STANDALONE) |
70 |
|
|
UX_PARAMETER_NOT_USED(cdc_ecm_class); |
71 |
|
|
UX_PARAMETER_NOT_USED(packet); |
72 |
|
|
return(UX_FUNCTION_NOT_SUPPORTED); |
73 |
|
|
#else |
74 |
|
|
|
75 |
|
|
UINT status; |
76 |
|
|
UX_SLAVE_CLASS_CDC_ECM *cdc_ecm; |
77 |
|
|
|
78 |
|
|
/* Proper class casting. */ |
79 |
|
1092 |
cdc_ecm = (UX_SLAVE_CLASS_CDC_ECM *) cdc_ecm_class; |
80 |
|
|
|
81 |
|
|
/* Protect this thread. */ |
82 |
|
1092 |
_ux_device_mutex_on(&cdc_ecm -> ux_slave_class_cdc_ecm_mutex); |
83 |
|
|
|
84 |
|
|
/* We only want to send the packet if the link is up. */ |
85 |
✓✓ |
1092 |
if (cdc_ecm->ux_slave_class_cdc_ecm_link_state == UX_DEVICE_CLASS_CDC_ECM_LINK_STATE_UP) |
86 |
|
|
{ |
87 |
|
|
|
88 |
|
|
/* Check the queue. See if there is something that is being sent. */ |
89 |
✓✓ |
1079 |
if (cdc_ecm -> ux_slave_class_cdc_ecm_xmit_queue == UX_NULL) |
90 |
|
|
|
91 |
|
|
/* Memorize this packet at the beginning of the queue. */ |
92 |
|
140 |
cdc_ecm -> ux_slave_class_cdc_ecm_xmit_queue = packet; |
93 |
|
|
|
94 |
|
|
else |
95 |
|
|
|
96 |
|
|
/* Add the packet to the end of the queue. */ |
97 |
|
939 |
cdc_ecm -> ux_slave_class_cdc_ecm_xmit_queue_tail -> nx_packet_queue_next = packet; |
98 |
|
|
|
99 |
|
|
/* Set the tail. */ |
100 |
|
1079 |
cdc_ecm -> ux_slave_class_cdc_ecm_xmit_queue_tail = packet; |
101 |
|
|
|
102 |
|
|
/* The packet to be sent is the last in the chain. */ |
103 |
|
1079 |
packet -> nx_packet_queue_next = NX_NULL; |
104 |
|
|
|
105 |
|
|
/* Free Mutex resource. */ |
106 |
|
1079 |
_ux_device_mutex_off(&cdc_ecm -> ux_slave_class_cdc_ecm_mutex); |
107 |
|
|
|
108 |
|
|
/* Set an event to wake up the bulkin thread. */ |
109 |
|
1079 |
_ux_device_event_flags_set(&cdc_ecm -> ux_slave_class_cdc_ecm_event_flags_group, UX_DEVICE_CLASS_CDC_ECM_NEW_BULKIN_EVENT, UX_OR); |
110 |
|
|
|
111 |
|
|
/* Packet successfully added. Return success. */ |
112 |
|
1079 |
status = UX_SUCCESS; |
113 |
|
|
} |
114 |
|
|
else |
115 |
|
|
{ |
116 |
|
|
|
117 |
|
|
/* Free Mutex resource. */ |
118 |
|
13 |
_ux_device_mutex_off(&cdc_ecm -> ux_slave_class_cdc_ecm_mutex); |
119 |
|
|
|
120 |
|
|
/* Report error to application. */ |
121 |
|
13 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CLASS_CDC_ECM_LINK_STATE_DOWN_ERROR); |
122 |
|
|
|
123 |
|
|
/* Return error. */ |
124 |
|
13 |
status = UX_ERROR; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
/* We are done here. */ |
128 |
|
1092 |
return(status); |
129 |
|
|
#endif |
130 |
|
|
} |