I’m the developper of a so-called brushless gimbal controller (STorM32: http://www.rcgroups.com/forums/showthread.php?t=2055844) and the code has become quite complex, so I want to use a RTOS. I think I’m OK at coding, but have not yet any experience with a RTOS. I’ve digested all the docu on the FreeRTOS web site, and also peeked a bit into the code, but some - probably very basic - questions remained, which I’d like to ask.
Some prelim info: I’m using a STM32F103 @ 72MHz, arm-gcc, and CMSIS, I’m not using Cube. The code can be regarded as to consist of two “tasks”, one is a control loop executed every 1500 us triggered by the SysTick timer interrupt, and the second is everything else and not time critical. And that’s exactly how I’d like to do it, to start two tasks with high and low priorities. The control loop consumes about 700-1100 us.
My problem, the control loop has some “time gaps”. For instance, it starts with triggering some sensors and doing a bit of stuff, but then there is a time gap of about 100 us where it’s just waiting for data to arrive. My question(s) will be about how to deal with that using FreeRTOS.
I think the obvious answer of you will be that one just needs to suspend/block the control task and should modify the sensor reading routines such that the control task is resumed. However, for reasons which I feel would require too much space to explain and which I’d like to ask you to just accept, that’s not easily possible and I’m looking for alternatives.
My first thought was to simply use the preemptive scheduler, give the control task a high priority, set the scheduling at 1500 us, and use e.g. vTaskDelay() to switch to the low-priority task while in a time gap.
Question: Did I got that correct that one can delay a task only in multiples of the SysTick timer period, and that this approach would thus not help me?
Question: Setting the scheduling time to e.g. 100 us or 50 us would however do what I want, right?
Question: But that would not make much sense in terms of performance, or wouldn’t you be worried much about the overhead due to the frequent task switching? (I’ve read somewhere that it takes about 1 us, so that at 100 us it would be just 1%, not sure if that’s correct though)
If that approach isn’t recommended, I obvioulsy would need a delay routine which allows me to delay for sub-scheduler times. E.g. one could set a timer, suspend, and make the timer interrupt to resume the task.
Question: Is there anything like that already supported in FreeRTOS, e.g. by some sort of macros, templates or demos, which I just have missed to find?
With such a delay routine, one also could consider, I think, to not use the premptive but the cooperative scheduler, which would also frees the SysTick handler from the scheduling. I’m somewhat confused about how the Systick timer is used with the cooperative scheduler.
Question: Could I make FreeRTOS to not grab the SysTick interrupt and attach it’s own handler, so that I would be able to use my old SysTick handler without change, or do I still have to link my handler routine into FreeRTOS’?
Sorry for the long post. And many thanks for FreeRTOS!