I am using the Linux portable layer of FreeRTOS for my application. Each of the FreeRTOS tasks is created as pthreads. When I am trying to give user input through stdin using scanf() inside such a FreeRTOS task, it does not seem to work. The scanf() always returns -1 and does not wait for user input. How can I get around this?
I tried another workaround. If I created a new pthread from within the FreeRTOS task, scanf() seems to work. How does this work and is it legitimate to create a pthread from within a FreeRTOS task?
Do you mean that you do not use
xTaskCreate to create your tasks? If so, that is not correct and you should use
I also doubt you can have a FreeRTOS task block to wait for user input because FreeRTOS tasks can only block on FreeRTOS primitives known to the scheduler. If the task is blocked waiting for user input it is blocked on a Linux primitive unknown to the FreeRTOS scheduler - so the scheduler doesn’t know the task isn’t running and can’t unblock the task when user input arrives.
No I meant that xTaskCreate creates the task as a pthread in the linux port
@jay505, isn’t it possible to create a network connection (UDP or TCP) in your application? Or use a serial input?
because FreeRTOS tasks can only block on FreeRTOS primitives known to the scheduler
The same can be said about the WinSim ( W32 ) project. It is also based threads, where only one thread can be active at any time.
When a thread calls a blocking API of the OS, the rule might get broken: two threads may become active at the same time, which may lead to crashes.
So even if you get stdin/stdout functions working, you might encounter synchronisation problems
“FreeRTOS primitives” : these are of course API’s like task-notification, queues, mutex, task-delay etc.