GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hub_change_process.c Lines: 13 13 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_change_process                   PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function is called by the topology thread when there has been  */
46
/*    activity on the HUB.                                                */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    hub                                   Pointer to HUB                */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_class_hub_port_change_process Port change process          */
59
/*    _ux_host_stack_transfer_request       Process transfer request      */
60
/*    _ux_utility_short_get                 Get 16-bit word               */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    HUB Class                                                           */
65
/*                                                                        */
66
/**************************************************************************/
67
27
UINT  _ux_host_class_hub_change_process(UX_HOST_CLASS_HUB *hub)
68
{
69
70
UX_TRANSFER     *transfer_request;
71
USHORT          port_status_change_bits;
72
UINT            port_index;
73
UINT            status;
74
75
76
    /* Now get the transfer_request attached to the interrupt endpoint.  */
77
27
    transfer_request =  &hub -> ux_host_class_hub_interrupt_endpoint -> ux_endpoint_transfer_request;
78
79
    /* The interrupt pipe buffer contains the status change for each of the ports
80
       the length of the buffer can be 1 or 2 depending on the number of ports.
81
       Usually, since HUBs can be bus powered the maximum number of ports is 4.
82
       We must be taking precautions on how we read the buffer content for
83
       big endian machines.  */
84
27
    if (transfer_request -> ux_transfer_request_actual_length == 1)
85
26
        port_status_change_bits =  (USHORT) *transfer_request -> ux_transfer_request_data_pointer;
86
    else
87
1
        port_status_change_bits =  (USHORT)_ux_utility_short_get(transfer_request -> ux_transfer_request_data_pointer);
88
89
    /* Scan all bits and report the change on each port.  */
90
81
    for (port_index = 1; port_index <= hub -> ux_host_class_hub_descriptor.bNbPorts; port_index++)
91
    {
92
93
54
        if (port_status_change_bits & (1<<port_index))
94
27
            _ux_host_class_hub_port_change_process(hub, port_index);
95
    }
96
97
    /* The HUB could also have changed.  */
98
27
    if (port_status_change_bits & 1)
99
1
        _ux_host_class_hub_hub_change_process(hub);
100
101
    /* The actual length should be cleared for the next transfer.  */
102
27
    transfer_request -> ux_transfer_request_actual_length =  0;
103
104
    /* Resend the request to the stack.  */
105
27
    status = _ux_host_stack_transfer_request(transfer_request);
106
107
    /* Return completion status.  */
108
27
    return(status);
109
}