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

FreeRTOS Multiple Timer Issue

Posted by deac3 on March 1, 2017

Hi All,

I'm creating and starting 9 timers as part of a constructor for my class. I am creating 4 instances of this class and it looks like only the timers for the first couple are running. My constructor is as follows:

~~~ SDM220( int modid ) { this->meterid = modid; printf("SDM220 #%dn", this->meterid );

        // begin all the timers
        for( int i = 0; i < NUM_TIMERS; i++ )
        {
            // configure a token for timer i 
            my_tokens[ i ].meter_id = mod_id;
            my_tokens[ i ].read_type = sdm_sensor_configs[ i ].identifier;
            my_tokens[ i ].config_idx = i;

            void* token_ptr = &my_tokens[ i ];

            // create and start timer i
            xTimers[ i ] = xTimerCreate(    "sdm_timer",                                                // text name of timer, store tag?
                                            sdm_sensor_configs[ i ].sensor_delay / portTICK_PERIOD_MS,  // timer interval
                                            pdTRUE,                                                     // reset timer?
                                            token_ptr,                                                  // timer id, in this case token object
                                            this->vTimerCallback );                                     // timer callback function

            if( xTimers[ i ] != NULL )
            {
                if( xTimerStart( xTimers[ i ], 0 ) != pdPASS )
                    {
                        printf( "timer not activated\n" );
                    }
            }
            else
            {
                printf( "sdm220 constructor goofed\n" );
            }
        }

        // create recipient queue for all the meters
        xSDMQueue = xQueueCreate( 10, sizeof( sdm_read_token ) );
    }

~~~

None of the xTimerStart() != pdPASS checks fail, but the timers for the later declared instances do not trigger.

For example if i declare the objects like this

~~~ // instantiate sdm meters struct SDM220 mysdm1( 1 ); struct SDM220 mysdm2( 2 ); struct SDM220 mysdm3( 3 ); struct SDM220 mysdm4( 4 ); ~~~

Then events for 1 and 2 come through fine, but 3 is spotty and 4 is nonexistent.

If I declare them like this: ~~~ // instantiate sdm meters struct SDM220 mysdm2( 2 ); struct SDM220 mysdm3( 3 ); struct SDM220 mysdm4( 4 ); struct SDM220 mysdm1( 1 ); ~~~

Then 2 and 3 come through fine, 4 is spotty, and 1 is nonexistent.

I thought it might be a stack issue on the timer service task but I increased the stack in FreeRTOSconfig.h and it remained unused! Any advice would be much appreciated!


FreeRTOS Multiple Timer Issue

Posted by rtel on March 1, 2017

I'm not sure what the problem could be if xTimers[ i ] is never being set to NULL within the loop.

Do you have configASSERT() defined? What is configTIMERQUEUELENGTH set to? Are the constructors called before the scheduler is started?


FreeRTOS Multiple Timer Issue

Posted by deac3 on March 1, 2017

Thanks for the quick reply!

I am using the esp32 port of freeRTOS in the esp-idf. Looks like it is defined here ~~~

if defined(CONFIGFREERTOSASSERT_DISABLE)
define configASSERT(a) /* assertions disabled */
elif defined(CONFIGFREERTOSASSERTFAILPRINT_CONTINUE)
define configASSERT(a) if (!(a)) {
    ets_printf("%s:%d (%s)- assert failed!\n", __FILE__, __LINE__,  \
               __FUNCTION__);                                       \
}
else /* CONFIGFREERTOSASSERTFAILABORT */
define configASSERT(a) if (!(a)) {
    ets_printf("%s:%d (%s)- assert failed!\n", __FILE__, __LINE__,  \
               __FUNCTION__);                                       \
    abort();                                                        \
    }
endif

~~~ configTIMERQUEUELENGTH was originally 10, I bumped it up to 200.

Yes the constructors are called before the RTOS scheduler. I had the timeout for xTimerStart() at 1000 for a bit, but learned that it doesnt matter if its called before the scheduler starts.

I am not sure what you mean about xTimers[ i ] being set to NULL


FreeRTOS Multiple Timer Issue

Posted by rtel on March 1, 2017

I am using the esp32 port of freeRTOS in the esp-idf. Looks like it is defined here

if defined(CONFIGFREERTOSASSERT_DISABLE)

I should double check which of these is actually being compiled in.

configTIMERQUEUELENGTH was originally 10, I bumped it up to 200.

Yes the constructors are called before the RTOS scheduler. I had the timeout for xTimerStart() at 1000 for a bit, but learned that it doesnt matter if its called before the scheduler starts.

When a timer is started a command is sent to the timer command queue. If the scheduler is not started then the command will sit in the command queue until the scheduler is started - which is why I was asking how long the queue was.

In your case, all the start commands should be in the timer command queue when the timer task is started.

Open the file FreeRTOS/source/timers.c, and find the line

static void prvTimerTask( void *pvParameters )

which is on line 544 in my current version of the file, but will no doubt be different in yours. Put a breakpoint on that line. It will get hit when the timer task starts. When the break point is hit inspect the xTimerQueue variable. You may need to cast it in the debugger to something like:

( xQUEUE ) xTimerQueue

otherwise the debugger might just see it as a void * and not show you its internals.

In the debugger you should be able to see the number of items in the queue. Does it look reasonable for the number of timers you started?

I am not sure what you mean about xTimers[ i ] being set to NULL

You said (if I recall correctly) that the line xTimers[ i ] = xTimerCreate( .... ) never returns NULL, which indicates the timer is being created.


[ 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