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 /**   Utility                                                             */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /* Include necessary system files.  */
25 
26 #define UX_SOURCE_CODE
27 
28 #include "ux_api.h"
29 
30 
31 #if !defined(UX_STANDALONE)
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_utility_semaphore_create                        PORTABLE C      */
37 /*                                                           6.1.11       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function creates a semaphore.                                  */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    semaphore                             Semaphore to create           */
49 /*    semaphore_name                        Semaphore name                */
50 /*    initial_count                         Initial semaphore count       */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    tx_semaphore_create                   ThreadX semaphore create      */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    USBX Components                                                     */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
69 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            used UX prefix to refer to  */
71 /*                                            TX symbols instead of using */
72 /*                                            them directly,              */
73 /*                                            resulting in version 6.1    */
74 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            off in standalone build,    */
76 /*                                            resulting in version 6.1.11 */
77 /*                                                                        */
78 /**************************************************************************/
_ux_utility_semaphore_create(UX_SEMAPHORE * semaphore,CHAR * semaphore_name,UINT initial_count)79 UINT  _ux_utility_semaphore_create(UX_SEMAPHORE *semaphore, CHAR *semaphore_name, UINT initial_count)
80 {
81 
82 UINT    status;
83 
84     /* Call ThreadX to create the semaphore.  */
85     status =  tx_semaphore_create(semaphore, (CHAR *) semaphore_name, initial_count);
86 
87     /* Check for status.  */
88     if (status != UX_SUCCESS)
89     {
90 
91         /* Error trap. */
92         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_UTILITY, status);
93 
94         /* If trace is enabled, insert this event into the trace buffer.  */
95         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_SEMAPHORE_ERROR, semaphore, 0, 0, UX_TRACE_ERRORS, 0, 0)
96 
97     }
98 
99     /* Return completion status.  */
100     return(status);
101 }
102 #endif
103