天嵌 ARM开发社区

 找回密码
 注册
查看: 2398|回复: 4

为何调用udeay没起到延时的效果!!!!

[复制链接]
wind 发表于 2010-7-24 21:13:46 | 显示全部楼层 |阅读模式
麻烦看下程序:我是想验证一下linux下的udelay、mdelay、ndelay的延时时间时候真的是如n(单位)时间所示,但我用下面的程序,通过调用current_kernel_time();读取当前的时间,在delay前后打印出时间多少,但1us、1ms的时间差为何

s3c2410_gpio_cfgpin(S3C2410_GPG14,S3C2410_GPG14_OUTP);
s3c2410_gpio_setpin(S3C2410_GPG14,1);

ntime1=current_kernel_time();
    printk(KERN_INFO"the ntime1.ctn is %ld\n",ntime1.tv_nsec);

udelay(100);  //在终端没有显示延时的时间

ntime2=current_kernel_time();
printk(KERN_INFO"the ntime2.ctn is %ld\n",ntime2.tv_nsec);

s3c2410_gpio_setpin(S3C2410_GPG14,0);
ntime1=current_kernel_time();
    printk(KERN_INFO"the ntime1.ctn is %ld\n",ntime1.tv_nsec);
mdelay(1);
ntime2=current_kernel_time();
printk(KERN_INFO"the ntime2.ctn is %ld\n",ntime2.tv_nsec);

s3c2410_gpio_setpin(S3C2410_GPG14,1);
ntime1=current_kernel_time();
    printk(KERN_INFO"the  time1.ctn is %ld\n",ntime1.tv_sec);
mdelay(1000);
ntime2=current_kernel_time();
printk(KERN_INFO"the  time2.ctn is %ld\n",ntime2.tv_sec);

s3c2410_gpio_setpin(S3C2410_GPG14,0);

为何在终端打印出来的信息udelay没起到延时的效果。

[root@EmbedSky qdts]# ./test
OPEN SUCCESS!
the ntime1.ctn is 262755000
the ntime2.ctn is 262755000
the ntime1.ctn is 262755000
the ntime2.ctn is 262755000
the  time1.ctn is 1630257097
the  time2.ctn is 1630257098
[root@EmbedSky qdts]# ./test
OPEN SUCCESS!
the ntime1.ctn is 902755000
the ntime2.ctn is 902755000
the ntime1.ctn is 902755000
the ntime2.ctn is 902755000
the  time1.ctn is 1630257109
the  time2.ctn is 1630257110
[root@EmbedSky qdts]# ./test
OPEN SUCCESS!
the ntime1.ctn is 102755000
the ntime2.ctn is 102755000
the ntime1.ctn is 102755000
the ntime2.ctn is 102755000
the  time1.ctn is 1630257125
the  time2.ctn is 1630257126
是不是跟打印函数的调用需要时间?还是什么原因
亚瑟王 发表于 2010-7-24 21:42:45 | 显示全部楼层
udelay是微秒级的,而Linux的时间片是10ms的,所以。。。
 楼主| wind 发表于 2010-7-24 23:04:06 | 显示全部楼层
亚瑟王,那如果我要延时20us,我用udelay(20),能不能起到延时效果,我用一个for让他udelay(100)100次有时差10ms,但如果udelay(20)*100次,他显示的是5ms时差。调用这个函数,内核实际上是有延时的吧?
 楼主| wind 发表于 2010-7-24 23:09:18 | 显示全部楼层
udelay(20)*100次=2ms,他显示的是5ms时差。current_kernel_time()跟jiffies分辨率是不是有关,从内核调用printk,耗时要多久
亚瑟王 发表于 2010-8-2 18:42:30 | 显示全部楼层
你用select函数试试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-20 02:36 , Processed in 1.035196 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表