GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_storage_configure.c Lines: 19 19 100.0 %
Date: 2026-03-06 18:57:10 Branches: 14 14 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
/**   Storage 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_storage.h"
30
#include "ux_host_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_host_class_storage_configure                    PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function calls the USBX stack to do a SET_CONFIGURATION to the */
46
/*    storage device. Once the storage is configured, its interface will  */
47
/*    be activated. The bulk endpoints enumerated(1 IN, 1 OUT).           */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    storage                               Pointer to storage class      */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _ux_host_stack_configuration_interface_get    Get configuration     */
60
/*    _ux_host_stack_device_configuration_get       Get device config     */
61
/*    _ux_host_stack_device_configuration_select    Select configuration  */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Storage Class                                                       */
66
/*                                                                        */
67
/**************************************************************************/
68
134
UINT  _ux_host_class_storage_configure(UX_HOST_CLASS_STORAGE *storage)
69
{
70
71
UINT                    status;
72
UX_CONFIGURATION        *configuration;
73
#if UX_MAX_DEVICES > 1
74
UX_DEVICE               *parent_device;
75
#endif
76
77
78
    /* If the device has been configured already, we don't need to do it
79
       again.  */
80
134
    if (storage -> ux_host_class_storage_device -> ux_device_state == UX_DEVICE_CONFIGURED)
81
126
        return(UX_SUCCESS);
82
83
    /* A storage device normally has one configuration. So retrieve the 1st configuration
84
       only.  */
85
8
    status =  _ux_host_stack_device_configuration_get(storage -> ux_host_class_storage_device, 0, &configuration);
86
87
    /* Check completion status.  */
88
8
    if (status != UX_SUCCESS)
89
    {
90
91
        /* Error trap. */
92
2
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONFIGURATION_HANDLE_UNKNOWN);
93
94
        /* If trace is enabled, insert this event into the trace buffer.  */
95
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, storage -> ux_host_class_storage_device, 0, 0, UX_TRACE_ERRORS, 0, 0)
96
97
2
        return(UX_CONFIGURATION_HANDLE_UNKNOWN);
98
    }
99
100
#if UX_MAX_DEVICES > 1
101
    /* Check the storage device power source and check the parent power source for
102
       incompatible connections.  */
103
6
    if (storage -> ux_host_class_storage_device -> ux_device_power_source == UX_DEVICE_BUS_POWERED)
104
    {
105
106
        /* Pickup pointer to parent device.  */
107
5
        parent_device =  storage -> ux_host_class_storage_device -> ux_device_parent;
108
109
        /* If the device is NULL, the parent is the root hub and we don't have to worry
110
           if the parent is not the root hub, check for its power source.  */
111

5
        if ((parent_device != UX_NULL) && (parent_device -> ux_device_power_source == UX_DEVICE_BUS_POWERED))
112
        {
113
114
            /* Error trap. */
115
1
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONNECTION_INCOMPATIBLE);
116
117
            /* If trace is enabled, insert this event into the trace buffer.  */
118
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONNECTION_INCOMPATIBLE, storage, 0, 0, UX_TRACE_ERRORS, 0, 0)
119
120
1
            return(UX_CONNECTION_INCOMPATIBLE);
121
        }
122
    }
123
#endif
124
125
    /* We have the valid configuration. Ask the USBX stack to set this configuration.  */
126
5
    status =  _ux_host_stack_device_configuration_select(configuration);
127
5
    if (status != UX_SUCCESS)
128
3
        return(status);
129
130
    /* If the operation went well, the storage device default alternate setting
131
       for the storage device interface is active and the interrupt endpoint is now enabled.
132
       We have to memorize the first interface since the interrupt endpoint is hooked to it.  */
133
2
    status =  _ux_host_stack_configuration_interface_get(configuration, 0, 0, &storage -> ux_host_class_storage_interface);
134
135
    /* Check completion status.  */
136
2
    if (status != UX_SUCCESS)
137
    {
138
        /* Store the instance in the interface container, this is for the USBX stack
139
           when it needs to invoke the class.  */
140
1
        storage -> ux_host_class_storage_interface -> ux_interface_class_instance =  (VOID *) storage;
141
    }
142
143
    /* Return completion status.  */
144
2
    return(status);
145
}
146