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 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_hcd_sim_host_port_status_get                    PORTABLE C      */
37 /*                                                           6.1.6        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*     This function will return the status for each port attached to the */
45 /*     root HUB.                                                          */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    hcd_sim_host                          Pointer to host controller    */
50 /*    port_index                            Port index                    */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Host Simulator Port Status                                          */
55 /*                                                                        */
56 /*    Where port status has the following format:                         */
57 /*                                                                        */
58 /*               bit 0         device connection status                   */
59 /*                             if 0 : no device connected                 */
60 /*                             if 1 : device connected to the port        */
61 /*               bit 1         port enable status                         */
62 /*                             if 0 : port disabled                       */
63 /*                             if 1 : port enabled                        */
64 /*               bit 2         port suspend status                        */
65 /*                             if 0 : port is not suspended               */
66 /*                             if 1 : port is suspended                   */
67 /*               bit 3         port overcurrent status                    */
68 /*                             if 0 : port has no overcurrent condition   */
69 /*                             if 1 : port has overcurrent condition      */
70 /*               bit 4         port reset status                          */
71 /*                             if 0 : port is not in reset                */
72 /*                             if 1 : port is in reset                    */
73 /*               bit 5         port power status                          */
74 /*                             if 0 : port power is off                   */
75 /*                             if 1 : port power is on                    */
76 /*               bit 6-7       device attached speed                      */
77 /*                             if 00 : low speed device attached          */
78 /*                             if 01 : full speed device attached         */
79 /*                             if 10 : high speed device attached         */
80 /*                                                                        */
81 /*  CALLS                                                                 */
82 /*                                                                        */
83 /*    None                                                                */
84 /*                                                                        */
85 /*  CALLED BY                                                             */
86 /*                                                                        */
87 /*    Host Simulator Controller Driver                                    */
88 /*                                                                        */
89 /*  RELEASE HISTORY                                                       */
90 /*                                                                        */
91 /*    DATE              NAME                      DESCRIPTION             */
92 /*                                                                        */
93 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
94 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
95 /*                                            resulting in version 6.1    */
96 /*  04-02-2021     Chaoqiong Xiao           Modified comment(s),          */
97 /*                                            used changeable status,     */
98 /*                                            resulting in version 6.1.6  */
99 /*                                                                        */
100 /**************************************************************************/
_ux_hcd_sim_host_port_status_get(UX_HCD_SIM_HOST * hcd_sim_host,ULONG port_index)101 ULONG  _ux_hcd_sim_host_port_status_get(UX_HCD_SIM_HOST *hcd_sim_host, ULONG port_index)
102 {
103 
104 ULONG       port_status;
105 
106 
107     /* Check to see if this port is valid on this controller.  */
108     if (hcd_sim_host -> ux_hcd_sim_host_nb_root_hubs < port_index)
109     {
110 
111         /* Error trap. */
112         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_PORT_INDEX_UNKNOWN);
113 
114         /* If trace is enabled, insert this event into the trace buffer.  */
115         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_PORT_INDEX_UNKNOWN, port_index, 0, 0, UX_TRACE_ERRORS, 0, 0)
116 
117         return(UX_PORT_INDEX_UNKNOWN);
118     }
119 
120     /* Returns current port status.  */
121     port_status = hcd_sim_host -> ux_hcd_sim_host_port_status[port_index];
122 
123     /* Return port status.  */
124     return(port_status);
125 }
126 
127