I am using FreeRTOS version 8.1.2 on Realtek Ameba board. I have written a code where I am using
xSemaphoreTake() without creating the semaphore.
I want to know what can be the issue of calling these functions without creating a semaphore.
Very often you will find out that FreeRTOS is lean: in many cases it assumes that parameters have been checked by you.
xSemaphoreTake() must be called with a valid semaphore handle.
If you want to let a task just block, you can use e.g.
Thanks for your reply @Hein Tibosch.
I am not looking for Delaying and blocking a task.
I just want to know the pitfalls, can it cause a hardfalut or crash if
xSemaphoreTake() is called without creating a semaphore?
Yes, calling any FreeRTOS function with an uninitialize handle has put your proogram into an undefined state and virtually anything can happen. If you are lucky, the call will fault and crash.
My general policy is to create ALL of my Queue, Semaphore and Mutexes that the program will need prior to starting the scheduler, so that it makes it much harder to have that problem.
An alternative is to make sure the handles are zeroed at startup and check the handle prior to making the call, skipping the call or creating the item if it is zero.
Very often you will find out that FreeRTOS is lean: in many cases it
assumes that parameters have been checked by you.
FreeRTOS is designed to keep the code size down. While you are
developing checking is performed using configASSERT() (although it
assumes things are zero’ed out), then when your code is ready for
production, you define configASSERT() away and get smaller faster code -
at which point you should make sure all your tests are still working.
SafeRTOS on the other hand has explicit validity checks in C, so
everything is checked, all the time.