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 Simulator Controller Driver */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define UX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "ux_api.h"
29 #include "ux_hcd_sim_host.h"
30 #include "ux_dcd_sim_slave.h"
31 #include "ux_device_stack.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _ux_hcd_sim_host_port_reset PORTABLE C */
39 /* 6.1.10 */
40 /* AUTHOR */
41 /* */
42 /* Chaoqiong Xiao, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* Implements the PORT_RESET request. */
47 /* */
48 /* INPUT */
49 /* */
50 /* hcd_sim_host Pointer to host controller */
51 /* port_index Port index to reset */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_device_stack_disconnect Simulate device disconnection */
60 /* _ux_dcd_sim_slave_initialize_complete Complete device initialization*/
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Host Simulator Controller Driver */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
71 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* 08-02-2021 Wen Wang Modified comment(s), */
74 /* fixed spelling error, */
75 /* resulting in version 6.1.8 */
76 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
77 /* added standalone support, */
78 /* resulting in version 6.1.10 */
79 /* */
80 /**************************************************************************/
_ux_hcd_sim_host_port_reset(UX_HCD_SIM_HOST * hcd_sim_host,ULONG port_index)81 UINT _ux_hcd_sim_host_port_reset(UX_HCD_SIM_HOST *hcd_sim_host, ULONG port_index)
82 {
83
84 UX_SLAVE_DEVICE *device;
85
86 #if defined(UX_HOST_STANDALONE)
87 /* No port reset wait simulated, return _STATE_NEXT later to move state. */
88 #endif
89
90 UX_PARAMETER_NOT_USED(hcd_sim_host);
91 UX_PARAMETER_NOT_USED(port_index);
92
93 /* Get a pointer to the device. */
94 device = &_ux_system_slave -> ux_system_slave_device;
95
96 /* Is this a connection? */
97 if (device -> ux_slave_device_state == UX_DEVICE_RESET)
98
99 /* Complete the device initialization. Note that every time the device
100 is disconnected, this must be called again for connection. */
101 _ux_dcd_sim_slave_initialize_complete();
102
103 else
104 {
105
106 /* Host sent a PORT_RESET when the device is Attached, Addressed, or
107 Configured. Per the USB spec, we should go back to the default state.
108 We do this by 1) simulating disconnect to get rid of class and device
109 resources and 2) recreating necessary entities for control transfers. */
110 _ux_device_stack_disconnect();
111 _ux_dcd_sim_slave_initialize_complete();
112 }
113
114 /* In either case, mark the device as default/attached now. */
115 device -> ux_slave_device_state = UX_DEVICE_ATTACHED;
116
117 /* This function should never fail. */
118 #if defined(UX_HOST_STANDALONE)
119 return(UX_STATE_NEXT);
120 #else
121 return(UX_SUCCESS);
122 #endif
123 }
124
125