|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
今天想测试一下for延时和usleep的区别,结果大吃一惊,发现for延时不起作用。下面贴出测试过程
& m9 U8 `+ T. \5 A1.测试环境:nios11.1,优化级别为level3,系统时钟50MHZ
8 p$ }% p. t. g# l, D! H: H+ l2.测试代码$ L/ N6 ^1 X4 l- N
#include <stdio.h>//printf) N: w5 k; B* w3 m, c6 O3 _+ ?
#include <unistd.h> //usleep
8 s( }1 @/ o0 p2 O# F' ]4 T#include <sys/alt_timestamp.h>3 _3 G4 P+ ~/ O' {) R$ j% }
#include "system.h"
{, Q! Z( H1 ^7 s% @#include "alt_types.h"
8 v" D* D/ |" x: P#include "altera_avalon_pio_regs.h"
# ~' s- s$ p: q/ xint main(void)
) Z5 u) V3 O) t+ B; X{
4 B3 N1 n' T8 M+ U alt_u32 cnt1 = 0;/ n0 K: }0 F9 }6 z8 g; ?# h8 k B
/**/
# \2 t- T, G: [7 A* M2 } alt_u32 t0,t1,t2;: ?& H0 J* K0 G
alt_timestamp_start();//开始时间戳服务
- l1 q, ~; J6 Z) E
) Q; P1 b1 m( ?2 J% B/ d4 V. e1 r( q t0 = alt_timestamp();//开始测量时间# y% Q3 P2 I, q# Z: Q- L3 E
usleep(1000*1000);//1ms
3 g0 W% L; _8 y t1 = alt_timestamp();2 q9 D8 D' E0 K W
//20ns*50000=1ms
/ A/ H) S, N# h for(cnt1=0;cnt1<500000;cnt1++);//for循环延时
1 t) P. M) X3 |1 V t2 = alt_timestamp();) S5 N1 o6 N, V' l/ ^- @
* _- i( j; Z5 X! A- _1 { printf("(t1-t0)=%ld\n",(t1-t0));
3 x' @. m' Y- I% D printf("(t2-t1)=%ld\n",(t2-t1));+ ?9 g2 Z' Y& F" d
printf("\n");
. ^& a; o+ B) I& L a" h% D. L printf("系统时钟频率是 %ld Hz\n", alt_timestamp_freq());4 ]5 a+ f1 a! P9 d3 P+ o
return 0;) _6 a- O5 B; C+ q2 r
}! v' M6 ] s8 z9 H( N
3.测试结果+ M3 N( Q5 k! y. y. }
(t1-t0)=48000174
) ~# `$ U$ i8 B' n' Y. y(t2-t1)=37
* P7 i& b. v; x$ c. I3 h( ^
5 w7 o9 b7 Q$ T1 n3 T* g, h) Y系统时钟频率是 50000000 Hz |
|