1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
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 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
73 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            added standalone support,   */
77 /*                                            resulting in version 6.1.10 */
78 /*                                                                        */
79 /**************************************************************************/
_ux_host_class_hid_periodic_report_start(UX_HOST_CLASS_HID * hid)80 UINT  _ux_host_class_hid_periodic_report_start(UX_HOST_CLASS_HID *hid)
81 {
82 #if defined(UX_HOST_STANDALONE)
83 UX_INTERRUPT_SAVE_AREA
84 #endif
85 UINT            status;
86 UX_TRANSFER     *transfer_request;
87 
88 
89     /* Ensure the instance is valid.  */
90     if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
91     {
92 
93         /* Error trap. */
94         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
95 
96         /* If trace is enabled, insert this event into the trace buffer.  */
97         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
98 
99         return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
100     }
101 
102     /* Protect thread reentry to this instance.  */
103     _ux_host_class_hid_lock_fail_return(hid);
104 
105     /* Check the status of the interrupt endpoint.  */
106     if (hid -> ux_host_class_hid_interrupt_endpoint_status != UX_HOST_CLASS_HID_INTERRUPT_ENDPOINT_READY)
107     {
108 
109         /* Unprotect thread reentry to this instance.  */
110         _ux_host_class_hid_unlock(hid);
111 
112         /* Error trap. */
113         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_PERIODIC_REPORT_ERROR);
114 
115         /* If trace is enabled, insert this event into the trace buffer.  */
116         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_PERIODIC_REPORT_ERROR, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
117 
118         /* Return error status.  */
119         return(UX_HOST_CLASS_HID_PERIODIC_REPORT_ERROR);
120     }
121 
122     /* Get the address of the HID associated with the interrupt endpoint.  */
123     transfer_request =  &hid -> ux_host_class_hid_interrupt_endpoint -> ux_endpoint_transfer_request;
124 
125     /* The transfer on the interrupt endpoint can be started.  */
126     status =  _ux_host_stack_transfer_request(transfer_request);
127 
128     /* Check the status. If no error, adjust the status of the periodic endpoint
129        to active.  */
130     if (status == UX_SUCCESS)
131         hid -> ux_host_class_hid_interrupt_endpoint_status =  UX_HOST_CLASS_HID_INTERRUPT_ENDPOINT_ACTIVE;
132 
133     /* Unprotect thread reentry to this instance.  */
134     _ux_host_class_hid_unlock(hid);
135 
136     /* Return the function status */
137     return(status);
138 }
139