FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [November 2013 Threads] vTaskDelayUntil() Posted by amarjith on November 1, 2013 Please help me I'm not much familiar with rtos I have a doubt in vTaskDelayUntil(), it used to implement a task that executes periodically and with a fixed frequency. My doubt is if i want to execute five different tasks in every 5 seconds using vTaskDelayUntil() as shown below
vTaskDelayUntil( &xLastWakeTimeLog, 5000 / portTICKRATEMS ) );
I calld this in five different tasks and my configTICKRATEHZ is 100. My single task will take 3 seconds to complete its process.Then how will it execute the code??
vTaskDelayUntil() Posted by davedoors on November 1, 2013 It depends on the priorities you assign to the tasks.
If the task that takes 3 seconds to complete has a priority above the other tasks then the other tasks will not run until it completes.
If the task that takes 3 seconds to complete has a priority below the other tasks then it will get preempted as soon as the other tasks need to run.
If all the tasks have the same priority then they will time slice and it will probably appear that all the tasks run just when they want to.
vTaskDelayUntil() Posted by amarjith on November 2, 2013 Thank you for reply. So if i want to execute five different tasks in every 5 seconds i have to set same priority for all my tasks right?. if so will it execute in every 5 seconds exactly?
vTaskDelayUntil() Posted by richard_damon on November 2, 2013 No. Using VTaskDelayUntil in the task loop will make that task run as close to that rate as possible. It will only be late if:
1) Some higher or equal priority task is running at the point, in which case the task will be delayed until the higher priority task blocks, or the same priority task blocks or continues for a tick.
2) It takes longer to finish than the repeat period, at which point the vTaskDelay Until doesn't block, but just updates the next execution time an returns.
You mentioned one task taking a long period to execute, If that is compute bound time, then you probably don't want that task higher priority than the others, as it would affect their timing. Long executing tasks (if CPU bound) tend to be lower in priority to avoid them impacting more important quick operations.
vTaskDelayUntil() Posted by amarjith on November 4, 2013 Ok :-). Thank you so much.
vTaskDelayUntil() Posted by amarjith on November 12, 2013 Hello sir, How much is the maximum available delay in vTaskDelayUntil() ? The xTimeIncrement is Short, so i can set only up to 65536( 6.5 seconds) right? If i want a delay more than this what will i do? i set unsigned long xTimeIncrement instead of portTickType xTimeIncrement is this a proper way?. i want to set delay up to 1hr in some tasks.
vTaskDelayUntil() Posted by richardbarry on November 12, 2013 I have no idea what xTimeIncrement is, so the answer to your question is probably "no".
Block times are specified in ticks, so the maximum time you can block for depends on your tick frequency (configTICKRATEHZ in FreeRTOSConfig.h) and the type used for portTickType. If configUSE16BITTICKS is 1 then the maximum block time is 0xffff ticks. If configUSE16BITTICKS is 0 then the maximum block time is 0xffffffff ticks.
If you want to convert milliseconds into ticks then divide it by portTICKRATEMS. For example, of you want to delay for 1000 milliseconds then call vTaskDelay( 1000 / portTICKRATEMS );
When you are blocking on an object such as a queue, semaphore or mutex then you can block indefinitely (without a timeout) if INCLUDEvTaskSuspend is set to 1 in FreeRTOSConfig.h and you set portMAXDELAY as the block time.
Regards.
vTaskDelayUntil() Posted by amarjith on November 12, 2013 xTimeIncrement is in void vTaskDelayUntil() (task.c) shown below
void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement )
i was saying about portTickType before xTimeIncrement, i changed in to unsigned long xTimeIncrement.
vTaskDelayUntil() Posted by richardbarry on November 12, 2013 The only valid way of changing the portTickType value is to use the configUSE16BIT_TICKS setting in FreeRTOSConfig.h, as already described.
Regards.
vTaskDelayUntil() Posted by richard_damon on November 13, 2013 At a 1 ms timer tick, and 16 bit ticks, you get 65.5 seconds as the maximum delay you can request. Timer ticks faster than 1 ms are really impractical, and some of the coding techniques in the examples don't work (as MSPERTICK is 0). In most application you can actually use a slower tick rate. A 10ms tick would allow a delay of 655 seconds, nearly 11 minutes. If you want real long delays, you need to turn off 16 bits as mentioned, then you get VERY long delays (Over a month with 1 ms ticks).
vTaskDelayUntil() Posted by amarjith on November 15, 2013 I'm Still confused!!
Forgive me if i'am doing wrong.i wrote program for delay as shown below, here i can set any delay 20mins, 50mins, 1 or 2 hrs or more. But i didnt change my code as you said.
define configUSE16BIT_TICKS 1
define configTICKRATEHZ ( ( portTickType ) 100 )
define configCPUCLOCKHZ ( ( unsigned long ) 12000000 ) /* Fosc / 2 */
i just changed the function shown below in task.c
void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement )
as
void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, unsigned long xTimeIncrement )
//UploadTimeInterval = 20 // will get 20 mins
xTaskCreate( vMTUpload, "vMTUpload", MEDIUMSTACKSIZE,UploadTimeInterval, 9, &xUploadHandle );
void vMT_Upload( void *pvParameters)
{
unsigned long UploadTime;
portTickType xLastWakeTimeUpload;
UploadTime = ( unsigned long ) pvParameters;
for(; ;)
{
////upload code
xLastWakeTimeUpload = xTaskGetTickCount();
vTaskDelayUntil( &xLastWakeTimeUpload, ((UploadTime*1000) / portTICK_RATE_MS ));
}
}
vTaskDelayUntil() Posted by amarjith on November 27, 2013
vTaskDelayUntil() Posted by richard_damon on November 27, 2013 UploadTime * 1000 / portTICKRATEMS sys UploadTime is in SECONDS, not minutes.
At 100Hz, a 16 bit tick will allow a maximum delay of 655 seconds, i.e. about 11 minutes.
Note that if you have a 16 bit processor, then your calculation will overflow long before the timer call, and this will actually limit your max delay to about 65 seconds.
vTaskDelayUntil() Posted by amarjith on December 1, 2013 Ho!sorry its in seconds. Yes i'm using pic24 microcontroller(16bit) can i set configUSE16BIT_TICKS is 0 in 16 bit controller?
vTaskDelayUntil() Posted by richard_damon on December 1, 2013 Yes, 16 bit processors can set configUSE16BIT_TICKS to 0, and get a 32 bit tick size. There will be slightly extra work done to process ticks as tick arithmetic will use 32 bit longs, which will require twice the instructions to do the math (in most cases), but this is not that big of a hit, especially if you need the long time measurement/delays.
vTaskDelayUntil() Posted by amarjith on December 2, 2013 Okay. Thank you for your valuable time.
vTaskDelayUntil() Posted by dragonflight1 on December 2, 2013 Rather than incur the 32 bit penalty all the time (though it really isn't that much), if you only want to delay a task some long time then you can use
~~~~~~~~~~~~~~~
void sleep( unsigned int sec ) {
long ticks = sec * 1000 * portTICKRATEMS;
while(ticks >= portMAXDELAY ) {
vTaskDelay( portMAXDELAY-1 );
ticks -= portMAX_DELAY-1;
}
vTaskDelay( ticks );
}
~~~~~~~~~~~~~~~
or
~~~~~~~~~~~~~~~
void sleepUntil( portTickType *prevWakeTime, unsigned int sec ) {
long ticks = sec * 1000 * portTICKRATEMS;
while(ticks >= portMAXDELAY ) {
vTaskDelayUntil( prevWakeTime, portMAXDELAY-1 );
ticks -= portMAX_DELAY-1;
}
vTaskDelayUntil( prevWakeTime, ticks );
}
~~~~~~~~
if you really want to wake up exactly every sec seconds.
NOTE: if you use sleepUntil then you must call it before the base timer overflows - 65 secs with 1000Hz or 655 secs with 100Hz which I assume is not an issue.
vTaskDelayUntil() Posted by amarjith on December 6, 2013
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|