Is there a possible Interrupt?

Hi, assuming FreeRTOS runs at a frequency of 1000 Hz (max. recommended) so the shortest possible execution time of a task is 1ms, right?! For example, the code shows two tasks which get executed 1ms each. ~~~ static void taskOne( void *pvParameters ) { for( ;; ) { func_do_something(); vTaskDelay( pdMS_TO_TICKS( 1000UL ) ); } } static void taskTwo( void *pvParameters ) { for( ;; ) { func_do_something(); vTaskDelay( pdMS_TO_TICKS( 1000UL ) ); } } ~~~ Is there any possiblity to interrupt a Task within that 1ms, e.g. by a interrupt service routine or another task, while it get executed? In other words i want to interfere this task when it gets executed.

Is there a possible Interrupt?

assuming FreeRTOS runs at a frequency of 1000 Hz (max. recommended) so the shortest possible execution time of a task is 1ms
A task is often implemented as a for( ;; ) loop. The duration of the loop is by no means depended on ( or limited to ) the rate of the clock tick. But true, in your example, there is a fixed 1-ms delay.
Is there any possibility to interrupt a Task within that 1ms, e.g. by a interrupt service routine or another task, while it get executed? In other words I want to interfere this task when it gets executed.
Sure that is possible. Please look up the following mechanisms: TaskNotify, Queues, Event Groups. Interrupts can not use normal API’s calls, they must use calls that end with FromISR, such as: ~~~ xQueueSendFromISR() xTaskNotifyFromISR() xSemaphoreGiveFromISR() xEventGroupSetBitsFromISR() // less recommended ~~~ If you google for examples of these function calls, things will become clearer. A general introduction to FreeRTOS can be found on freertos.org

Is there a possible Interrupt?

Ok thank you for your reply. My bad that I forgot to mention something. I have the following two tasks. First, taskOne gets executed then taskTwo gets executed for 1ms and so on… ~~~ static void taskOne( void *pvParameters ) { for( ;; ) { func_do_something(); vTaskDelay( pdMS_TO_TICKS( 1000UL ) ); } } static void taskTwo( void *pvParameters ) { for( ;; ) { for(int i =0; i < 9999; i++){ int tmp = i; } } } ~~~ Assuming that I am not allowed to change the code of taskTwo and the 9999 rounds in the inner for loop of taskTwo can be completed within dat 1 ms. Now my question: Can I interrupt that inner loop of 9999 rounds when taskTwo gets executed. (Again I am not allowed to change the Code of taskTwo, FreeRTOS frequency is fixed to 1000 Hz)

Is there a possible Interrupt?

Tasks running will not stop Interrupts from running (unless they are running in a critical section) Interrupts can affect the status of tasks. If preemption is enabled (which is generally assumed with FreeRTOS examples), if a higher priority task gets moved to the Ready state, then taskTwo will move out of the Running state to just Ready, and that higher priority task will start to run.

Is there a possible Interrupt?

Ok but a higher prior task will only get scheduled after a tick occured so the scheduler can check if there is a higher prior taks. Since the frequency is 1000 Hz this will only happen after 1ms, right? So if taskTwo gets executed it can’t be interrupted within that 1ms because the scheduler will check only every 1 ms if there will be another task with a higher priority which needs to be executed. I want to interrupt taskTwo durring its 1 ms execution but I am not sure if that is possible.

Is there a possible Interrupt?

It is possible. Have a look into the comprehensive documentation here chapter Interrupt Management (hint portYIELD_FROM_ISR)

Is there a possible Interrupt?

I looked into the documentation but the problem is that they force the interrupts by the periodic task. As I mentioned before the code in taskTwo is not allowed to be changed but I still want to interrupt the loop in taskTwo. Is that possible without forcing the interrupts from taskTwo ?

Is there a possible Interrupt?

I’m not sure what you mean with ‘they force interrrupts by the periodic task’. However, with preemption enabled the highest prio task will run as soon as it’s moved from blocked to ready state by whatever mechanism. So a taskThree with the highest prio in your system blocking e.g. on a semaphore or a notification will get immediately woken up e.g. by an ISR signalling the correspondong semaphore or notification and runs until blocking again ….

Is there a possible Interrupt?

See in the pcture: 2 – the periodic task prints its first message then forces an interrupt… In the Code of the perodic task they call: ~~~ … vPortGenerateSimulatedInterrupt( mainINTERRUPT_NUMBER ); …. ~~~ But as I said before – my code looks like this: ~~~ static void taskTwo( void pvParameters ) { for( ;; ) { for(int i =0; i < 9999; i++){ int tmp = i; } } } ~~~ And in my szenario I am not allowed to force an interrupt from *taskTwo itself. I am looking for a mechanism to interrupt the loop in taskTwo by another Taks or interrupt from outside. For exmaple, it would be perfect if I can create an periodic interrupt which will interrupt the loop after every 10 loops.

Is there a possible Interrupt?

If the ISR ends with a call to portYIELDFROMISR, (or portENDSWITCHINGISR which calls portYIELDFROMISR) then the schedule is called right at that point (or maybe at the point when the ISR actually ends), this activation of the scheduler will cause taskTwo to be moved from Running and let the higher priority task run. That can be ANY properly written ISR from some action, like a character coming in, or even a hardware timer expiring. If you want to interrupt taskTwo, then the reason has to be because something more important came up and activated a higher priority task.

Is there a possible Interrupt?

Ok thank you. I tried this out with the vApplicationTickHook which gets called within a ISR and interrupts the loop from taskTwo – as you mentioned it. But the distance between the interrupts is to long. So the schedule looks like this: ~~~
loop round 1 loop round 2 loop round … loop round 40000 INTERRUPT loop round 40001 loop round 40002 loop round … loop round 80000 INTERRUPT ~~~
I need a more frequent interrupt between these loops so it would look like this: ~~~
loop round 1 loop round 2 INTERRUPT loop round 3 loop round 4 INTERRUPT loop round 3 ~~~
How do I trigger a ISR that often? vApplicationTickHook only gets triggered every 1 ms since the frequency is 1000 Hz 🙁

Is there a possible Interrupt?

Sure, as the name and the documentation tells vApplicationTickHook hooks the application resp. SysTick. Seems you’ve to find an interrupt source you can setup according to your needs (for instance a HW timer provided by many MCUs) and use it.

Is there a possible Interrupt?

vApplicationTickHook by definition happens once every tick. Other ISRs happen as often as the harware behind that ISR needs it. In general, the software doesn’t really control when hardware interrupts happen, it is the hardware that does. The software only enables the interrupt to let the hardware know it is ready, and starts the hardware action that cause it. This means that interrupts won’t be on nice loop boundries. For instance, a typical serial port will generate an interrupt when a character comes in, or when it is ready to send another character out. If you really need an interrupt periodically faster than the tick interrupt, many chips have hardware timers that can generate periodic interrupts. Perhaps you need to explain WHY you need to interrupt the task more often. FreeRTOS, if you have configured it right, is generally pretty good at running what needs to get run when it need to be run. You generally don’t need to ‘interrupt’ something just for the sake of interrupting it, but have something come up that needs servicing quickly, so when the interrupt occurs that tells you it needs servicing, that interrupt can initiate the task switch.

Is there a possible Interrupt?

I am interested in this szenario because this is relevant for me in a security related question. So I don’t “need” it – I was asking if this is in anyway possible. As it looks like, it is only partly possible to interrupt a task durring its execution time. To sum it up, a task can be interrupted when 1) an interrupt by a tick happens (which is at 1000 Hz every 1 ms and ) 2) if another ISR occurs (which is hardly to trigger with a high frequency, e.g. every micro second) If you still have any idea how to interrupt taskTwo , howsoever, let me know. Thank you all!

Is there a possible Interrupt?

A task can have its execution intererupted by just two types of things: 1) It can make a system call which causes FreeRTOS to decide to run some other task 2) A hardware interrupt occurs for some reason. (And the task hasn’t disabled interrupts) Interrupts can occur for many reasons, and can happen at all sorts of rates. It is actually fairly easy on most processors to setup an interrupt to occur every microsecond, most hardware timers are able to do that, you need to have a reasonably fast processor if you want to try to get anything done on a processor that has been setup that way.