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