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_enum_thread_entry PORTABLE C */ |
37 |
|
|
/* 6.1.10 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This file contains the enum thread for USBX. It is in charge of */ |
45 |
|
|
/* the topology changes either from device insertion\extraction on */ |
46 |
|
|
/* the root hub or on a regular hub. */ |
47 |
|
|
/* */ |
48 |
|
|
/* This thread ensures we never have more that 2 instances trying to */ |
49 |
|
|
/* perform a change to the topology (mostly enumeration) for fear that */ |
50 |
|
|
/* more than one device could answer to address 0. */ |
51 |
|
|
/* */ |
52 |
|
|
/* This function is the entry point of the topology thread. It waits */ |
53 |
|
|
/* until one of the HCDs or a hub sets the semaphore to indicate */ |
54 |
|
|
/* there has been a change in the USB topology which could be either */ |
55 |
|
|
/* a insertion or extraction or eventually a hub downstream port */ |
56 |
|
|
/* signal. */ |
57 |
|
|
/* */ |
58 |
|
|
/* This is for RTOS mode. */ |
59 |
|
|
/* */ |
60 |
|
|
/* INPUT */ |
61 |
|
|
/* */ |
62 |
|
|
/* input Not used input */ |
63 |
|
|
/* */ |
64 |
|
|
/* OUTPUT */ |
65 |
|
|
/* */ |
66 |
|
|
/* None */ |
67 |
|
|
/* */ |
68 |
|
|
/* CALLS */ |
69 |
|
|
/* */ |
70 |
|
|
/* _ux_host_stack_rh_change_process Root hub processing */ |
71 |
|
|
/* _ux_utility_semaphore_get Get signal semaphore */ |
72 |
|
|
/* (ux_system_host_enum_hub_function) HUB enum processing function */ |
73 |
|
|
/* */ |
74 |
|
|
/* CALLED BY */ |
75 |
|
|
/* */ |
76 |
|
|
/* ThreadX */ |
77 |
|
|
/* */ |
78 |
|
|
/**************************************************************************/ |
79 |
|
362 |
VOID _ux_host_stack_enum_thread_entry(ULONG input) |
80 |
|
|
{ |
81 |
|
|
|
82 |
|
|
UX_PARAMETER_NOT_USED(input); |
83 |
|
|
|
84 |
|
|
/* Loop forever waiting for changes signaled through the semaphore. */ |
85 |
|
|
while (1) |
86 |
|
|
{ |
87 |
|
|
|
88 |
|
|
/* Wait for the semaphore to be put by the root hub or a regular hub. */ |
89 |
|
1892 |
_ux_host_semaphore_get_norc(&_ux_system_host -> ux_system_host_enum_semaphore, UX_WAIT_FOREVER); |
90 |
|
|
|
91 |
|
|
#if UX_MAX_DEVICES > 1 |
92 |
|
|
/* We try the hub first. For this we look into the USBX project |
93 |
|
|
structure to see if there is at least one hub. */ |
94 |
✓✓ |
1542 |
if (_ux_system_host -> ux_system_host_enum_hub_function != UX_NULL) |
95 |
|
|
{ |
96 |
|
|
|
97 |
|
|
/* Yes, there is a HUB function, call it! */ |
98 |
|
148 |
_ux_system_host -> ux_system_host_enum_hub_function(); |
99 |
|
|
} |
100 |
|
|
#endif |
101 |
|
|
|
102 |
|
|
/* The signal may be also coming from the root hub, call the root hub handler. */ |
103 |
|
1542 |
_ux_host_stack_rh_change_process(); |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
|