GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_device_configuration_reset.c Lines: 20 20 100.0 %
Date: 2026-03-06 18:57:10 Branches: 4 4 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
/**   Host Stack                                                          */
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_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_stack_device_configuration_reset           PORTABLE C      */
37
/*                                                           6.1.12       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function resets the configuration of the device to zero.       */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    configuration                          Pointer to configuration     */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    Completion Status                                                   */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    _ux_host_stack_configuration_instance_delete                        */
57
/*                                           Delete configuration instance*/
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    USBX Components                                                     */
62
/*                                                                        */
63
/**************************************************************************/
64
12
UINT  _ux_host_stack_device_configuration_reset(UX_DEVICE *device)
65
{
66
67
UX_TRANSFER             *transfer_request;
68
UX_ENDPOINT             *control_endpoint;
69
UX_CONFIGURATION        *current_configuration;
70
UINT                    status;
71
72
    /* If trace is enabled, insert this event into the trace buffer.  */
73
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_SELECT, device, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
74
75
    /* A configuration is selected. Retrieve the pointer to the control endpoint
76
       and its transfer request.  */
77
12
    control_endpoint =  &device -> ux_device_control_endpoint;
78
12
    transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
79
80
    /* Check for the state of the device . If the device is already configured,
81
       we need to cancel the existing configuration before resetting it.   */
82
12
    if (device -> ux_device_state == UX_DEVICE_CONFIGURED)
83
    {
84
85
        /* The device is configured. Get the first configuration pointer.  */
86
10
        current_configuration =  device -> ux_device_current_configuration;
87
88
        /* Deselect this instance */
89
10
        _ux_host_stack_configuration_instance_delete(current_configuration);
90
    }
91
92
    /* No configuration is selected now.  */
93
12
    device -> ux_device_current_configuration = UX_NULL;
94
95
    /* Packed descriptor are not valid now.  */
96
12
    if (device -> ux_device_packed_configuration)
97
    {
98
1
        _ux_utility_memory_free(device -> ux_device_packed_configuration);
99
1
        device -> ux_device_packed_configuration = UX_NULL;
100
1
        device -> ux_device_packed_configuration_keep_count = 0;
101
    }
102
103
    /* Set state of device to ADDRESSED.  */
104
12
    device -> ux_device_state = UX_DEVICE_ADDRESSED;
105
106
    /* Reset power source.  */
107
12
    device -> ux_device_power_source = UX_DEVICE_BUS_POWERED;
108
109
    /* Create a transfer_request for the SET_CONFIGURATION request. No data for this request.  */
110
12
    transfer_request -> ux_transfer_request_requested_length =  0;
111
12
    transfer_request -> ux_transfer_request_function =          UX_SET_CONFIGURATION;
112
12
    transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE;
113
12
    transfer_request -> ux_transfer_request_value =             0;
114
12
    transfer_request -> ux_transfer_request_index =             0;
115
116
    /* Send request to HCD layer.  */
117
12
    status =  _ux_host_stack_transfer_request(transfer_request);
118
119
    /* Return status.  */
120
12
    return(status);
121
}
122