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

The empty for loop in list.c

Posted by fraza077 on September 11, 2015

I guess a lot of you have seen this your code get stuck here before:


for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ { / There is nothing to do here, just iterating to the wanted insertion position. */ }


After having bundled through all this once again today, I found my problem (I was in a critical section due to an accidental Find/Replace having greater scope than I thought), but it struck me that there really weren't enough checks in this section, despite the comment claim that "There is nothing to do here".

In my case, for whatever reason, it was adding a duplicate element to the list. Is this something one could use an assert for? Inside the for loop:


configASSERT(pxNewListItem != pxIterator);

Also, in case anything else goes wrong, why not ensure the list only gets run through once? For example:


volatile xListItem *start = ( xListItem * ) &( pxList->xListEnd ); volatile uint32 RunThroughCnt = 0; for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) { if (pxIterator == start) { RunThroughCnt++; configASSERT(RunThroughCnt <= 1); } configASSERT(pxNewListItem != pxIterator);

}

I imagine those of you who know the inner workings of FreeRTOS better than I do might know some reasons why these wouldn't work? If not, is there anything else that can be done to make this safer?

Just staying in the for loop forever is annoying, all the info I get is that the watchdog kicked in, And I don't have a clue where the code was when that happened.

Cheers,

Zac


The empty for loop in list.c

Posted by rtel on September 11, 2015

Things inside the kernel are kept as lean as possible, especially code that runs frequently, and especially especially code that is in a loop. Adding these checks would be useful, I agree, but aren't done because it would make the code slower. Instead we have added asserts at the points in the code that can lead to you getting stuck in the loop. For example, the most common cause (bar far) is people setting incorrect interrupt priorities - that is - using FreeRTOS API functions from an interrupt that has a priority higher than the priority masked by critical sections - so we have an assert that traps that happening. That way the assert should be hit before the code ever reaches the loop, and it is hit at the point the cause is detected, rather than the symptom.

Regards.


[ 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