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 /** Host Stack */
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 /**************************************************************************/
31 /* */
32 /* FUNCTION RELEASE */
33 /* */
34 /* _ux_utility_delay_ms PORTABLE C */
35 /* 6.1.10 */
36 /* AUTHOR */
37 /* */
38 /* Chaoqiong Xiao, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* This function causes the calling thread to sleep for the */
43 /* specified number of milliseconds */
44 /* */
45 /* INPUT */
46 /* */
47 /* ms_wait Number of milliseconds to */
48 /* wait for */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* None */
53 /* */
54 /* CALLS */
55 /* */
56 /* tx_thread_sleep ThreadX sleep function */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* USBX Components */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
67 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
68 /* resulting in version 6.1 */
69 /* 11-09-2020 Chaoqiong Xiao Modified comment(s), */
70 /* fixed compile warnings 64b, */
71 /* resulting in version 6.1.2 */
72 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
73 /* added standalone support, */
74 /* resulting in version 6.1.10 */
75 /* */
76 /**************************************************************************/
_ux_utility_delay_ms(ULONG ms_wait)77 VOID _ux_utility_delay_ms(ULONG ms_wait)
78 {
79
80 ULONG ticks;
81
82 #if defined(UX_STANDALONE)
83
84 /* Get current time. */
85 ticks = _ux_utility_time_get();
86
87 /* Wait until timeout. */
88 while(_ux_utility_time_elapsed(ticks, _ux_utility_time_get()) <
89 UX_MS_TO_TICK_NON_ZERO(ms_wait));
90 #else
91
92 /* translate ms into ticks. */
93 ticks = (ULONG)(ms_wait * UX_PERIODIC_RATE) / 1000;
94
95 /* For safety add 1 to ticks. */
96 ticks++;
97
98 /* Call ThreadX sleep function. */
99 tx_thread_sleep(ticks);
100 #endif
101
102 /* Return completion status. */
103 return;
104 }
105