GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hub_feature.c Lines: 13 13 100.0 %
Date: 2026-03-06 18:57:10 Branches: 2 2 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_feature                          PORTABLE C      */
38
/*                                                           6.1.12       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function will send a command to the HUB on a specific port.    */
46
/*    The commands can be SET_FEATURE or CLEAR_FEATURE.                   */
47
/*                                                                        */
48
/*    In standalone mode, this functioin prepares the control transfer    */
49
/*    request context of specific command, for host stack transfer        */
50
/*    function to process, in next steps.                                 */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    hub                                   Pointer to HUB class          */
55
/*    port                                  Port number                   */
56
/*    command                               Command to send               */
57
/*    feature                               Feature to send               */
58
/*                                                                        */
59
/*  OUTPUT                                                                */
60
/*                                                                        */
61
/*    Completion Status                                                   */
62
/*                                                                        */
63
/*  CALLS                                                                 */
64
/*                                                                        */
65
/*    _ux_host_stack_transfer_request       Process transfer request      */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    HUB Class                                                           */
70
/*                                                                        */
71
/**************************************************************************/
72
180
UINT  _ux_host_class_hub_feature(UX_HOST_CLASS_HUB *hub, UINT port, UINT command, UINT function)
73
{
74
75
UX_ENDPOINT     *control_endpoint;
76
UX_TRANSFER     *transfer_request;
77
UINT            target;
78
UINT            status;
79
80
81
    /* We need to get the default control endpoint transfer request pointer.  */
82
180
    control_endpoint =  &hub -> ux_host_class_hub_device -> ux_device_control_endpoint;
83
180
    transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
84
85
    /* The target is DEVICE for the HUB and OTHER for the downstream ports.  */
86
180
    if (port == 0)
87
1
        target =  UX_REQUEST_TARGET_DEVICE;
88
    else
89
179
        target =  UX_REQUEST_TARGET_OTHER;
90
91
    /* Create a transfer request for the SET_FEATURE or CLEAR_FEATURE request.  */
92
180
    transfer_request -> ux_transfer_request_function =          command;
93
180
    transfer_request -> ux_transfer_request_requested_length =  0;
94
180
    transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | target;
95
180
    transfer_request -> ux_transfer_request_value =             function;
96
180
    transfer_request -> ux_transfer_request_index =             port;
97
98
#if defined(UX_HOST_STANDALONE)
99
100
    /* Reset transfer state for _run.  */
101
    UX_TRANSFER_STATE_RESET(transfer_request);
102
    status = UX_SUCCESS;
103
#else
104
105
    /* Send request to HCD layer.  */
106
180
    status =  _ux_host_stack_transfer_request(transfer_request);
107
#endif
108
109
    /* Return completion status.  */
110
180
    return(status);
111
}