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: 2024-12-12 17:16:36 Branches: 12 16 75.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
/**   HID Class                                                           */
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_class_hid.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_class_hid_report_id_get                    PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function retrieves the report after                            */
45
/*    report_id -> ux_host_class_hid_report_get_id and stores it in the   */
46
/*    same pointer. If report_id -> ux_host_class_hid_report_get_id is    */
47
/*    null, retrieves the first report of the type specified by           */
48
/*    report_id -> ux_host_class_hid_report_get_type.                     */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    hid                                   Pointer to HID class          */
53
/*    report_id                             Report id structure           */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    Completion Status                                                   */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _ux_host_semaphore_get                Get protection semaphore      */
62
/*    _ux_host_semaphore_put                Release protection semaphore  */
63
/*    _ux_host_stack_class_instance_verify  Verify class instance is valid*/
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application                                                         */
68
/*    HID Class                                                           */
69
/*                                                                        */
70
/*  RELEASE HISTORY                                                       */
71
/*                                                                        */
72
/*    DATE              NAME                      DESCRIPTION             */
73
/*                                                                        */
74
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
75
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
76
/*                                            resulting in version 6.1    */
77
/*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
78
/*                                            added standalone support,   */
79
/*                                            resulting in version 6.1.10 */
80
/*                                                                        */
81
/**************************************************************************/
82
436
UINT  _ux_host_class_hid_report_id_get(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_REPORT_GET_ID *report_id)
83
{
84
#if defined(UX_HOST_STANDALONE)
85
UX_INTERRUPT_SAVE_AREA
86
#endif
87
UINT                        status;
88
UX_HOST_CLASS_HID_REPORT    *next_hid_report;
89
90
91
    /* Ensure the instance is valid.  */
92
436
    if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
93
    {
94
95
        /* Error trap.  */
96
3
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
97
98
        /* If trace is enabled, insert this event into the trace buffer.  */
99
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
100
101
3
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
102
    }
103
104
    /* Protect thread reentry to this instance.  */
105
433
    _ux_host_class_hid_lock_fail_return(hid);
106
107
    /* Check if this is the first report to get.  */
108
432
    if (report_id -> ux_host_class_hid_report_get_report == UX_NULL)
109
    {
110
111
        /* Check for the type of report ID to get (Input, Output, Feature).  */
112

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