GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_report_callback_register.c Lines: 18 22 81.8 %
Date: 2026-03-06 18:57:10 Branches: 8 12 66.7 %

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_callback_register         PORTABLE C      */
38
/*                                                           6.1.10       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function will register a report callback to a HID report.      */
46
/*    This function should be called by a HID client when it has been     */
47
/*    instantiated by a new HID device.                                   */
48
/*                                                                        */
49
/*    The registration process will allow the HID class to call a         */
50
/*    function in the HID client when an asynchronous report is present.  */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    hid                                   Pointer to HID class          */
55
/*    call_back                             HID report callback           */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    Completion Status                                                   */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    _ux_host_stack_class_instance_verify  Verify class instance is valid*/
64
/*    _ux_host_semaphore_get                Get protection semaphore      */
65
/*    _ux_host_semaphore_put                Release protection semaphore  */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    Application                                                         */
70
/*    HID Class                                                           */
71
/*                                                                        */
72
/**************************************************************************/
73
228
UINT  _ux_host_class_hid_report_callback_register(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_REPORT_CALLBACK *call_back)
74
{
75
#if defined(UX_HOST_STANDALONE)
76
UX_INTERRUPT_SAVE_AREA
77
#endif
78
UINT                            status;
79
UX_HOST_CLASS_HID_REPORT         *hid_report;
80
81
82
    /* Ensure the instance is valid.  */
83
228
    if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
84
    {
85
86
        /* Error trap. */
87
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
88
89
        /* If trace is enabled, insert this event into the trace buffer.  */
90
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
91
92
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
93
    }
94
95
    /* Protect thread reentry to this instance.  */
96
227
    _ux_host_class_hid_lock_fail_return(hid);
97
98
    /* Search for the report ID. Note that this can only be an Input report!  */
99
226
    hid_report =  hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_input_report;
100
101
    /* Parse all the report IDs in search of the one specified by the user.  */
102
230
    while (hid_report != UX_NULL)
103
    {
104
105
        /* Check report ID.  */
106
229
        if (hid_report -> ux_host_class_hid_report_id == call_back -> ux_host_class_hid_report_callback_id)
107
        {
108
109
            /* We have found the correct report. Set the call back function, buffer and flags.  */
110
225
            hid_report -> ux_host_class_hid_report_callback_function =   call_back -> ux_host_class_hid_report_callback_function;
111
225
            hid_report -> ux_host_class_hid_report_callback_buffer   =   call_back -> ux_host_class_hid_report_callback_buffer;
112
225
            hid_report -> ux_host_class_hid_report_callback_flags    =   call_back -> ux_host_class_hid_report_callback_flags;
113
225
            hid_report -> ux_host_class_hid_report_callback_length   =   call_back -> ux_host_class_hid_report_callback_length;
114
115
            /* Unprotect thread reentry to this instance.  */
116
225
            _ux_host_class_hid_unlock(hid);
117
118
            /* Tell the user the report was OK and the call back was registered.  */
119
225
            return(UX_SUCCESS);
120
        }
121
122
        /* Jump to next report.  */
123
4
        hid_report = hid_report -> ux_host_class_hid_report_next_report;
124
    }
125
126
    /* Unprotect thread reentry to this instance.  */
127
1
    _ux_host_class_hid_unlock(hid);
128
129
    /* Error trap. */
130
1
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_REPORT_ERROR);
131
132
    /* If trace is enabled, insert this event into the trace buffer.  */
133
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_REPORT_ERROR, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
134
135
    /* The report ID could not be found amongst the reports.  */
136
1
    return(UX_HOST_CLASS_HID_REPORT_ERROR);
137
}
138
139
140
/**************************************************************************/
141
/*                                                                        */
142
/*  FUNCTION                                               RELEASE        */
143
/*                                                                        */
144
/*    _uxe_host_class_hid_report_callback_register        PORTABLE C      */
145
/*                                                           6.3.0        */
146
/*  AUTHOR                                                                */
147
/*                                                                        */
148
/*    Chaoqiong Xiao, Microsoft Corporation                               */
149
/*                                                                        */
150
/*  DESCRIPTION                                                           */
151
/*                                                                        */
152
/*    This function checks errors in HID report callback register function*/
153
/*    call.                                                               */
154
/*                                                                        */
155
/*  INPUT                                                                 */
156
/*                                                                        */
157
/*    hid                                   Pointer to HID class          */
158
/*    call_back                             HID report callback           */
159
/*                                                                        */
160
/*  OUTPUT                                                                */
161
/*                                                                        */
162
/*    Status                                                              */
163
/*                                                                        */
164
/*  CALLS                                                                 */
165
/*                                                                        */
166
/*    _ux_host_class_hid_report_callback_register                         */
167
/*                                          Register a report callback    */
168
/*                                                                        */
169
/*  CALLED BY                                                             */
170
/*                                                                        */
171
/*    Application                                                         */
172
/*                                                                        */
173
/**************************************************************************/
174
UINT  _uxe_host_class_hid_report_callback_register(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_REPORT_CALLBACK *call_back)
175
{
176
177
    /* Sanity check.  */
178
    if ((hid == UX_NULL) || (call_back == UX_NULL))
179
        return(UX_INVALID_PARAMETER);
180
181
    /* Invoke periodic start function.  */
182
    return(_ux_host_class_hid_report_callback_register(hid, call_back));
183
}