GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_idle_set.c Lines: 21 25 84.0 %
Date: 2026-03-06 18:57:10 Branches: 6 8 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_idle_set                         PORTABLE C      */
38
/*                                                           6.1.10       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function performs a SET_IDLE to the HID device.                */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    hid                                   Pointer to HID class          */
50
/*    idle_time                             Idle time                     */
51
/*    report_id                             Report ID                     */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _ux_host_stack_class_instance_verify  Verify instance is valid      */
60
/*    _ux_host_stack_transfer_request       Process transfer request      */
61
/*    _ux_host_semaphore_get                Get protection semaphore      */
62
/*    _ux_host_semaphore_put                Release protection semaphore  */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    HID Class                                                           */
67
/*                                                                        */
68
/**************************************************************************/
69
204
UINT  _ux_host_class_hid_idle_set(UX_HOST_CLASS_HID *hid, USHORT idle_time, USHORT report_id)
70
{
71
#if defined(UX_HOST_STANDALONE)
72
UINT            status;
73
    do
74
    {
75
        status = _ux_host_class_hid_idle_set_run(hid, idle_time, report_id);
76
    } while(status == UX_STATE_WAIT || status == UX_STATE_LOCK);
77
    return(hid -> ux_host_class_hid_status);
78
#else
79
80
UX_ENDPOINT     *control_endpoint;
81
UX_TRANSFER     *transfer_request;
82
UINT            status;
83
84
    /* If trace is enabled, insert this event into the trace buffer.  */
85
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_IDLE_SET, hid, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
86
87
    /* Ensure the instance is valid.  */
88
204
    if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
89
    {
90
91
        /* If trace is enabled, insert this event into the trace buffer.  */
92
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
93
94
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
95
    }
96
97
    /* We need to get the default control endpoint transfer request pointer.  */
98
203
    control_endpoint =  &hid -> ux_host_class_hid_device -> ux_device_control_endpoint;
99
203
    transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
100
101
    /* Protect thread reentry to this instance.  */
102
203
    status =  _ux_host_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER);
103
203
    if (status != UX_SUCCESS)
104
1
        return(status);
105
106
    /* Protect the control endpoint semaphore here.  It will be unprotected in the
107
       transfer request function.  */
108
202
    status =  _ux_host_semaphore_get(&hid -> ux_host_class_hid_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
109
110
    /* Check for status.  */
111
202
    if (status != UX_SUCCESS)
112
    {
113
114
        /* Something went wrong. */
115
        /* Unprotect thread reentry to this instance.  */
116
1
        _ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore);
117
118
1
        return(status);
119
    }
120
121
    /* Create a transfer request for the SET_IDLE request.  */
122
201
    transfer_request -> ux_transfer_request_data_pointer =      UX_NULL;
123
201
    transfer_request -> ux_transfer_request_requested_length =  0;
124
201
    transfer_request -> ux_transfer_request_function =          UX_HOST_CLASS_HID_SET_IDLE;
125
201
    transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
126
201
    transfer_request -> ux_transfer_request_value =             (UINT)((idle_time << 8) | report_id);
127
201
    transfer_request -> ux_transfer_request_index =             hid -> ux_host_class_hid_interface -> ux_interface_descriptor.bInterfaceNumber;
128
129
    /* Send request to HCD layer.  */
130
201
    status =  _ux_host_stack_transfer_request(transfer_request);
131
132
    /* Unprotect thread reentry to this instance.  */
133
201
    _ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore);
134
135
    /* Return the function status.  */
136
201
    return(status);
137
#endif
138
}
139
140
/**************************************************************************/
141
/*                                                                        */
142
/*  FUNCTION                                               RELEASE        */
143
/*                                                                        */
144
/*    _uxe_host_class_hid_idle_set                        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 IDLE set function call.          */
153
/*                                                                        */
154
/*  INPUT                                                                 */
155
/*                                                                        */
156
/*    hid                                   Pointer to HID class          */
157
/*    idle_time                             Idle time                     */
158
/*    report_id                             Report ID                     */
159
/*                                                                        */
160
/*  OUTPUT                                                                */
161
/*                                                                        */
162
/*    Status                                                              */
163
/*                                                                        */
164
/*  CALLS                                                                 */
165
/*                                                                        */
166
/*    _ux_host_class_hid_idle_set           Issue SET_IDLE to device      */
167
/*                                                                        */
168
/*  CALLED BY                                                             */
169
/*                                                                        */
170
/*    Application                                                         */
171
/*                                                                        */
172
/**************************************************************************/
173
UINT  _uxe_host_class_hid_idle_set(UX_HOST_CLASS_HID *hid, USHORT idle_time, USHORT report_id)
174
{
175
176
    /* Sanity check.  */
177
    if (hid == UX_NULL)
178
        return(UX_INVALID_PARAMETER);
179
180
    /* Invoke IDLE set function.  */
181
    return(_ux_host_class_hid_idle_set(hid, idle_time, report_id));
182
}