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 /** HUB Class */
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_class_hub.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_hub_port_reset PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function will reset a downstream port of the HUB. When the */
46 /* port is reset, the hardware logic of the HUB also enables it. */
47 /* */
48 /* INPUT */
49 /* */
50 /* hub Pointer to HUB class */
51 /* port Port number */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_host_class_hub_port_change_reset_process Reset HUB */
60 /* _ux_host_class_hub_feature Set HUB class feature */
61 /* _ux_host_class_hub_status_get Get HUB status */
62 /* _ux_utility_delay_ms Thread sleep */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* HUB Class */
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 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
_ux_host_class_hub_port_reset(UX_HOST_CLASS_HUB * hub,UINT port)77 UINT _ux_host_class_hub_port_reset(UX_HOST_CLASS_HUB *hub, UINT port)
78 {
79
80 UINT status;
81 UINT port_enable_retry;
82 USHORT port_status;
83 USHORT port_change;
84
85
86 /* Send the PORT_RESET command. */
87 status = _ux_host_class_hub_feature(hub, port, UX_SET_FEATURE, UX_HOST_CLASS_HUB_PORT_RESET);
88
89 /* Check the function result and update HUB status if there was a problem. */
90 if (status != UX_SUCCESS)
91 return(status);
92
93 /* We allow retrying of this as we may not get the port enable status bit
94 set on the first try. */
95 port_enable_retry = UX_HOST_CLASS_HUB_ENABLE_RETRY_COUNT;
96 while (port_enable_retry--)
97 {
98
99 /* Now get the status until we have a port enabled. */
100 status = _ux_host_class_hub_status_get(hub, port, &port_status, &port_change);
101 if (status != UX_SUCCESS)
102 return(status);
103
104 /* On return of the GET_STATUS, the port_change field has been updated.
105 Check for each of the bits it may contain. */
106 if (port_change & UX_HOST_CLASS_HUB_PORT_CHANGE_RESET)
107 {
108
109 /* The port has been successfully reset. */
110
111 /* Clear the RESET change bit. */
112 _ux_host_class_hub_port_change_reset_process(hub, port, port_status);
113
114 /* Return success. */
115 return(UX_SUCCESS);
116 }
117
118 /* We should wait a bit before retrying this operation. */
119 _ux_utility_delay_ms(UX_HOST_CLASS_HUB_ENABLE_RETRY_DELAY);
120 }
121
122 /* We get here when the port never reported RESET completion. */
123
124 /* Invoke error callback. */
125 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HUB, UX_PORT_RESET_FAILED);
126
127 /* Return error. */
128 return(UX_PORT_RESET_FAILED);
129 }
130
131