#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <time.h>
typedef unsigned int uint32;
uint32 a;
int main()
{
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
a = (1000000 * start.tv_sec + start.tv_nsec / 1000);
printf( "%u\n", a);
return EXIT_SUCCESS;
}
I created a timer to get the timestamp at any palce, so the above is a free running timer to take the timestamp. I tried to get the output in microseconds and getting the value as : 2847675807 is this right ?? I should get the value in microseconds. I think, getting some bigger values. someone please help me.
typedef unsigned int uint64;
typedef unsigned int uint32;
uint32 a;
uint64 timestamp()
{
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
a = (uint32)(1e6 * start.tv_sec + start.tv_nsec * 1e-3);
printf( "%u\n", a);
return EXIT_SUCCESS;
}
int main()
{
timestamp();
return 1;
}
I modified like above but then also same results like bigger number