GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_interface_endpoint_get.c Lines: 14 18 77.8 %
Date: 2024-12-12 17:16:36 Branches: 6 10 60.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
/**   Host Stack                                                          */
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_stack.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _ux_host_stack_interface_endpoint_get               PORTABLE C      */
36
/*                                                           6.1.12       */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Chaoqiong Xiao, Microsoft Corporation                               */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function returns an endpoint container based on the interface  */
44
/*    handle and an endpoint index.                                       */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    interface                             Pointer to interface          */
49
/*    endpoint_index                        Index of endpoint to get      */
50
/*    endpoint                              Destination for endpoint      */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    None                                                                */
59
/*                                                                        */
60
/*  CALLED BY                                                             */
61
/*                                                                        */
62
/*    Application                                                         */
63
/*    USBX Components                                                     */
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
/*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
73
/*                                            fixed parameter/variable    */
74
/*                                            names conflict C++ keyword, */
75
/*                                            resulting in version 6.1.12 */
76
/*                                                                        */
77
/**************************************************************************/
78
1296
UINT  _ux_host_stack_interface_endpoint_get(UX_INTERFACE *interface_ptr, UINT endpoint_index, UX_ENDPOINT **endpoint)
79
{
80
81
UINT            current_endpoint_index;
82
UX_ENDPOINT     *current_endpoint;
83
84
    /* If trace is enabled, insert this event into the trace buffer.  */
85
    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)
86
87
    /* Do a sanity check on the interface handle.  */
88
1296
    if (interface_ptr -> ux_interface_handle != (ULONG) (ALIGN_TYPE) interface_ptr)
89
    {
90
91
        /* Error trap. */
92
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_INTERFACE_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_INTERFACE_HANDLE_UNKNOWN, interface_ptr, 0, 0, UX_TRACE_ERRORS, 0, 0)
96
97
1
        return(UX_INTERFACE_HANDLE_UNKNOWN);
98
    }
99
100
    /* Start with the endpoint attached to the interface.  */
101
1295
    current_endpoint =  interface_ptr -> ux_interface_first_endpoint;
102
103
    /* The first endpoint has the index 0.  */
104
1295
    current_endpoint_index =  0;
105
106
    /* Traverse the list of the endpoints until we found the right one.  */
107
1720
    while (current_endpoint != UX_NULL)
108
    {
109
110
        /* Check if the endpoint index matches the current one.  */
111
1716
        if (endpoint_index == current_endpoint_index)
112
        {
113
114
            /* Setup the return endpoint pointer.  */
115
1291
            *endpoint=current_endpoint;
116
117
            /* Return success to the caller.  */
118
1291
            return(UX_SUCCESS);
119
        }
120
121
        /* Move to the next endpoint.  */
122
425
        current_endpoint =  current_endpoint -> ux_endpoint_next_endpoint;
123
124
        /* Move to the next index.  */
125
425
        current_endpoint_index++;
126
    }
127
128
    /* Error trap. */
129
4
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_ENDPOINT_HANDLE_UNKNOWN);
130
131
    /* If trace is enabled, insert this event into the trace buffer.  */
132
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0)
133
134
    /* Return an error!  */
135
4
    return(UX_ENDPOINT_HANDLE_UNKNOWN);
136
}
137
138
139
/**************************************************************************/
140
/*                                                                        */
141
/*  FUNCTION                                               RELEASE        */
142
/*                                                                        */
143
/*    _uxe_host_stack_interface_endpoint_get              PORTABLE C      */
144
/*                                                           6.3.0        */
145
/*  AUTHOR                                                                */
146
/*                                                                        */
147
/*    Chaoqiong Xiao, Microsoft Corporation                               */
148
/*                                                                        */
149
/*  DESCRIPTION                                                           */
150
/*                                                                        */
151
/*    This function checks errors in host stack endpoint get function     */
152
/*    call.                                                               */
153
/*                                                                        */
154
/*  INPUT                                                                 */
155
/*                                                                        */
156
/*    interface_ptr                         Pointer to interface          */
157
/*    endpoint_index                        Index of endpoint to get      */
158
/*    endpoint                              Destination for endpoint      */
159
/*                                                                        */
160
/*  OUTPUT                                                                */
161
/*                                                                        */
162
/*    None                                                                */
163
/*                                                                        */
164
/*  CALLS                                                                 */
165
/*                                                                        */
166
/*    _ux_host_stack_interface_endpoint_get Endpoint get                  */
167
/*                                                                        */
168
/*  CALLED BY                                                             */
169
/*                                                                        */
170
/*    Application                                                         */
171
/*                                                                        */
172
/*  RELEASE HISTORY                                                       */
173
/*                                                                        */
174
/*    DATE              NAME                      DESCRIPTION             */
175
/*                                                                        */
176
/*  10-31-2023     Chaoqiong Xiao           Initial Version 6.3.0         */
177
/*                                                                        */
178
/**************************************************************************/
179
UINT  _uxe_host_stack_interface_endpoint_get(UX_INTERFACE *interface_ptr, UINT endpoint_index, UX_ENDPOINT **endpoint)
180
{
181
182
    /* Sanity checks.  */
183
    if ((interface_ptr == UX_NULL) || (endpoint == UX_NULL))
184
        return(UX_INVALID_PARAMETER);
185
186
    /* Invoke endpoint get function.  */
187
    return(_ux_host_stack_interface_endpoint_get(interface_ptr, endpoint_index, endpoint));
188
}