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_semaphore_get PORTABLE C */ |
36 |
|
|
/* 6.1.11 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function gets a semaphore signal. */ |
44 |
|
|
/* */ |
45 |
|
|
/* INPUT */ |
46 |
|
|
/* */ |
47 |
|
|
/* semaphore Semaphore to get signal from */ |
48 |
|
|
/* */ |
49 |
|
|
/* OUTPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* Completion Status */ |
52 |
|
|
/* */ |
53 |
|
|
/* CALLS */ |
54 |
|
|
/* */ |
55 |
|
|
/* tx_thread_identify ThreadX identify thread */ |
56 |
|
|
/* tx_thread_info_get ThreadX get thread info */ |
57 |
|
|
/* tx_semaphore_get ThreadX semaphore get */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLED BY */ |
60 |
|
|
/* */ |
61 |
|
|
/* USBX Components */ |
62 |
|
|
/* */ |
63 |
|
|
/* RELEASE HISTORY */ |
64 |
|
|
/* */ |
65 |
|
|
/* DATE NAME DESCRIPTION */ |
66 |
|
|
/* */ |
67 |
|
|
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ |
68 |
|
|
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ |
69 |
|
|
/* used UX prefix to refer to */ |
70 |
|
|
/* TX symbols instead of using */ |
71 |
|
|
/* them directly, */ |
72 |
|
|
/* resulting in version 6.1 */ |
73 |
|
|
/* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ |
74 |
|
|
/* off in standalone build, */ |
75 |
|
|
/* resulting in version 6.1.11 */ |
76 |
|
|
/* */ |
77 |
|
|
/**************************************************************************/ |
78 |
|
219381 |
UINT _ux_utility_semaphore_get(UX_SEMAPHORE *semaphore, ULONG semaphore_signal) |
79 |
|
|
{ |
80 |
|
|
|
81 |
|
|
UINT status; |
82 |
|
|
UX_THREAD *my_thread; |
83 |
|
|
CHAR *name; |
84 |
|
|
UINT state; |
85 |
|
|
ULONG run_count; |
86 |
|
|
UINT priority; |
87 |
|
|
UINT preemption_threshold; |
88 |
|
|
ULONG time_slice; |
89 |
|
|
UX_THREAD *next_thread; |
90 |
|
|
UX_THREAD *suspended_thread; |
91 |
|
|
|
92 |
|
|
/* Call TX to know my own tread. */ |
93 |
|
219381 |
my_thread = tx_thread_identify(); |
94 |
|
|
|
95 |
|
|
/* Retrieve information about the previously created thread "my_thread." */ |
96 |
|
219381 |
tx_thread_info_get(my_thread, &name, &state, &run_count, |
97 |
|
|
&priority, &preemption_threshold, |
98 |
|
|
&time_slice, &next_thread,&suspended_thread); |
99 |
|
|
|
100 |
|
|
/* Is this the lowest priority thread in the system trying to use TX services ? */ |
101 |
✓✓ |
219381 |
if (priority > _ux_system -> ux_system_thread_lowest_priority) |
102 |
|
|
{ |
103 |
|
|
|
104 |
|
|
/* We need to remember this thread priority. */ |
105 |
|
665 |
_ux_system -> ux_system_thread_lowest_priority = priority; |
106 |
|
|
|
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
/* Get ThreadX semaphore instance. */ |
110 |
|
219381 |
status = tx_semaphore_get(semaphore, semaphore_signal); |
111 |
|
|
|
112 |
|
|
/* Return completion status. */ |
113 |
|
218396 |
return(status); |
114 |
|
|
} |
115 |
|
|
#endif |