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 #if defined(UX_HOST_STANDALONE)
34 
35 
36 static inline VOID _ux_host_class_hid_inst_tasks_run(UX_HOST_CLASS_HID *hid);
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  FUNCTION                                               RELEASE        */
41 /*                                                                        */
42 /*    _ux_host_class_hid_tasks_run                        PORTABLE C      */
43 /*                                                           6.1.10       */
44 /*  AUTHOR                                                                */
45 /*                                                                        */
46 /*    Chaoqiong Xiao, Microsoft Corporation                               */
47 /*                                                                        */
48 /*  DESCRIPTION                                                           */
49 /*                                                                        */
50 /*    This function runs HID background tasks.                            */
51 /*                                                                        */
52 /*    This function is for standalone mode.                               */
53 /*                                                                        */
54 /*  INPUT                                                                 */
55 /*                                                                        */
56 /*    hid                                       Pointer to hid instance   */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    None                                                                */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    (ux_host_class_hid_client_function)   Client task function          */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    USBX Host Stack                                                     */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  01-31-2022     Chaoqiong Xiao           Initial Version 6.1.10        */
75 /*                                                                        */
76 /**************************************************************************/
_ux_host_class_hid_tasks_run(UX_HOST_CLASS * hid_class)77 UINT  _ux_host_class_hid_tasks_run(UX_HOST_CLASS *hid_class)
78 {
79 UX_HOST_CLASS_HID           *hid;
80 
81     /* Validate class entry.  */
82     if (hid_class -> ux_host_class_status != UX_USED ||
83         hid_class -> ux_host_class_entry_function != _ux_host_class_hid_entry)
84         return(UX_STATE_IDLE);
85 
86     /* Run for class instances.  */
87     hid = (UX_HOST_CLASS_HID *)hid_class -> ux_host_class_first_instance;
88     while(hid)
89     {
90 
91         /* Run tasks for each hid instance.  */
92         if ((hid -> ux_host_class_hid_flags & UX_HOST_CLASS_HID_FLAG_PROTECT) == 0)
93         {
94             hid -> ux_host_class_hid_flags |= UX_HOST_CLASS_HID_FLAG_PROTECT;
95             _ux_host_class_hid_inst_tasks_run(hid);
96             hid -> ux_host_class_hid_flags &= ~UX_HOST_CLASS_HID_FLAG_PROTECT;
97         }
98         hid = hid -> ux_host_class_hid_next_instance;
99     }
100     return(UX_STATE_WAIT);
101 }
102 
_ux_host_class_hid_inst_tasks_run(UX_HOST_CLASS_HID * hid)103 static inline VOID _ux_host_class_hid_inst_tasks_run(UX_HOST_CLASS_HID *hid)
104 {
105 UX_HOST_CLASS_HID_CLIENT        *client = hid -> ux_host_class_hid_client;
106     if (client && client -> ux_host_class_hid_client_function)
107     {
108         client -> ux_host_class_hid_client_function(client);
109     }
110 }
111 #endif
112