do you see the same behavior if you run the client and server on different DUTs
Not yet tested, I’m waiting for another board.
The code is similar to the one I already shared, without the second server socket, and without response sent, just server processing messages:
//MAIN
void vApplicationIdleHook(void) {}
int main(void)
{
uint8_t error;
BOARD_init();
error = startTCP_looped_communication();
if (!error)
{ vTaskStartScheduler(); }
else { }
for( ;; ) { }
return 0;
}
//high level task
uint32_t startTCP_looped_communication(void)
{
int32_t ret = pdPASS;
if (ret == pdPASS)
{ /* Create server main task */
ret = xTaskCreate(server_conn_Task, "server_conn_Task", REMOTE_SERVER_MAIN_TASK_STACK_SIZE, NULL, REMOTE_SERVER_MAIN_TASK_PRIORITY, &server_TaskHandler);
}
if (ret == pdPASS)
{ /* Create clientmain task */
ret = xTaskCreate(client_conn_Task, "client_conn_Task", REMOTE_SERVER_MAIN_TASK_STACK_SIZE, NULL, REMOTE_SERVER_MAIN_TASK_PRIORITY, &client_TaskHandler);
}
return (ret == pdPASS) ? 0 : 1;
}
//Client TASK
portTASK_FUNCTION(client_conn_Task, pvParam)
{ (void)pvParam;
uint8_t ret;
static const TickType_t tout = pdMS_TO_TICKS(5000);
Socket_t local_server_socket;
const char *pcInterfaceName = "eth1";
struct freertos_sockaddr xServerAddress, xClientAddress;
BaseType_t xSentBytes;
RCP_msg_t tx_msg;
local_server_socket = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP);
configASSERT(local_server_socket != FREERTOS_INVALID_SOCKET);
FreeRTOS_setsockopt(local_server_socket, 0, FREERTOS_SO_BINDTODEVICE, pcInterfaceName, strlen(pcInterfaceName));
FreeRTOS_setsockopt(local_server_socket, 0, FREERTOS_SO_RCVTIMEO, &tout , sizeof(tout ));
FreeRTOS_setsockopt(local_server_socket, 0, FREERTOS_SO_SNDTIMEO, &tout , sizeof(tout ));
xClientAddress.sin_family = FREERTOS_AF_INET;
xClientAddress.sin_port = FreeRTOS_htons(ETH_PORT);
xClientAddress.sin_addr = FreeRTOS_inet_addr("192.168.1.2");
xServerAddress.sin_family = FREERTOS_AF_INET;
xServerAddress.sin_port = FreeRTOS_htons(ETH_PORT);
xServerAddress.sin_addr = FreeRTOS_inet_addr("192.168.1.1");
vTaskDelay(pdMS_TO_TICKS(1000));
do {
ret = FreeRTOS_connect(local_server_socket, &xServerAddress, sizeof(xServerAddress));
vTaskDelay(pdMS_TO_TICKS(750));
} while (ret < 0);
for (;;)
{
encode_and_send_ETH_payload( msg_list[msg_id], local_server_socket);
msg_id++;
if(msg_id>7) {msg_id = 0;}
vTaskDelay(pdMS_TO_TICKS(22));
}
}
//SERVER task
portTASK_FUNCTION(server_conn_Task, pvParam ) {
(void)pvParam;
Socket_t xListeningSocket, xConnectedSocket, local_client_socket;
struct freertos_sockaddr xBindAddress, connected_client_sockadd;
socklen_t connected_client_size = sizeof(connected_client_sockadd);
static const TickType_t tout = pdMS_TO_TICKS(5000);
const char *pcInterfaceName = "eth0"; //test8650 // eth0=8670
RCP_msg_t rx_eth_msg, tx_eth_msg;
BaseType_t xReceivedBytes, xSentBytes;
xListeningSocket = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP);
if (xListeningSocket != FREERTOS_INVALID_SOCKET)
{
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &tout , sizeof(tout ));
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_SNDTIMEO, &tout , sizeof(tout ));
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_BINDTODEVICE, pcInterfaceName, strlen(pcInterfaceName));
xBindAddress.sin_family = FREERTOS_AF_INET;
xBindAddress.sin_port = FreeRTOS_htons( ETH_PORT );
xBindAddress.sin_addr = FreeRTOS_inet_addr("192.168.1.1");
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) ); //bind to 5555
FreeRTOS_listen( xListeningSocket, xBacklog );
xConnectedSocket = FreeRTOS_accept( xListeningSocket, &connected_client_sockadd, &connected_client_size );
if (xConnectedSocket != 0x0)
{
for( ;; )
{
xReceivedBytes = FreeRTOS_recv(xConnectedSocket, (void*)(&rx_eth_msg), sizeof(rx_eth_msg), 0 );
if( xReceivedBytes > 0 )
{
tx_eth_msg = compute_client_request(rx_eth_msg);
}
}
}}}
encode_and_send_ETH_payload just encode and sends ETH:
defines variables..
...
memcpy(buffer, &message, sizeof(message));
FreeRTOS_send(xSocket, buffer, messageSize, 0);
free(buffer);
...
I’ve tested the speed of functions using ticks to verify any “blocking” point.
It turns out my procedures gets some dozens of microseconds each.
Somehow, somewhere, some FreeRTOS process cannot go under 22ms.