OiO.lk Blog C# How to make thread sleep exactly N seconds in NIOS II Altura with eCos RTOS
C#

How to make thread sleep exactly N seconds in NIOS II Altura with eCos RTOS


I was going thru this PDF – https://www.gaisler.com/doc/ecos-ref-a4.pdf

It states at page 48 / 596 – Clocks –

"
The information needed to perform these conversions is the clock resolution. This is a structure with two
fields, a dividend and a divisor, and specifies the number of nanoseconds between clock ticks. For example a clock that runs at 100Hz will have 10 milliseconds between clock ticks, or 10000000 nanoseconds.
The ratio between the resolution’s dividend and divisor will therefore be 10000000 to 1, and typical values
for these might be 1000000000 and 100. If the clock runs at a different frequency, say 60Hz, the numbers
could be 1000000000 and 60 respectively. Given a delay in nanoseconds, this can be converted to clock ticks
by multiplying with the the divisor and then dividing by the dividend. For example a delay of 50 milliseconds corresponds to 50000000 nanoseconds, and with a clock frequency of 100Hz this can be converted to
((50000000 * 100) / 1000000000) = 5 clock ticks"

Given this logic if I want to make a a thread exactly sleep for N seconds is the below code the correct implementation:

#define SEC_TO_NANOSEC_MUL_FACTOR 1000000000

cyg_resolution_t resolution =
cyg_clock_get_resolution(cyg_real_time_clock());
cyg_tick_count_t waitTicks =
(((N * SEC_TO_NANOSEC_MUL_FACTOR) * resolution.divisor) / resolution.dividend);

cyg_thread_delay(waitTicks);

Is the resolution and frequency talked in above context same?
If not then how do we find the frequency set in NIOS II processor?
Any other info is always welcome



You need to sign in to view this answers

Exit mobile version