How to control time-dependent tasks

How do you implement the following scenario typically with FreeRTOS? Example: Task1: priority 2, should run every 10 minutes for max. 2 minutes, then suspend Task2: priority 2, should run every day at 12.00, then suspend I think I need a third (management-)task with a higher priority to control periodically the current time and resume/suspend the first two tasks, or is there another better design suggestion/approach? I do not want complete solutions only food for thought! 😉 Thanks!

How to control time-dependent tasks

The tasks can do the every so often themselves by using vTaskDelay/vTaskDelayUntil to wait for their next activation time (you will need something that gives you absolute time for #2, and likely 32 bit ticks if you don’t want task 2 to need to wait up momentarily to see that it needs to go back to sleep for a while, unless your tick rate is slower the once a second (at 1 Hz, the max delay with 16 bit ticks is about 18 hours, and the tick rate is likely higher). Having task 1 suspend after 2 minutes is a strange requirement. With a RTOS, normally a task will do the stuff it needs to do, and then wait until it needs to do it again. For it to abruptly stop (and presumably resume where it stopped 8 minutes later) is a very unusual type of situation. If task 1 is doing lots of small steps, then perhaps it could check an elapsed time after each on to decide if it should do the next or sit and wait. (Again this doesn’t sound very RTOSish, maybe if you start the REAL problem, and not how to implement your solution, we might be able to give better help.)

How to control time-dependent tasks

Agree with Richard D, maybe you are better describing the problem to get ideas for solutions. Task 1 can use vTaskDelayUntil() to start ever 10 minutes, and either just look at the time periodically to know when to stop, or it could start a software timer with a 2 minute period when it starts and have the software timer tell it when to stop. To know when 12.00 was you would need a real time clock, or be sent the time from a remote interface. If you have a real time clock then use it to set an alarm at 12.00 and wake task 2 from the alarm handler.