1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Host Stack */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_stack_rh_change_process PORTABLE C */
/* 6.1.2 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function checks for changes in topology in each of the */
/* installed HCDs. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* _ux_host_stack_rh_device_insertion Process device insertion */
/* _ux_host_stack_rh_device_extraction Process device extraction */
/* (ux_hcd_entry_function) HCD entry function */
/* */
/* CALLED BY */
/* */
/* USBX Components */
/* */
/**************************************************************************/
VOID _ux_host_stack_rh_change_process(VOID)
{
UX_HCD *hcd;
UINT hcd_index;
ULONG port_status;
UINT port_index;
UX_INTERRUPT_SAVE_AREA
/* This thread was maybe awaken by one or more HCD controllers. Check each
of the HCD to see where there has been a change of topology. */
for(hcd_index = 0; hcd_index < UX_SYSTEM_HOST_MAX_HCD_GET(); hcd_index++)
{
/* Pickup HCD pointer. */
hcd = &_ux_system_host -> ux_system_host_hcd_array[hcd_index];
/* Is this HCD operational? */
if (hcd -> ux_hcd_status == UX_HCD_STATUS_OPERATIONAL)
{
/* On each port of the root hub of the controller, get the port status */
for (port_index = 0; port_index < hcd -> ux_hcd_nb_root_hubs; port_index++)
{
/* Was there any activity on this port ? */
if (hcd -> ux_hcd_root_hub_signal[port_index] != 0)
{
/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_RH_CHANGE_PROCESS, port_index, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
/* Reset that port activity signal. */
UX_DISABLE
hcd -> ux_hcd_root_hub_signal[port_index]--;
UX_RESTORE
/* Call HCD for port status. */
port_status = hcd -> ux_hcd_entry_function(hcd, UX_HCD_GET_PORT_STATUS, (VOID *)((ALIGN_TYPE)port_index));
/* Check return status. */
if (port_status != UX_PORT_INDEX_UNKNOWN)
{
/* The port_status value is valid and will tell us if there is
a device attached\detached on the downstream port. */
if (port_status & UX_PS_CCS)
{
/* There is a device attached to this port. Check if we know
about it. If not, this is a device insertion signal. */
if ((hcd -> ux_hcd_rh_device_connection & (ULONG)(1 << port_index)) == 0)
{
/* We have a simple device insertion, we have not lost any signals.
the root hub and the stack enumeration module are in synch. */
_ux_host_stack_rh_device_insertion(hcd,port_index);
}
else
{
/* We can get here when there has been multiple events on the hardware root hub
but we may have missed them of they were too close or the stack got too busy.
We check the number of events in the root hub signal. If it is not zero
we are out of synch, meaning we got a disconnection followed very quickly
by a insertion. */
if (hcd -> ux_hcd_root_hub_signal[port_index] != 0)
{
/* We need to get back in synch now. */
UX_DISABLE
hcd -> ux_hcd_root_hub_signal[port_index] = 0;
UX_RESTORE
/* First extract the device. */
_ux_host_stack_rh_device_extraction(hcd,port_index);
/* Now, insert it again. */
_ux_host_stack_rh_device_insertion(hcd,port_index);
}
}
}
else
{
/* There is no device attached to this port. Check if we know
about it. If not, this is a device removal signal. */
if ((hcd -> ux_hcd_rh_device_connection & (ULONG)(1 << port_index)) !=0)
{
_ux_host_stack_rh_device_extraction(hcd,port_index);
}
}
}
}
}
}
}
}
|