4,465
社区成员




//在驱动nandflash驱动中或其它驱动中:
static int __init era_nand_init(void)
{
struct nand_chip *this;
int retval;
udelay(1);//这里将变的很慢(纠正:上面多了个s)
ndelay(1); //照样慢(纠正:上面多了个s)
...
}
#include <linux/module.h>
#include <linux/param.h>
#include <linux/smp.h>
#include <asm/compiler.h>
#include <asm/war.h>
inline void __delay(unsigned int loops)
{
__asm__ __volatile__ (
" .set noreorder \n"
" .align 3 \n"
"1: bnez %0, 1b \n"
" subu %0, 1 \n"
" .set reorder \n"
: "=r" (loops)
: "0" (loops));
}
EXPORT_SYMBOL(__delay);
/*
* Division by multiplication: you don't have to worry about
* loss of precision.
*
* Use only for very small delays ( < 1 msec). Should probably use a
* lookup table, really, as the multiplications take much too long with
* short delays. This is a "reasonable" implementation, though (and the
* first constant multiplications gets optimized away if the delay is
* a constant)
*/
void __udelay(unsigned long us)
{
unsigned int lpj = current_cpu_data.udelay_val;
__delay((us * 0x000010c7 * HZ * lpj) >> 32);
}
EXPORT_SYMBOL(__udelay);
void __ndelay(unsigned long ns)
{
unsigned int lpj = current_cpu_data.udelay_val;
__delay((ns * 0x00000005 * HZ * lpj) >> 32);
}
EXPORT_SYMBOL(__ndelay);
init\main.c
main()
{
...
calibrate_delay();
udelay(1); //这里调用正常
ndelay(1); //正常
...
}
在驱动nandflash驱动中或其它驱动中:
static int __init era_nand_init(void)
{
struct nand_chip *this;
int retval;
udelays(1);//这里将变的很慢
ndelays(1); //照样慢
...