xTaskResumeAll() not inside a task
Is it safe to call xTaskResumeAll outside of a task? The reason I ask is I’m getting “strange” issues when I create a semaphore outside of task and because I’m using heap_3.c which just wraps malloc in vTaskSuspendAll and xTaskResumeAll, it is this call that causes the problems.
If I implement my own calls to malloc, it all works fine and if I just call vTaskSuspendAll it works (which I’d expect as this is just a counter increment). But as soon as I run xTaskResumeAll my USB CDC stops working, which I haven’t been able to track the exact problem as a lot of it is library code built into the ROM, so I’m struggling to debug it.
The processor is LPC11U68 (cortex M0+).
xTaskResumeAll() not inside a task
Actually I wasn’t calling vTaskStartScheduler, instead I had a for loop to just test the USB CDC. As soon as I switched back to using vTaskStartScheduler all was well again. So even though vTaskResumeAll is still called before vTaskStartScheduler, as long as it’s called my project functions.
If I don’t call vTaskStartScheduler then it looks like I get memory corruption or something similar. Does this make sense?
xTaskResumeAll() not inside a task
Is it safe to call xTaskResumeAll outside of a task?There is only one place the function can be called outside of a task, and that is before the scheduler is started. xTaskResumeAll() is called by some of the functions that create RTOS objects, so while I can’t see any reason to call it directly before the scheduler has started (what is being resumed if no tasks are running?), it is commonly called indirectly (called by other API functions) before the scheduler starts. It can’t be called from an interrupt. Only functions that end if ‘FromISR’ can be called from an interrupt.
If I implement my own calls to malloc, it all works fine and if I just call vTaskSuspendAll it works (which I’d expect as this is just a counter increment). But as soon as I run xTaskResumeAll my USB CDC stops working, which I haven’t been able to track the exact problem as a lot of it is library code built into the ROM, so I’m struggling to debug it.Right. That is because calling API functions before the scheduler has been started will leave interrupts disabled. That is deliberate and to stop interrupt handlers trying to use the RTOS API before the scheduler has started (which in the early days was the cause of a LOT of support requests).
xTaskResumeAll() not inside a task
xTaskResumeAll() not inside a task
Yes I have some drivers that create sempahores before their tasks are created, which is called before the scheduler starts. Because I’m using heap_3.c this calls xTaskResumeAll for me, so I was calling it myself to being with.
Ah that’s why, interrupts are left disabled. So I should be able to initialise the CDC inside a task and it all work correctly. Thanks for getting back to me. I kept replyinh below as it didn’t refresh with this reply!