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: 2024-12-12 17:16:36 Branches: 8 8 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   HUB Class                                                           */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
23
/* Include necessary system files.  */
24
25
#define UX_SOURCE_CODE
26
27
#include "ux_api.h"
28
#include "ux_host_class_hub.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_class_hub_port_reset                       PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function will reset a downstream port of the HUB. When the     */
45
/*    port is reset, the hardware logic of the HUB also enables it.       */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    hub                                   Pointer to HUB class          */
50
/*    port                                  Port number                   */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_class_hub_port_change_reset_process Reset HUB              */
59
/*    _ux_host_class_hub_feature            Set HUB class feature         */
60
/*    _ux_host_class_hub_status_get         Get HUB status                */
61
/*    _ux_utility_delay_ms                  Thread sleep                  */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    HUB Class                                                           */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73
/*                                            resulting in version 6.1    */
74
/*                                                                        */
75
/**************************************************************************/
76
26
UINT  _ux_host_class_hub_port_reset(UX_HOST_CLASS_HUB *hub, UINT port)
77
{
78
79
UINT        status;
80
UINT        port_enable_retry;
81
USHORT      port_status;
82
USHORT      port_change;
83
84
85
    /* Send the PORT_RESET command.  */
86
26
    status =  _ux_host_class_hub_feature(hub, port, UX_SET_FEATURE, UX_HOST_CLASS_HUB_PORT_RESET);
87
88
    /* Check the function result and update HUB status if there was a problem.  */
89
26
    if (status != UX_SUCCESS)
90
1
        return(status);
91
92
    /* We allow retrying of this as we may not get the port enable status bit
93
       set on the first try.  */
94
25
    port_enable_retry =  UX_HOST_CLASS_HUB_ENABLE_RETRY_COUNT;
95
28
    while (port_enable_retry--)
96
    {
97
98
        /* Now get the status until we have a port enabled.  */
99
27
        status =  _ux_host_class_hub_status_get(hub, port, &port_status, &port_change);
100
27
        if (status != UX_SUCCESS)
101
1
            return(status);
102
103
        /* On return of the GET_STATUS, the port_change field has been updated.
104
           Check for each of the bits it may contain. */
105
26
        if (port_change & UX_HOST_CLASS_HUB_PORT_CHANGE_RESET)
106
        {
107
108
            /* The port has been successfully reset.  */
109
110
            /* Clear the RESET change bit.  */
111
23
            _ux_host_class_hub_port_change_reset_process(hub, port, port_status);
112
113
            /* Return success.  */
114
23
            return(UX_SUCCESS);
115
        }
116
117
        /* We should wait a bit before retrying this operation.  */
118
3
        _ux_utility_delay_ms(UX_HOST_CLASS_HUB_ENABLE_RETRY_DELAY);
119
    }
120
121
    /* We get here when the port never reported RESET completion.  */
122
123
    /* Invoke error callback.  */
124
1
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HUB, UX_PORT_RESET_FAILED);
125
126
    /* Return error.  */
127
1
    return(UX_PORT_RESET_FAILED);
128
}
129