【发布时间】:2014-05-14 10:55:44
【问题描述】:
a.c:
#include "a.h"
double GetTimeStamp()
{
struct timespec start;
if((clock_gettime( CLOCK_REALTIME, &start)) == -1 )
{
perror("clock gettime\n");
}
/* I am calculating the Clock granularity here the granularity is basically how long that timer interrupt
* will last while it's processing the background task.*/
//micro seconds output
return (1e3 * start.tv_sec + start.tv_nsec * 1e-3);
}
int a()
{
intr_rx_time = GetTimeStamp();
IPLatency = intr_rx_time;
}
a.h:
a();
double intr_rx_time, IPLatency;
b.c:
#include "a.h"
extern double IPLatency;
uint32 ipLatency;
int main()
{
ipLatency = (uint32)IPLatency;
printf("Current IP Latency microseconds: %ld\n", ipLatency);
}
在上面:我正在计算来自 a.c 程序的时间戳。稍后我正在读取 b.c 程序中的计算时间戳值,如上所示。但是我在 b.c 程序中将输出设为 0。上述程序中的错误是什么?有人可以帮忙吗?
【问题讨论】:
标签: c linux timer timestamp qnx