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