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 /**   Device Stack                                                        */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_device_stack.h"
29 
30 
31 #if defined(UX_DEVICE_STANDALONE)
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                                 RELEASE      */
35 /*                                                                        */
36 /*    _ux_device_stack_tasks_run                            PORTABLE C    */
37 /*                                                             6.1.10     */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function runs device stack and registered classes tasks.       */
45 /*                                                                        */
46 /*    It's for standalone mode.                                           */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    UX_STATE_RESET                        Tasks suspended               */
54 /*    UX_STATE_IDLE                         Activated but no task ran     */
55 /*    (others > UX_STATE_IDLE)              Tasks running                 */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    (ux_slave_dcd_function)               run DCD function              */
60 /*    (ux_slave_class_task_function)        run Class tasks function      */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application                                                         */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  01-31-2022     Chaoqiong Xiao           Initial Version 6.1.10        */
71 /*                                                                        */
72 /**************************************************************************/
_ux_device_stack_tasks_run(VOID)73 UINT  _ux_device_stack_tasks_run(VOID)
74 {
75 
76 UX_SLAVE_DCD                *dcd;
77 UX_SLAVE_CLASS              *class_instance;
78 ULONG                       class_index;
79 UINT                        status;
80 
81 
82     status = UX_STATE_RESET;
83 
84     /* Run all DCD tasks (pending ISR handle).  */
85     dcd = &_ux_system_slave -> ux_system_slave_dcd;
86     dcd -> ux_slave_dcd_function(dcd, UX_DCD_TASKS_RUN, UX_NULL);
87 
88     /* Run all Class instance tasks.  */
89     class_instance =  _ux_system_slave -> ux_system_slave_class_array;
90     for (class_index = 0; class_index < UX_SYSTEM_DEVICE_MAX_CLASS_GET(); class_index++)
91     {
92 
93         /* Skip classes not used.  */
94         if (class_instance -> ux_slave_class_status == UX_UNUSED)
95             continue;
96 
97         /* Skip classes has no task function.  */
98         if (class_instance -> ux_slave_class_task_function == UX_NULL)
99             continue;
100 
101         /* Invoke task function.  */
102         status |= class_instance -> ux_slave_class_task_function(class_instance -> ux_slave_class_instance);
103 
104         /* Move to the next class.  */
105         class_instance ++;
106     }
107 
108     /* Return overall status.  */
109     return(status);
110 }
111 #endif
112