GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_report_id_get.c Lines: 28 32 87.5 %
Date: 2026-03-06 18:57:10 Branches: 12 16 75.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
/**   HID 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_hid.h"
30
#include "ux_host_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_host_class_hid_report_id_get                    PORTABLE C      */
38
/*                                                           6.1.10       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function retrieves the report after                            */
46
/*    report_id -> ux_host_class_hid_report_get_id and stores it in the   */
47
/*    same pointer. If report_id -> ux_host_class_hid_report_get_id is    */
48
/*    null, retrieves the first report of the type specified by           */
49
/*    report_id -> ux_host_class_hid_report_get_type.                     */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    hid                                   Pointer to HID class          */
54
/*    report_id                             Report id structure           */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    Completion Status                                                   */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _ux_host_semaphore_get                Get protection semaphore      */
63
/*    _ux_host_semaphore_put                Release protection semaphore  */
64
/*    _ux_host_stack_class_instance_verify  Verify class instance is valid*/
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application                                                         */
69
/*    HID Class                                                           */
70
/*                                                                        */
71
/**************************************************************************/
72
436
UINT  _ux_host_class_hid_report_id_get(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_REPORT_GET_ID *report_id)
73
{
74
#if defined(UX_HOST_STANDALONE)
75
UX_INTERRUPT_SAVE_AREA
76
#endif
77
UINT                        status;
78
UX_HOST_CLASS_HID_REPORT    *next_hid_report;
79
80
81
    /* Ensure the instance is valid.  */
82
436
    if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
83
    {
84
85
        /* Error trap.  */
86
3
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
87
88
        /* If trace is enabled, insert this event into the trace buffer.  */
89
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
90
91
3
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
92
    }
93
94
    /* Protect thread reentry to this instance.  */
95
433
    _ux_host_class_hid_lock_fail_return(hid);
96
97
    /* Check if this is the first report to get.  */
98
432
    if (report_id -> ux_host_class_hid_report_get_report == UX_NULL)
99
    {
100
101
        /* Check for the type of report ID to get (Input, Output, Feature).  */
102

415
        switch (report_id -> ux_host_class_hid_report_get_type)
103
        {
104
105
244
        case UX_HOST_CLASS_HID_REPORT_TYPE_INPUT           :
106
107
            /* Search for the input report ID. */
108
244
            next_hid_report =  hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_input_report;
109
244
            break;
110
111
167
        case UX_HOST_CLASS_HID_REPORT_TYPE_OUTPUT          :
112
113
            /* Search for the output report ID. */
114
167
            next_hid_report =  hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_output_report;
115
167
            break;
116
117
3
        case UX_HOST_CLASS_HID_REPORT_TYPE_FEATURE         :
118
119
            /* Search for the feature report ID. */
120
3
            next_hid_report =  hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_feature_report;
121
3
            break;
122
123
1
        default :
124
125
            /* Error trap.  */
126
1
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_REPORT_ERROR);
127
128
            /* If trace is enabled, insert this event into the trace buffer.  */
129
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_REPORT_ERROR, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
130
131
            /* The report ID could not be found amongst the reports.  */
132
1
            next_hid_report =  UX_NULL;
133
1
            break;
134
        }
135
    }
136
    else
137
    {
138
139
        /* We had a report ID scan previously, point to the next report.  */
140
17
        next_hid_report =  report_id -> ux_host_class_hid_report_get_report -> ux_host_class_hid_report_next_report;
141
    }
142
143
    /* Did we find the next report?  */
144
432
    if (next_hid_report != UX_NULL)
145
    {
146
147
        /* We want the first report, memorize the ID.  */
148
422
        report_id -> ux_host_class_hid_report_get_id =  next_hid_report -> ux_host_class_hid_report_id;
149
150
        /* And remember where we left.  */
151
422
        report_id -> ux_host_class_hid_report_get_report =  next_hid_report;
152
153
        /* Successfully found next report.  */
154
422
        status =  UX_SUCCESS;
155
    }
156
    else
157
    {
158
159
        /* If trace is enabled, insert this event into the trace buffer.  */
160
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_REPORT_ERROR, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
161
162
        /* No more reports.  */
163
10
        status =  UX_HOST_CLASS_HID_REPORT_ERROR;
164
    }
165
166
    /* Unprotect thread reentry to this instance.  */
167
432
    _ux_host_class_hid_unlock(hid);
168
169
    /* The status variable has been set correctly.  */
170
432
    return(status);
171
}
172
173
/**************************************************************************/
174
/*                                                                        */
175
/*  FUNCTION                                               RELEASE        */
176
/*                                                                        */
177
/*    _uxe_host_class_hid_report_id_get                   PORTABLE C      */
178
/*                                                           6.3.0        */
179
/*  AUTHOR                                                                */
180
/*                                                                        */
181
/*    Chaoqiong Xiao, Microsoft Corporation                               */
182
/*                                                                        */
183
/*  DESCRIPTION                                                           */
184
/*                                                                        */
185
/*    This function checks errors in HID report ID get function call.     */
186
/*                                                                        */
187
/*  INPUT                                                                 */
188
/*                                                                        */
189
/*    hid                                   Pointer to HID class          */
190
/*    report_id                             Report id structure           */
191
/*                                                                        */
192
/*  OUTPUT                                                                */
193
/*                                                                        */
194
/*    Status                                                              */
195
/*                                                                        */
196
/*  CALLS                                                                 */
197
/*                                                                        */
198
/*    _ux_host_class_hid_report_id_get      Get a report                  */
199
/*                                                                        */
200
/*  CALLED BY                                                             */
201
/*                                                                        */
202
/*    Application                                                         */
203
/*                                                                        */
204
/**************************************************************************/
205
UINT  _uxe_host_class_hid_report_id_get(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_REPORT_GET_ID *report_id)
206
{
207
208
    /* Sanity checks.  */
209
    if ((hid == UX_NULL) || (report_id == UX_NULL))
210
        return(UX_INVALID_PARAMETER);
211
212
    /* Invoke report ID get function.  */
213
    return(_ux_host_class_hid_report_id_get(hid, report_id));
214
}