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 |
|
|
/** Host Stack */ |
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_stack.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _ux_host_stack_endpoint_instance_create PORTABLE C */ |
37 |
|
|
/* 6.1.10 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function will create an endpoint instance. The HCD layer is */ |
45 |
|
|
/* invoked to create each endpoint and the bandwidth claimed by each */ |
46 |
|
|
/* endpoint is allocated. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* endpoint Endpoint to delete */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* Completion Status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_host_stack_bandwidth_check Check bandwidth */ |
59 |
|
|
/* _ux_host_stack_bandwidth_claim Claim bandwidth */ |
60 |
|
|
/* _ux_utility_semaphore_create Semaphore create */ |
61 |
|
|
/* (ux_hcd_entry_function) HCD entry function */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* USBX Components */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
2127 |
UINT _ux_host_stack_endpoint_instance_create(UX_ENDPOINT *endpoint) |
69 |
|
|
{ |
70 |
|
|
|
71 |
|
|
UX_HCD *hcd; |
72 |
|
|
UINT status; |
73 |
|
|
UCHAR endpoint_type; |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
/* Obtain the HCD for this endpoint. */ |
77 |
|
2127 |
hcd = UX_DEVICE_HCD_GET(endpoint -> ux_endpoint_device); |
78 |
|
|
|
79 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
80 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_ENDPOINT_INSTANCE_CREATE, endpoint -> ux_endpoint_device, endpoint, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
/* If the endpoint needs guaranteed bandwidth, check if we have enough */ |
84 |
|
2127 |
endpoint_type = (endpoint -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE; |
85 |
✓✓ |
2127 |
switch (endpoint_type) |
86 |
|
|
{ |
87 |
|
|
|
88 |
|
930 |
case UX_CONTROL_ENDPOINT: |
89 |
|
|
case UX_BULK_ENDPOINT: |
90 |
|
|
|
91 |
|
930 |
break; |
92 |
|
|
|
93 |
|
1197 |
default: |
94 |
|
|
|
95 |
|
|
/* Check the bandwidth for this endpoint */ |
96 |
✓✓ |
1197 |
if (_ux_host_stack_bandwidth_check(hcd, endpoint) != UX_SUCCESS) |
97 |
|
|
{ |
98 |
|
|
|
99 |
|
|
/* Error trap. */ |
100 |
|
10 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_NO_BANDWIDTH_AVAILABLE); |
101 |
|
|
|
102 |
|
10 |
return(UX_NO_BANDWIDTH_AVAILABLE); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
|
106 |
|
1187 |
break; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
/* Create this endpoint. */ |
110 |
|
2117 |
status = hcd -> ux_hcd_entry_function(hcd, UX_HCD_CREATE_ENDPOINT, (VOID *) endpoint); |
111 |
|
|
|
112 |
|
|
/* Check status. */ |
113 |
✓✓ |
2117 |
if (status != UX_SUCCESS) |
114 |
|
|
{ |
115 |
|
|
|
116 |
|
|
/* Return completion status. */ |
117 |
|
8 |
return(status); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/* Claim bandwidth if needed. */ |
121 |
✓✓✓✓
|
2109 |
if ((endpoint_type == UX_INTERRUPT_ENDPOINT) || (endpoint_type == UX_ISOCHRONOUS_ENDPOINT)) |
122 |
|
|
{ |
123 |
|
|
|
124 |
|
|
/* Claim its bandwidth */ |
125 |
|
1186 |
_ux_host_stack_bandwidth_claim(hcd, endpoint); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
/* Create a semaphore for this endpoint to be attached to its transfer request. */ |
129 |
|
2109 |
status = _ux_host_semaphore_create(&endpoint -> ux_endpoint_transfer_request.ux_transfer_request_semaphore, |
130 |
|
|
"ux_transfer_request_semaphore", 0); |
131 |
|
|
|
132 |
|
|
/* Check status. */ |
133 |
✓✓ |
2109 |
if (status == UX_SUCCESS) |
134 |
|
|
{ |
135 |
|
|
|
136 |
|
|
/* If trace is enabled, register this object. */ |
137 |
|
|
UX_TRACE_OBJECT_REGISTER(UX_TRACE_HOST_OBJECT_TYPE_ENDPOINT, endpoint, 0, 0, 0) |
138 |
|
|
|
139 |
|
|
/* By default transfer request contained is for endpoint itself. */ |
140 |
|
2105 |
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_endpoint = endpoint; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
/* Return completion status. */ |
144 |
|
2109 |
return(status); |
145 |
|
|
} |
146 |
|
|
|