GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_periodic_report_start.c Lines: 15 19 78.9 %
Date: 2026-03-06 18:57:10 Branches: 8 10 80.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_periodic_report_start            PORTABLE C      */
38
/*                                                           6.1.10       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function starts the interrupt endpoint to obtain the periodic  */
46
/*    report.                                                             */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    hid                                   Pointer to HID class          */
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
/*    Application                                                         */
66
/*    HID Class                                                           */
67
/*                                                                        */
68
/**************************************************************************/
69
211
UINT  _ux_host_class_hid_periodic_report_start(UX_HOST_CLASS_HID *hid)
70
{
71
#if defined(UX_HOST_STANDALONE)
72
UX_INTERRUPT_SAVE_AREA
73
#endif
74
UINT            status;
75
UX_TRANSFER     *transfer_request;
76
77
78
    /* Ensure the instance is valid.  */
79
211
    if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
80
    {
81
82
        /* Error trap. */
83
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
84
85
        /* If trace is enabled, insert this event into the trace buffer.  */
86
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
87
88
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
89
    }
90
91
    /* Protect thread reentry to this instance.  */
92
210
    _ux_host_class_hid_lock_fail_return(hid);
93
94
    /* Check the status of the interrupt endpoint.  */
95
209
    if (hid -> ux_host_class_hid_interrupt_endpoint_status != UX_HOST_CLASS_HID_INTERRUPT_ENDPOINT_READY)
96
    {
97
98
        /* Unprotect thread reentry to this instance.  */
99
3
        _ux_host_class_hid_unlock(hid);
100
101
        /* Error trap. */
102
3
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_PERIODIC_REPORT_ERROR);
103
104
        /* If trace is enabled, insert this event into the trace buffer.  */
105
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_PERIODIC_REPORT_ERROR, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
106
107
        /* Return error status.  */
108
3
        return(UX_HOST_CLASS_HID_PERIODIC_REPORT_ERROR);
109
    }
110
111
    /* Get the address of the HID associated with the interrupt endpoint.  */
112
206
    transfer_request =  &hid -> ux_host_class_hid_interrupt_endpoint -> ux_endpoint_transfer_request;
113
114
    /* The transfer on the interrupt endpoint can be started.  */
115
206
    status =  _ux_host_stack_transfer_request(transfer_request);
116
117
    /* Check the status. If no error, adjust the status of the periodic endpoint
118
       to active.  */
119
206
    if (status == UX_SUCCESS)
120
205
        hid -> ux_host_class_hid_interrupt_endpoint_status =  UX_HOST_CLASS_HID_INTERRUPT_ENDPOINT_ACTIVE;
121
122
    /* Unprotect thread reentry to this instance.  */
123
206
    _ux_host_class_hid_unlock(hid);
124
125
    /* Return the function status */
126
206
    return(status);
127
}
128
129
/**************************************************************************/
130
/*                                                                        */
131
/*  FUNCTION                                               RELEASE        */
132
/*                                                                        */
133
/*    _uxe_host_class_hid_periodic_report_start           PORTABLE C      */
134
/*                                                           6.3.0        */
135
/*  AUTHOR                                                                */
136
/*                                                                        */
137
/*    Chaoqiong Xiao, Microsoft Corporation                               */
138
/*                                                                        */
139
/*  DESCRIPTION                                                           */
140
/*                                                                        */
141
/*    This function checks errors in HID periodic report start function   */
142
/*    call.                                                               */
143
/*                                                                        */
144
/*  INPUT                                                                 */
145
/*                                                                        */
146
/*    hid                                   Pointer to HID class          */
147
/*                                                                        */
148
/*  OUTPUT                                                                */
149
/*                                                                        */
150
/*    Status                                                              */
151
/*                                                                        */
152
/*  CALLS                                                                 */
153
/*                                                                        */
154
/*    _ux_host_class_hid_periodic_report_start                            */
155
/*                                          Start polling periodic report */
156
/*                                                                        */
157
/*  CALLED BY                                                             */
158
/*                                                                        */
159
/*    Application                                                         */
160
/*                                                                        */
161
/**************************************************************************/
162
UINT  _uxe_host_class_hid_periodic_report_start(UX_HOST_CLASS_HID *hid)
163
{
164
165
    /* Sanity check.  */
166
    if (hid == UX_NULL)
167
        return(UX_INVALID_PARAMETER);
168
169
    /* Invoke periodic start function.  */
170
    return(_ux_host_class_hid_periodic_report_start(hid));
171
}