Skip to content

Commit

Permalink
Clock seconds since startup on minimal-net
Browse files Browse the repository at this point in the history
  • Loading branch information
dak664 committed Jul 24, 2011
1 parent 0bb585f commit 05c11d3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions platform/minimal-net/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
#include "sys/clock.h"
#include <sys/time.h>

static long startsecs=0,startmsecs=0;
/*---------------------------------------------------------------------------*/
void
clock_init(void)
{
struct timeval tv;
gettimeofday(&tv, NULL) ;
startmsecs=tv.tv_usec/1000;
startsecs=tv.tv_sec;
}
/*---------------------------------------------------------------------------*/
clock_time_t
clock_time(void)
Expand All @@ -56,13 +66,27 @@ clock_time(void)
unsigned long
clock_seconds(void)
{
/* Returne seconds since startup */
long secs,msecs;
struct timeval tv;
gettimeofday(&tv, NULL) ;
msecs=tv.tv_usec/1000;
secs=tv.tv_sec;
secs -=startsecs;
msecs-=startmsecs;
if (msecs<0) secs--;
return secs;
}
#if 0
/* Return seconds since midnight*/
struct timeval tv;
struct timezone tz;

gettimeofday(&tv, &tz);

return tv.tv_sec;
}
#endif
/*---------------------------------------------------------------------------*/
void
clock_delay(unsigned int d)
Expand Down
3 changes: 3 additions & 0 deletions platform/minimal-net/contiki-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ sprint_ip6(uip_ip6addr_t addr)
int
main(void)
{
clock_init();
#if UIP_CONF_IPV6
/* A hard coded address overrides the stack default MAC address to allow multiple instances.
* uip6.c defines it as {0x00,0x06,0x98,0x00,0x02,0x32} giving an ipv6 address of [fe80::206:98ff:fe00:232]
Expand Down Expand Up @@ -265,6 +266,8 @@ main(void)
/* Make standard output unbuffered. */
setvbuf(stdout, (char *)NULL, _IONBF, 0);

printf("\n*******%s online*******\n",CONTIKI_VERSION_STRING);

while(1) {
fd_set fds;
int n;
Expand Down

0 comments on commit 05c11d3

Please sign in to comment.