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 /**   Utility                                                             */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /* Include necessary system files.  */
24 
25 #define UX_SOURCE_CODE
26 
27 #include "ux_api.h"
28 
29 
30 #if !defined(UX_STANDALONE)
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_utility_thread_create                           PORTABLE C      */
36 /*                                                           6.1.11       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function creates a thread for USBX.                            */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    thread_ptr                            Thread control block pointer  */
48 /*    name                                  Pointer to thread name string */
49 /*    entry_function                        Entry function of the thread  */
50 /*    entry_input                           32-bit input value to thread  */
51 /*    stack_start                           Pointer to start of stack     */
52 /*    stack_size                            Stack size in bytes           */
53 /*    priority                              Priority of thread (0-31)     */
54 /*    preempt_threshold                     Preemption threshold          */
55 /*    time_slice                            Thread time-slice value       */
56 /*    auto_start                            Automatic start selection     */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    Completion Status                                                   */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    tx_thread_create                      ThreadX create thread function*/
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    USBX Components                                                     */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
75 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            used UX prefix to refer to  */
77 /*                                            TX symbols instead of using */
78 /*                                            them directly,              */
79 /*                                            resulting in version 6.1    */
80 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
81 /*                                            off in standalone build,    */
82 /*                                            resulting in version 6.1.11 */
83 /*                                                                        */
84 /**************************************************************************/
_ux_utility_thread_create(UX_THREAD * thread_ptr,CHAR * name,VOID (* entry_function)(ULONG),ULONG entry_input,VOID * stack_start,ULONG stack_size,UINT priority,UINT preempt_threshold,ULONG time_slice,UINT auto_start)85 UINT  _ux_utility_thread_create(UX_THREAD *thread_ptr, CHAR *name,
86                 VOID (*entry_function)(ULONG), ULONG entry_input,
87                 VOID *stack_start, ULONG stack_size,
88                 UINT priority, UINT preempt_threshold,
89                 ULONG time_slice, UINT auto_start)
90 {
91 
92 UINT    status;
93 
94 
95     /* Call ThreadX to create USBX thread.  */
96     status =  tx_thread_create(thread_ptr,name,entry_function,entry_input,
97                     stack_start,stack_size, priority,preempt_threshold,time_slice,auto_start);
98 
99     /* Check for status.  */
100     if (status != UX_SUCCESS)
101     {
102 
103         /* Error trap. */
104         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_UTILITY, status);
105 
106         /* If trace is enabled, insert this event into the trace buffer.  */
107         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_THREAD_ERROR, thread_ptr, 0, 0, UX_TRACE_ERRORS, 0, 0)
108 
109     }
110     /* Return completion status.  */
111     return(status);
112 }
113 #endif
114