1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Host Stack */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /* Include necessary system files. */
24
25 #define UX_SOURCE_CODE
26
27 #include "ux_api.h"
28 #include "ux_host_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_host_stack_enum_thread_entry PORTABLE C */
36 /* 6.1.10 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This file contains the enum thread for USBX. It is in charge of */
44 /* the topology changes either from device insertion\extraction on */
45 /* the root hub or on a regular hub. */
46 /* */
47 /* This thread ensures we never have more that 2 instances trying to */
48 /* perform a change to the topology (mostly enumeration) for fear that */
49 /* more than one device could answer to address 0. */
50 /* */
51 /* This function is the entry point of the topology thread. It waits */
52 /* until one of the HCDs or a hub sets the semaphore to indicate */
53 /* there has been a change in the USB topology which could be either */
54 /* a insertion or extraction or eventually a hub downstream port */
55 /* signal. */
56 /* */
57 /* This is for RTOS mode. */
58 /* */
59 /* INPUT */
60 /* */
61 /* input Not used input */
62 /* */
63 /* OUTPUT */
64 /* */
65 /* None */
66 /* */
67 /* CALLS */
68 /* */
69 /* _ux_host_stack_rh_change_process Root hub processing */
70 /* _ux_utility_semaphore_get Get signal semaphore */
71 /* (ux_system_host_enum_hub_function) HUB enum processing function */
72 /* */
73 /* CALLED BY */
74 /* */
75 /* ThreadX */
76 /* */
77 /* RELEASE HISTORY */
78 /* */
79 /* DATE NAME DESCRIPTION */
80 /* */
81 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
82 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
83 /* optimized based on compile */
84 /* definitions, */
85 /* resulting in version 6.1 */
86 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
87 /* refined macros names, */
88 /* resulting in version 6.1.10 */
89 /* */
90 /**************************************************************************/
_ux_host_stack_enum_thread_entry(ULONG input)91 VOID _ux_host_stack_enum_thread_entry(ULONG input)
92 {
93
94 UX_PARAMETER_NOT_USED(input);
95
96 /* Loop forever waiting for changes signaled through the semaphore. */
97 while (1)
98 {
99
100 /* Wait for the semaphore to be put by the root hub or a regular hub. */
101 _ux_host_semaphore_get_norc(&_ux_system_host -> ux_system_host_enum_semaphore, UX_WAIT_FOREVER);
102
103 #if UX_MAX_DEVICES > 1
104 /* We try the hub first. For this we look into the USBX project
105 structure to see if there is at least one hub. */
106 if (_ux_system_host -> ux_system_host_enum_hub_function != UX_NULL)
107 {
108
109 /* Yes, there is a HUB function, call it! */
110 _ux_system_host -> ux_system_host_enum_hub_function();
111 }
112 #endif
113
114 /* The signal may be also coming from the root hub, call the root hub handler. */
115 _ux_host_stack_rh_change_process();
116 }
117 }
118
119