valeriv wrote on Monday, December 11, 2017:
Hello all
I need your advices and opinion about IPC.
The project run on STM32, in IAR with FreeRTOS.
I have 2 tasks (there are a lot of tasks in the project but I speak about two) : ModbusMasterTask with priority 5 and IOTask with priority 7.
When IO task want to get any information from modbus, it connect TransmitCallbackFunction to modbusMasterObject and wait for message on xQueueReceive method from modbusMasterTask.
IOTask:
ReadInputRegisters:
SetTransmitCallbackFunction
if xQueueReceive
return true;
return false;
Delay(30)
ModbusMasterTask a little more complicated : it checks TransmitCallbackFunction if it is NULL task does nothing.
IF ( NULL != TransmitCallbackFunction )
{
EnterCriticalSection;
Send request
Get answer from slave
SetTransmitCallbackFunction to NULL
xQueueSend transmitEndMessage to IOTask
ExitCriticalSection
}
Delay(30)
So, here is the FIRST question: It works good but I don’t understand how it works. The priority of the IOTask higher than ModbusMasterTask and I think that on xQueueSend OS immediately try to make run IOTask but it cann’t because the code in critical section. Probably after ExitCriticalSection OS make run IOTask ???
AM I RIGHT ?
And now I need change existing code. Actually ModbusMasterTask always knows about start and end of transmission, so it doesn’t need to run always, but IOTask can trigger it and after ModbusMasterTask GetsAnswer from slave it can go to blocking state. I tryed to do this with Notify functions and BinarySemaphore, but it doesn’t work and I think that it is because of critical section.
So, my pseudocode is
IOTask:
ReadInputRegisters:
SetTransmitCallbackFunction
xSemaphoreGive – new row PROBLEM !!!
if xQueueReceive
return true;
return false;
Delay(30)
ModbusMasterTask:
EnterCriticalSection;
Send request
Get answer from slave
SetTransmitCallbackFunction to NULL
xQueueSend transmitEndMessage to IOTask
xSemaphoreTake with MAX DELAY – new row PROBLEM !!!
ExitCriticalSection
NO DELAY – PROBLEM !!!
It is the SECOND question- problem
Both of tasks enters there loops several times and stuck on ModbusMasterTask forever.
Please help me to resolve this problem
Thanks a lot for your time and consideration
Valerie