GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hub_port_reset.c Lines: 15 15 100.0 %
Date: 2026-03-06 18:57:10 Branches: 8 8 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
69
26
UINT  _ux_host_class_hub_port_reset(UX_HOST_CLASS_HUB *hub, UINT port)
70
{
71
72
UINT        status;
73
UINT        port_enable_retry;
74
USHORT      port_status;
75
USHORT      port_change;
76
77
78
    /* Send the PORT_RESET command.  */
79
26
    status =  _ux_host_class_hub_feature(hub, port, UX_SET_FEATURE, UX_HOST_CLASS_HUB_PORT_RESET);
80
81
    /* Check the function result and update HUB status if there was a problem.  */
82
26
    if (status != UX_SUCCESS)
83
1
        return(status);
84
85
    /* We allow retrying of this as we may not get the port enable status bit
86
       set on the first try.  */
87
25
    port_enable_retry =  UX_HOST_CLASS_HUB_ENABLE_RETRY_COUNT;
88
28
    while (port_enable_retry--)
89
    {
90
91
        /* Now get the status until we have a port enabled.  */
92
27
        status =  _ux_host_class_hub_status_get(hub, port, &port_status, &port_change);
93
27
        if (status != UX_SUCCESS)
94
1
            return(status);
95
96
        /* On return of the GET_STATUS, the port_change field has been updated.
97
           Check for each of the bits it may contain. */
98
26
        if (port_change & UX_HOST_CLASS_HUB_PORT_CHANGE_RESET)
99
        {
100
101
            /* The port has been successfully reset.  */
102
103
            /* Clear the RESET change bit.  */
104
23
            _ux_host_class_hub_port_change_reset_process(hub, port, port_status);
105
106
            /* Return success.  */
107
23
            return(UX_SUCCESS);
108
        }
109
110
        /* We should wait a bit before retrying this operation.  */
111
3
        _ux_utility_delay_ms(UX_HOST_CLASS_HUB_ENABLE_RETRY_DELAY);
112
    }
113
114
    /* We get here when the port never reported RESET completion.  */
115
116
    /* Invoke error callback.  */
117
1
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HUB, UX_PORT_RESET_FAILED);
118
119
    /* Return error.  */
120
1
    return(UX_PORT_RESET_FAILED);
121
}
122