mutty00 wrote on Sunday, August 21, 2016:
Hi,
I’m expecting a little issue using FreeRTOS on my project that uses TCP socket on a SAMW25 system.
Here follows a simplified stub of code I’m using. The first part is the callback function that handle received message interrupt, the second part is the task that manage the received message.
static void socket_cb(SOCKET sock, uint8_t u8Msg, void *pvMsg)
{
switch (u8Msg)
{
/* Message receive */
case SOCKET_MSG_RECV:
{
tstrSocketRecvMsg *pstrRecv = (tstrSocketRecvMsg *)pvMsg;
if (sock==tcp_client_socket)
{
if (pstrRecv && pstrRecv->s16BufferSize > 0)
{
BaseType_t xHigherPriorityTaskWoken=pdFALSE;
port_pin_set_output_level(LED_RED_KEY,false); xTaskNotifyFromISR(xSerialTaskH,pstrRecv>s16BufferSize,eSetValueWithoutOverwrite,&xHigherPriorityTaskWoken );
}
else
{
close(tcp_server_socket);
tcp_server_socket = -1;
}
}
}
break;
default: break;
}
}
static void Task(void *params)
{
for (;;)
{
//Do Something
portDISABLE_INTERRUPTS(); /// I added this to fix the issue.....
recv(tcp_client_socket, TCPBuffer, sizeof(TCPBuffer), 0);
xTaskNotifyWait( 0x00, ULONG_MAX, &ulSize, portMAX_DELAY );
//endless repeat for incoming all messages
}
}
The problem I have is that if I’ve many pending messages on Wifi, as soon as recv function is called, interrupt is generated. If interrupt if executed BEFORE xTaskNotifyWait is completed, the xTaskNotifyFromISR called form ISR is not effective and task is never waked up. The only solution I’ve fond at the moment is to DISABLE INTERRUPT before calling recv and xTaskNotifyWait ( that atomatically re-enable them.
I’d like to know if there are other solution for this.
Thank you.