PDA

View Full Version : Using the Time functions


jdm2104
02-03-2008, 01:02 PM
Hi,

I would like to use the standard library time function to seed the ClearSpeed vector random number generator. I have included time.h, however, I have a linker error when compiling my code.

Could you tell me what compiler option I should use so time() can be used?

Regards,

David

Dangermouse
02-11-2008, 09:40 AM
Hi jdm2104,

You should get an error when trying to use time() since there is no real-time clock available on the board. You could go via the host to get the current time, however it would be quicker to use get_cycles() to get a random number (unsigned int). The cycle count is a mono value and is not reset under normal circumstances.

Regards,
DM.

Solomon
02-11-2008, 05:52 PM
Just to clarify what DangerMouse wrote.

The ClearSpeed hardware has a hardware counter that increments every cycle (This is 210MHz on their current products).
You can read this integer with get_cycles() - or better get_cycles_ila(). The former is a function call - so has more overhead than the latter which is compiled inline.

You can then convert this into milliseconds or whatever.

However I prefer to keep it as an unsigned integer and so subtract it from a later call to get_cycles_ila(). This stops you getting a large negative time if you are unlucky enough to have the hardware timer wrap round to zero during your timed section.

I would agree that having a working time() or better gettimeofday() would be quite useful for ClearSpeed to implement in the future.

p.s. if you say you get a linker error- it would have been good to have posted the actual commadn line and error message if you wanted others to try and help you!

Solomon

Solomon
02-11-2008, 05:54 PM
Dear jdm2104,

I just spotted that this was your first posting.

Welcome to the list !

Feel free to post any more queries - I am sure there are plenty of people out there who would be more than happy to help.

S.