Path: blob/master/arch/microblaze/include/asm/delay.h
15126 views
/*1* include/asm-microblaze/delay.h2*3* This file is subject to the terms and conditions of the GNU General Public4* License. See the file "COPYING" in the main directory of this archive5* for more details.6*7* Copyright (C) 2008 Michal Simek8* Copyright (C) 2007 John Williams9* Copyright (C) 2006 Atmark Techno, Inc.10*/1112#ifndef _ASM_MICROBLAZE_DELAY_H13#define _ASM_MICROBLAZE_DELAY_H1415extern inline void __delay(unsigned long loops)16{17asm volatile ("# __delay \n\t" \18"1: addi %0, %0, -1\t\n" \19"bneid %0, 1b \t\n" \20"nop \t\n"21: "=r" (loops)22: "0" (loops));23}2425/*26* Note that 19 * 226 == 4294 ==~ 2^32 / 10^6, so27* loops = (4294 * usecs * loops_per_jiffy * HZ) / 2^32.28*29* The mul instruction gives us loops = (a * b) / 2^32.30* We choose a = usecs * 19 * HZ and b = loops_per_jiffy * 22631* because this lets us support a wide range of HZ and32* loops_per_jiffy values without either a or b overflowing 2^32.33* Thus we need usecs * HZ <= (2^32 - 1) / 19 = 226050910 and34* loops_per_jiffy <= (2^32 - 1) / 226 = 1900428035* (which corresponds to ~3800 bogomips at HZ = 100).36* -- paulus37*/38#define __MAX_UDELAY (226050910UL/HZ) /* maximum udelay argument */39#define __MAX_NDELAY (4294967295UL/HZ) /* maximum ndelay argument */4041extern unsigned long loops_per_jiffy;4243extern inline void __udelay(unsigned int x)44{4546unsigned long long tmp =47(unsigned long long)x * (unsigned long long)loops_per_jiffy \48* 226LL;49unsigned loops = tmp >> 32;5051/*52__asm__("mulxuu %0,%1,%2" : "=r" (loops) :53"r" (x), "r" (loops_per_jiffy * 226));54*/55__delay(loops);56}5758extern void __bad_udelay(void); /* deliberately undefined */59extern void __bad_ndelay(void); /* deliberately undefined */6061#define udelay(n) (__builtin_constant_p(n) ? \62((n) > __MAX_UDELAY ? __bad_udelay() : __udelay((n) * (19 * HZ))) : \63__udelay((n) * (19 * HZ)))6465#define ndelay(n) (__builtin_constant_p(n) ? \66((n) > __MAX_NDELAY ? __bad_ndelay() : __udelay((n) * HZ)) : \67__udelay((n) * HZ))6869#define muldiv(a, b, c) (((a)*(b))/(c))7071#endif /* _ASM_MICROBLAZE_DELAY_H */727374