GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_interface_endpoint_get.c Lines: 14 18 77.8 %
Date: 2026-03-06 18:57:10 Branches: 6 10 60.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_interface_endpoint_get               PORTABLE C      */
37
/*                                                           6.1.12       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function returns an endpoint container based on the interface  */
45
/*    handle and an endpoint index.                                       */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    interface                             Pointer to interface          */
50
/*    endpoint_index                        Index of endpoint to get      */
51
/*    endpoint                              Destination for endpoint      */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    None                                                                */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Application                                                         */
64
/*    USBX Components                                                     */
65
/*                                                                        */
66
/**************************************************************************/
67
1299
UINT  _ux_host_stack_interface_endpoint_get(UX_INTERFACE *interface_ptr, UINT endpoint_index, UX_ENDPOINT **endpoint)
68
{
69
70
UINT            current_endpoint_index;
71
UX_ENDPOINT     *current_endpoint;
72
73
    /* If trace is enabled, insert this event into the trace buffer.  */
74
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_INTERFACE_ENDPOINT_GET, interface_ptr, endpoint_index, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
75
76
    /* Do a sanity check on the interface handle.  */
77
1299
    if (interface_ptr -> ux_interface_handle != (ULONG) (ALIGN_TYPE) interface_ptr)
78
    {
79
80
        /* Error trap. */
81
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_INTERFACE_HANDLE_UNKNOWN);
82
83
        /* If trace is enabled, insert this event into the trace buffer.  */
84
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_INTERFACE_HANDLE_UNKNOWN, interface_ptr, 0, 0, UX_TRACE_ERRORS, 0, 0)
85
86
1
        return(UX_INTERFACE_HANDLE_UNKNOWN);
87
    }
88
89
    /* Start with the endpoint attached to the interface.  */
90
1298
    current_endpoint =  interface_ptr -> ux_interface_first_endpoint;
91
92
    /* The first endpoint has the index 0.  */
93
1298
    current_endpoint_index =  0;
94
95
    /* Traverse the list of the endpoints until we found the right one.  */
96
1724
    while (current_endpoint != UX_NULL)
97
    {
98
99
        /* Check if the endpoint index matches the current one.  */
100
1720
        if (endpoint_index == current_endpoint_index)
101
        {
102
103
            /* Setup the return endpoint pointer.  */
104
1294
            *endpoint=current_endpoint;
105
106
            /* Return success to the caller.  */
107
1294
            return(UX_SUCCESS);
108
        }
109
110
        /* Move to the next endpoint.  */
111
426
        current_endpoint =  current_endpoint -> ux_endpoint_next_endpoint;
112
113
        /* Move to the next index.  */
114
426
        current_endpoint_index++;
115
    }
116
117
    /* Error trap. */
118
4
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_ENDPOINT_HANDLE_UNKNOWN);
119
120
    /* If trace is enabled, insert this event into the trace buffer.  */
121
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0)
122
123
    /* Return an error!  */
124
4
    return(UX_ENDPOINT_HANDLE_UNKNOWN);
125
}
126
127
128
/**************************************************************************/
129
/*                                                                        */
130
/*  FUNCTION                                               RELEASE        */
131
/*                                                                        */
132
/*    _uxe_host_stack_interface_endpoint_get              PORTABLE C      */
133
/*                                                           6.3.0        */
134
/*  AUTHOR                                                                */
135
/*                                                                        */
136
/*    Chaoqiong Xiao, Microsoft Corporation                               */
137
/*                                                                        */
138
/*  DESCRIPTION                                                           */
139
/*                                                                        */
140
/*    This function checks errors in host stack endpoint get function     */
141
/*    call.                                                               */
142
/*                                                                        */
143
/*  INPUT                                                                 */
144
/*                                                                        */
145
/*    interface_ptr                         Pointer to interface          */
146
/*    endpoint_index                        Index of endpoint to get      */
147
/*    endpoint                              Destination for endpoint      */
148
/*                                                                        */
149
/*  OUTPUT                                                                */
150
/*                                                                        */
151
/*    None                                                                */
152
/*                                                                        */
153
/*  CALLS                                                                 */
154
/*                                                                        */
155
/*    _ux_host_stack_interface_endpoint_get Endpoint get                  */
156
/*                                                                        */
157
/*  CALLED BY                                                             */
158
/*                                                                        */
159
/*    Application                                                         */
160
/*                                                                        */
161
/**************************************************************************/
162
UINT  _uxe_host_stack_interface_endpoint_get(UX_INTERFACE *interface_ptr, UINT endpoint_index, UX_ENDPOINT **endpoint)
163
{
164
165
    /* Sanity checks.  */
166
    if ((interface_ptr == UX_NULL) || (endpoint == UX_NULL))
167
        return(UX_INVALID_PARAMETER);
168
169
    /* Invoke endpoint get function.  */
170
    return(_ux_host_stack_interface_endpoint_get(interface_ptr, endpoint_index, endpoint));
171
}