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: 2024-12-12 17:16:36 Branches: 6 8 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_idle_set                         PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function performs a SET_IDLE to the HID device.                */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    hid                                   Pointer to HID class          */
49
/*    idle_time                             Idle time                     */
50
/*    report_id                             Report ID                     */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_stack_class_instance_verify  Verify instance is valid      */
59
/*    _ux_host_stack_transfer_request       Process transfer request      */
60
/*    _ux_host_semaphore_get                Get protection semaphore      */
61
/*    _ux_host_semaphore_put                Release protection semaphore  */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    HID Class                                                           */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73
/*                                            protected default control   */
74
/*                                            endpoint before using it,   */
75
/*                                            resulting in version 6.1    */
76
/*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
77
/*                                            added standalone support,   */
78
/*                                            resulting in version 6.1.10 */
79
/*                                                                        */
80
/**************************************************************************/
81
204
UINT  _ux_host_class_hid_idle_set(UX_HOST_CLASS_HID *hid, USHORT idle_time, USHORT report_id)
82
{
83
#if defined(UX_HOST_STANDALONE)
84
UINT            status;
85
    do
86
    {
87
        status = _ux_host_class_hid_idle_set_run(hid, idle_time, report_id);
88
    } while(status == UX_STATE_WAIT || status == UX_STATE_LOCK);
89
    return(hid -> ux_host_class_hid_status);
90
#else
91
92
UX_ENDPOINT     *control_endpoint;
93
UX_TRANSFER     *transfer_request;
94
UINT            status;
95
96
    /* If trace is enabled, insert this event into the trace buffer.  */
97
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_IDLE_SET, hid, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
98
99
    /* Ensure the instance is valid.  */
100
204
    if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
101
    {
102
103
        /* If trace is enabled, insert this event into the trace buffer.  */
104
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
105
106
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
107
    }
108
109
    /* We need to get the default control endpoint transfer request pointer.  */
110
203
    control_endpoint =  &hid -> ux_host_class_hid_device -> ux_device_control_endpoint;
111
203
    transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
112
113
    /* Protect thread reentry to this instance.  */
114
203
    status =  _ux_host_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER);
115
203
    if (status != UX_SUCCESS)
116
1
        return(status);
117
118
    /* Protect the control endpoint semaphore here.  It will be unprotected in the
119
       transfer request function.  */
120
202
    status =  _ux_host_semaphore_get(&hid -> ux_host_class_hid_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
121
122
    /* Check for status.  */
123
202
    if (status != UX_SUCCESS)
124
    {
125
126
        /* Something went wrong. */
127
        /* Unprotect thread reentry to this instance.  */
128
1
        _ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore);
129
130
1
        return(status);
131
    }
132
133
    /* Create a transfer request for the SET_IDLE request.  */
134
201
    transfer_request -> ux_transfer_request_data_pointer =      UX_NULL;
135
201
    transfer_request -> ux_transfer_request_requested_length =  0;
136
201
    transfer_request -> ux_transfer_request_function =          UX_HOST_CLASS_HID_SET_IDLE;
137
201
    transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
138
201
    transfer_request -> ux_transfer_request_value =             (UINT)((idle_time << 8) | report_id);
139
201
    transfer_request -> ux_transfer_request_index =             hid -> ux_host_class_hid_interface -> ux_interface_descriptor.bInterfaceNumber;
140
141
    /* Send request to HCD layer.  */
142
201
    status =  _ux_host_stack_transfer_request(transfer_request);
143
144
    /* Unprotect thread reentry to this instance.  */
145
201
    _ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore);
146
147
    /* Return the function status.  */
148
201
    return(status);
149
#endif
150
}
151
152
/**************************************************************************/
153
/*                                                                        */
154
/*  FUNCTION                                               RELEASE        */
155
/*                                                                        */
156
/*    _uxe_host_class_hid_idle_set                        PORTABLE C      */
157
/*                                                           6.3.0        */
158
/*  AUTHOR                                                                */
159
/*                                                                        */
160
/*    Chaoqiong Xiao, Microsoft Corporation                               */
161
/*                                                                        */
162
/*  DESCRIPTION                                                           */
163
/*                                                                        */
164
/*    This function checks errors in HID IDLE set function call.          */
165
/*                                                                        */
166
/*  INPUT                                                                 */
167
/*                                                                        */
168
/*    hid                                   Pointer to HID class          */
169
/*    idle_time                             Idle time                     */
170
/*    report_id                             Report ID                     */
171
/*                                                                        */
172
/*  OUTPUT                                                                */
173
/*                                                                        */
174
/*    Status                                                              */
175
/*                                                                        */
176
/*  CALLS                                                                 */
177
/*                                                                        */
178
/*    _ux_host_class_hid_idle_set           Issue SET_IDLE to device      */
179
/*                                                                        */
180
/*  CALLED BY                                                             */
181
/*                                                                        */
182
/*    Application                                                         */
183
/*                                                                        */
184
/*  RELEASE HISTORY                                                       */
185
/*                                                                        */
186
/*    DATE              NAME                      DESCRIPTION             */
187
/*                                                                        */
188
/*  10-31-2023     Chaoqiong Xiao           Initial Version 6.3.0         */
189
/*                                                                        */
190
/**************************************************************************/
191
UINT  _uxe_host_class_hid_idle_set(UX_HOST_CLASS_HID *hid, USHORT idle_time, USHORT report_id)
192
{
193
194
    /* Sanity check.  */
195
    if (hid == UX_NULL)
196
        return(UX_INVALID_PARAMETER);
197
198
    /* Invoke IDLE set function.  */
199
    return(_ux_host_class_hid_idle_set(hid, idle_time, report_id));
200
}