1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
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_hcd_thread_entry PORTABLE C */
37 /* 6.1.10 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function is the entry point of the host controller thread. */
45 /* The HCD thread is initialized at the system level and the thread */
46 /* entry routine is invoked right away. This thread suspends until */
47 /* one of the HCD resumes it due to HCD activities. */
48 /* */
49 /* It's for RTOS mode. */
50 /* */
51 /* INPUT */
52 /* */
53 /* input Not used input */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* None */
58 /* */
59 /* CALLS */
60 /* */
61 /* _ux_utility_semaphore_get Get signal semaphore */
62 /* (ux_hcd_entry_function) HCD's entry function */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* ThreadX */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
74 /* optimized based on compile */
75 /* definitions, */
76 /* resulting in version 6.1 */
77 /* 11-09-2020 Chaoqiong Xiao Modified comment(s), */
78 /* fixed registered HCD scan, */
79 /* resulting in version 6.1.2 */
80 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
81 /* refined macros names, */
82 /* resulting in version 6.1.10 */
83 /* */
84 /**************************************************************************/
_ux_host_stack_hcd_thread_entry(ULONG input)85 VOID _ux_host_stack_hcd_thread_entry(ULONG input)
86 {
87
88 UINT hcd_index;
89 UX_HCD *hcd;
90 UX_INTERRUPT_SAVE_AREA
91
92 UX_PARAMETER_NOT_USED(input);
93
94 /* Loop forever on the semaphore. The semaphore is used to signal that
95 there is work for one or more HCDs. */
96 while (1)
97 {
98
99 /* Get the semaphore that signals something is available for this
100 thread to process. */
101 _ux_host_semaphore_get_norc(&_ux_system_host -> ux_system_host_hcd_semaphore, UX_WAIT_FOREVER);
102
103 #if UX_MAX_HCD > 1
104 /* This thread was awaken by one or more HCD controllers. Check each of the HCDs
105 to see who posted work to do. */
106 for(hcd_index = 0; hcd_index < _ux_system_host -> ux_system_host_max_hcd; hcd_index++)
107 {
108 #else
109 hcd_index = 0;
110 #endif
111
112 /* Pickup HCD pointer. */
113 hcd = &_ux_system_host -> ux_system_host_hcd_array[hcd_index];
114
115 /* Is there work to do for this HCD? */
116 if((hcd -> ux_hcd_status == UX_HCD_STATUS_OPERATIONAL) && (hcd -> ux_hcd_thread_signal !=0))
117 {
118
119 /* Yes, call the HCD function to process the work. */
120 hcd -> ux_hcd_entry_function(hcd, UX_HCD_PROCESS_DONE_QUEUE, UX_NULL);
121 UX_DISABLE
122 hcd -> ux_hcd_thread_signal--;
123 UX_RESTORE
124 }
125
126 #if UX_MAX_HCD > 1
127 }
128 #endif
129 }
130 }
131
132