]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/standalone_v6_6/src/usleep.c
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / standalone_v6_6 / src / usleep.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2014 - 2017 Xilinx, Inc. All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file usleep.c
36 *
37 * This function supports user configurable sleep implementation.
38 * This provides a microsecond delay using the timer specified by the user in
39 * the ARM Cortex R5 MP core.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who      Date     Changes
45 * ----- -------- -------- -----------------------------------------------
46 * 5.00  pkp      02/20/14 First release
47 * 5.04  pkp              02/19/16 usleep routine is modified to use TTC3 if present
48 *                                                 else it will use set of assembly instructions to
49 *                                                 provide the required delay
50 * 5.04  pkp              03/09/16 Assembly routine for usleep is modified to avoid
51 *                                                 disabling the interrupt
52 * 5.04  pkp              03/11/16 Compare the counter value to previously read value
53 *                                                 to detect the overflow for TTC3
54 * 6.0   asa      08/15/16 Updated the usleep signature. Fix for CR#956899.
55 * 6.6   srm      10/18/17 Updated sleep routines to support user configurable
56 *                         implementation. Now sleep routines will use TTC
57 *                         instance specified by user.
58 *
59 * </pre>
60 *
61 ******************************************************************************/
62 /***************************** Include Files *********************************/
63
64 #include "sleep.h"
65 #include "xtime_l.h"
66 #include "xparameters.h"
67 #include "xil_types.h"
68 #include "xpseudo_asm.h"
69 #include "xreg_cortexr5.h"
70
71 #if defined (SLEEP_TIMER_BASEADDR)
72 #include "xil_sleeptimer.h"
73 #endif
74
75 /*****************************************************************************/
76 /**
77 *
78 * This API gives a delay in microseconds
79 *
80 * @param        useconds requested
81 *
82 * @return       0 always
83 *
84 * @note         By default, usleep is implemented using TTC3. Although user is
85 *               given an option to select other instances of TTC. When the user
86 *               selects other instances of TTC, usleep is implemented by that
87 *               specific TTC instance. If the user didn't select any other instance
88 *               of TTC specifically and when TTC3 is absent, usleep is implemented
89 *               using assembly instructions which is tested with instruction and
90 *               data caches enabled and it gives proper delay. It may give more
91 *               delay than exepcted when caches are disabled. If interrupt comes
92 *               when usleep using assembly instruction is being executed, the delay
93 *               may be greater than what is expected since once the interrupt is
94 *               served count resumes from where it was interrupted unlike the case
95 *               of TTC3 where counter keeps running while interrupt is being served.
96 *
97 ****************************************************************************/
98
99 int usleep_R5(unsigned long useconds)
100 {
101 #if defined (SLEEP_TIMER_BASEADDR)
102         Xil_SleepTTCCommon(useconds, COUNTS_PER_USECOND);
103 #else
104 #if defined (__GNUC__)
105         __asm__ __volatile__ (
106 #elif defined (__ICCARM__)
107         __asm volatile (
108 #endif
109                 "push {r0,r1,r3} \n"
110                 "mov r0, %[usec] \n"
111                 "mov r1, %[iter] \n"
112                 "1: \n"
113                 "mov r3, r1 \n"
114                 "2: \n"
115                 "subs r3, r3, #0x1\n"
116                 "bne 2b \n"
117                 "subs r0, r0, #0x1 \n"
118                 "bne 1b \n"
119                 "pop {r0,r1,r3} \n"
120                 ::[iter] "r" (ITERS_PER_USEC), [usec] "r" (useconds)
121                 );
122 #endif
123
124 return 0;
125 }