Author Topic: Sleep  (Read 9446 times)

Offline chronosdino

  • Newbie
  • *
  • Posts: 10
    • View Profile
Sleep
« on: October 13, 2008, 03:37:39 PM »
Hello and first thanks for answering to my old questions.

But one more is coming :D

I try to change my program from Interniche kernel to uTasker kernel.

I use the sleep function a lot of time, and i have understood that it not existe on uTasker.


If i understand well with the monotime, i can launch a function ( task ) in x second.
But in my programme i only want to make my function wait (sleep) for x seconds or milliseconds and another task work in this time, then after this delay, my task work back at the point where the sleep was written.

Is there any easy solution to simulate the same way or must i change all my task code ?



Thanks,
Chronosdino
« Last Edit: October 17, 2008, 01:04:29 PM by chronosdino »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Sleep
« Reply #1 on: October 13, 2008, 04:10:14 PM »
Hi Chronosdino

There are some more posts with some details about this - eg.:
http://www.utasker.com/forum/index.php?topic=160.0

Basically the system is state-event based. Therefore a typical method to do this is something like:

iState = WAIT_1; // set the state of the task to know that it is waiting for a certain event
uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(2*SEC), E_WAIT_1_FINISHED ); // start a timer for the wait delay
return;               // quite the task


Then the task will be woken with the event E_WAIT_1_FINISHED and can then continue based on the fact that the event arrived in the WAIT_1 state.

The following also discussed this technique:
http://www.utasker.com/forum/index.php?topic=59.0

Regards

Mark


Offline chronosdino

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Sleep
« Reply #2 on: October 17, 2008, 09:45:54 AM »
thank you for answering !

but with
uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(2*SEC), E_WAIT_1_FINISHED ); // start a timer for the wait delay

how can i do some ms delay ?

for exemple 5ms or 30ms

Thank you !

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Sleep
« Reply #3 on: October 17, 2008, 03:04:45 PM »
Hi Chronosdino

I recommend using the DMA timers (assuming they are still free in your project) to generate short and highly accurate delays.

See the example of its use in application.h (#define TEST_DMA_TIMER), which requires its support also to be active (SUPPORT_DMA_TIMER in app_hw_m5223x.h)

This will set up an accurate delay (it can be from microsecond to quite long minute delays since the DMA timers are 32 bit in length)

    DMA_TIMER_SETUP dma_timer_setup;                                     // interrupt configuration parameters
    dma_timer_setup.int_type = DMA_TIMER_INTERRUPT;
    dma_timer_setup.int_handler = DMA_timer_int;
    dma_timer_setup.channel = 1;                                         // DMA timer channel 1
    dma_timer_setup.int_priority = DMA_TIMER1_INTERRUPT_PRIORITY;        // define interrupt priority
    dma_timer_setup.mode = (DMA_TIMER_INTERNAL_CLOCK | DMA_TIMER_SINGLE_SHOT_INTERRUPT);
    dma_timer_setup.count_delay = DMA_TIMER_US_DELAY(1,1,6345);          // 6345us delay using no dividers
    fnConfigureInterrupt((void *)&dma_timer_setup);                      // enter interrupt for DMA timer test


When the interrupt fires, it calls DMA_timer_int(), which can be used to wake the task via interrupt event rather than timer event, but the result is effectively the same:

static void DMA_timer_int(void)
{
    fnInterruptMessage(OWN_TASK, E_WAIT_1_FINISHED);
}


Regards

Mark

P.S. It is also possible to use global hardware timers to generate high resolution timer events (not restricted to the TICK resolution as uTaskerMonoTimer is), but I would use the DMA timers in preference unless you have a large number of timers which need to operate in parallel. The Global HW Timers are descried in the following document:
http://www.utasker.com/docs/uTasker/uTaskerTimers.PDF


Offline chronosdino

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Sleep
« Reply #4 on: October 17, 2008, 04:15:06 PM »
Thank you !!

I think that it could work in my project !


So, What about another question ? :)

do you know the time that the http task or the web serveur use to work ?
or
If i have a kind of while(1) task, is it possible to make the web serveur work ?

how many time is during or needing web serveur task ?

with dynamic variable for sure !


i know that it is a very hard question, but it is very important !


Thank you for the time that you take for that

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Sleep
« Reply #5 on: October 18, 2008, 12:38:06 PM »
Hi

A while (1) {} type task has the following form in the uTasker project:
- the task is set to polling mode (UTASKER_GO)
- the content of the corresponding task is the content of the while (1). The while (1) is not set in the task itself but instead is 'created' by the UTASKER_GO state.

See also page 10/11 of the following document for an example: http://www.utasker.com/docs/uTasker/uTaskerV1.3_user_guide.PDF

The task will therefore run as fast as it can but all other tasks will also have the chance to run in each loop.

The web server is not a task in itself. It is called from with the Ethernet task only when Ethernet frames are received, so the web server doesn't actually need any processing power from the system when it is not actually handling a frame. The effect on the web server response time will depend on the content of the polling task - if it is doing little it will hardly effect anything. If it is doing a lot of things it will delay more, but the actual value can only be known when also this work is known. The same is true for the inverse - when the web server is generating dynamic content it has some work to do and so this will tend to slow down the polling rate of the polling task. Whether this is critical depends on the job of the polling task so there is no general measurement possible without knowing all details.

Regards

Mark