EDA365电子工程师网
标题:
nios11中for延时不起作用
[打印本页]
作者:
yuxuejun1123
时间:
2012-8-14 14:17
标题:
nios11中for延时不起作用
今天想测试一下for延时和usleep的区别,结果大吃一惊,发现for延时不起作用。下面贴出测试过程
$ b- a1 Q6 T; {1 W
1.测试环境:nios11.1,优化级别为level3,系统时钟50MHZ
, h- c% L6 ~' c9 ^% B( G
2.测试代码
9 m R# E) z# ^8 L: d4 [4 _
#include <stdio.h>//printf
: s: q7 r) L+ R( X9 T
#include <unistd.h> //usleep
5 U2 i/ D' w3 J" F/ e' U( [
#include <sys/alt_timestamp.h>
/ c7 Q. t5 b$ L: J
#include "system.h"
8 i: \5 d; s2 f' r" V
#include "alt_types.h"
, w' ]* c* j7 c/ f- G) E' C
#include "altera_avalon_pio_regs.h"
$ V1 k9 e* C8 m9 X0 i2 }
int main(void)
) v6 f9 \( p) X4 t+ J+ {5 B$ Z
{
' P) \% p3 j, h9 X
alt_u32 cnt1 = 0;
4 P1 T& I0 y# M0 c4 c' U: X
/**/
: s) e" U* U8 r3 V
alt_u32 t0,t1,t2;
3 U5 s9 P9 Q3 N. U3 i" w. E
alt_timestamp_start();//开始时间戳服务
! z; P1 t$ U8 K
8 g: F4 J: E5 }7 e
t0 = alt_timestamp();//开始测量时间
6 G$ T& `) H6 @+ c/ a& M9 e
usleep(1000*1000);//1ms
: S5 Y! G; c! K" f3 e' c% f$ }
t1 = alt_timestamp();
2 c% [* s- m* E/ e
//20ns*50000=1ms
Z4 ^7 L5 e% Y* D& h9 s+ }2 [
for(cnt1=0;cnt1<500000;cnt1++);//for循环延时
; V5 _) z4 W1 j5 }6 u- B
t2 = alt_timestamp();
6 ]; h( S7 L$ E' m$ M
0 j/ X- f* z9 }: P! \
printf("(t1-t0)=%ld\n",(t1-t0));
: c' B$ i) l7 Y" O k) h/ l1 T
printf("(t2-t1)=%ld\n",(t2-t1));
) F5 n& u9 G+ j' m$ n
printf("\n");
7 x9 P2 ~' _$ @% ^! P3 ^' ?% A
printf("系统时钟频率是 %ld Hz\n", alt_timestamp_freq());
E4 n* u% F- x1 a$ V
return 0;
& e! T5 G7 M) E0 Z% b9 e8 {
}
* W, A& q& p: ~. ?* B
3.测试结果
. B* i1 x) W' t _5 L1 z; q6 r: |
(t1-t0)=48000174
, X/ t9 [/ @6 h$ B! e& b a
(t2-t1)=37
& N. v' ]' I- O1 p# z! S
( w" D& x. u1 q6 O2 p+ P/ R
系统时钟频率是 50000000 Hz
作者:
296222219
时间:
2012-8-16 08:24
学习
欢迎光临 EDA365电子工程师网 (https://bbs.elecnest.cn/)
Powered by Discuz! X3.2