[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ok, anyone started Contiki 4 AII yet?



On Tue, 18 Mar 2003 19:20:04 +0100, Ullrich von Bassewitz wrote:
> Rob <rsteinmetz@mindspring.com> wrote:
>> CLK_TCK is defined in time.h. There is no definition for apple2. You
>> could "spoof" it to see what happens next.
> 
> The sources will compile but won't link. The problem is not CLK_TCK, but
> the missing clock() function. clock() returns a 32 bit value (as
> implemented in cc65) that represents the CPU time used since some
> arbitrary point of time. CLK_TCK (or better CLOCKS_PER_SEC which is the
> corresponding ISO C constant) tells how many of the clock ticks make one
> second. Since most 6502 machines don't do multitasking, CPU time and real
> time is identical.
> 
> Contiki uses clock() and CLK_TCK to implement timers. For example the TCP
> stack needs timers to keep track of connection timeouts, packet retransmit
> timeouts and so on. Without having a function that is able to measure time
> in some way or the other, there is no way to implement a TCP stack.

The nice thing is that the time measurements does not have to be very
precise. Contiki calls the clock() function as part of the idle time
processing loop (which also check the keyboard for input and any
network devices for incoming data), and I wouldn't be surprised if it
would be enough for Contiki to let clock() return a 32-bit integer
that would be incremented by 1 for every call to clock(). I.e.,
something like this:

unsigned long
clock(void) {
  static unsigned long counter;

  return ++counter;
}

CLK_TCK would then have to be tuned to a value that roughly
corresponds to one second. Of course, this timer would drift a lot
when there is activity going on, but it might be good enough for the
TCP timers.

/adam
-- 
Adam Dunkels - http://dunkels.com/adam/