Forum Discussion

PrakashPrasad's avatar
PrakashPrasad
Icon for New Contributor rankNew Contributor
1 year ago
Solved

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

  • Hi


    From the code it seems correct.

    Going through the the eCOS document, the clock resolution is the same as frequency.

    https://doc.ecoscentric.com/ref/kernel-clocks.html


    The NiosII frequency could be found in the hardware design in the platform designer. You could see what is the clock frequency that is connected to the clock input signal of the NiosII.






2 Replies

  • tehjingy_Altera's avatar
    tehjingy_Altera
    Icon for Regular Contributor rankRegular Contributor

    Hi


    From the code it seems correct.

    Going through the the eCOS document, the clock resolution is the same as frequency.

    https://doc.ecoscentric.com/ref/kernel-clocks.html


    The NiosII frequency could be found in the hardware design in the platform designer. You could see what is the clock frequency that is connected to the clock input signal of the NiosII.






  • tehjingy_Altera's avatar
    tehjingy_Altera
    Icon for Regular Contributor rankRegular Contributor

    Hi


    I’m glad that your question has been addressed, I now transition this thread to community support. If you have a new question, Please login to ‘https://supporttickets.intel.com/s/?language=en_US’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.


    Regards

    Jingyang, Teh