xTimer and tcp connection problem

Hello everybody. I have a problem with transmitting data to tcp when using timers. I have an application which creates a tcp server for 4 clients (using LwIP – netconn). Each accepted connection is associated with a thread, suspended by a queue. Using LPCXpresso base board and LPC1769 Rev.B (with IAR 6.70) I’m trying to transmit the same data to all the connected clients with a frequency of 1 message per second. I did this in two ways: 1. using a timer 2. using another thread (with delay) When I use the timer, after few minutes, the ethernet connection blocks in busy state. There were no problems when using another thread. for (1): The timer callback function looks like this: ~~~~~ static void vTimerCallback( xTimerHandle pxTimer ) { struct rfqueue *s1Queue, *s2Queue; s1Queue = &id1Message; s2Queue = &id2Message; if(currentidindex == 0) { // send first ID xQueueSend ( xQueueIDHandler, (void *)&s1Queue, ( portTickType ) 0);
current
idindex = 1; } else { // send second ID xQueueSend ( xQueueIDHandler, (void *)&s2Queue, ( portTickType ) 0);
current
id_index = 0;
} } ~~~~~ for (2) the thread is: ~~~~~ static portTASKFUNCTION(vTaskTimer, pvParameters) { int i; struct rfqueue *s1Queue, *s2Queue; s1Queue = &id1Message; s2Queue = &id2Message; while(1) { vTaskDelay(configTICKRATEHZ);
if(currentidindex == 0) { // send first ID xQueueSend ( xQueueIDHandler, (void *)&s1Queue, ( portTickType ) 0);
current_id_index = 1; } else { // send second ID xQueueSend ( xQueueIDHandler, (void *)&s2Queue, ( portTickType ) 0);
current_id_index = 0;
} } } ~~~~~ In the FreeRTOSconfig, the timers are configured as follows: ~~~~~

define configUSE_TIMERS 1

define configTIMERTASKPRIORITY 1

define configTIMERQUEUELENGTH 10

define configTIMERTASKSTACK_DEPTH 96

~~~~~ Timer is created in main() with: ~~~~~ xTimerTest = xTimerCreate( “Test Timer”, 1000 , pdTRUE, ( void * ) 1 , vTimerCallback); configASSERT( xTimerTest ); xTimerStart( xTimerTest, 0 );
~~~~~ Am I missing something in the timers configuration or is it something related to queue send from timer callback? Thank you Cosmin

xTimer and tcp connection problem

Timer callback functions are called from a task, so the execution environment is the same for both code snippets. Only the context is different. The first two things I would guess as being route cause would be 1 You are somehow breaking the thread safety rules of lwIP. The core is not thread safe, sockets are if they are ported right, don’t know about netcon. 2 You are simply running out of stack in the timer task. Do you have stack overflow checking turned on? When you run the code from its own task instead of the timers task do you allocate that task more than 96 words?

xTimer and tcp connection problem

The task stack is 96 also. ~~~~~ xTaskCreate(vTaskTimer, (signed char *) “Test timer”, 96, NULL, (tskIDLE_PRIORITY + 1UL), &xHandleTimer);
~~~~~ The struct sent via queue are defined like this: ~~~~~ struct rfqueue{ uint32t id; uint8t msg[12]; uint8t strength; } id1Message, id2Message; ~~~~~ For stack overflow i have this in the config: #define configCHECKFORSTACK_OVERFLOW 2 I’m testing it again with timers but is it possible to have stack overflow if the data remains unchanged? I’m not modifying the id1Message and id2Message.