Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

xTimer and tcp connection problem

Posted by c0de4x4 on December 19, 2013

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);
currentidindex = 1; } else { // send second ID xQueueSend ( xQueueIDHandler, (void *)&s2Queue, ( portTickType ) 0);
currentid_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);
currentidindex = 1; } else { // send second ID xQueueSend ( xQueueIDHandler, (void *)&s2Queue, ( portTickType ) 0);
currentidindex = 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

Posted by edwards3 on December 19, 2013

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

Posted by c0de4x4 on December 19, 2013

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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists