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


call vportfree from isr

Posted by stefano marini on August 14, 2010
I need of some help:
calling a vportfree function from isr crash the system.

this succeed because the vport free port for arm7 use vTaskSuspendAll internally.
I use the heap_2.c file

there is a way to solve this problem?

RE: call vportfree from isr

Posted by Dave on August 14, 2010
Never call a function that does not end in FromISR from an ISR.

RE: call vportfree from isr

Posted by Richard Damon on August 14, 2010
As was said, calling any FreeRTOS function that doesn't end in FromISR in an ISR is an invitation for trouble. As it turns out, memory management (malloc/free type functions) do not work well in an ISR, because of there need to set up periods where they are not disturbed while they manipulate structures shared among multiple tasks (the free store list). In general, there are 3 categories of ways to implement this: Disabling Interrupt, Disabling the Scheduler, or a Mutex. Some of the manipulations that a memory management routine does may take long enough that you sometimes don't want to use the disabling interrupt method (so FreeRTOS uses a Disabling the Scheduler method), but this is not compatible with the use of memory management during isrs, as that needs to use the Disabling Interrupt method.

One option is to take the memory management routines (vPortFree, vPortMalloc) and rewrite them (that is one reason it is nice to use open source, you have the source to modify) to use critical sections instead of schedule disabling, and then add a FromISR version that assumes it is in an interrupt and thus doesn't need the critical section. It would then be nice to submit this version back for others to use, maybe as a heap_2isr.c

The other option is to change the structure of your program a bit. If you only need free in the isr, once solution would be to set up a queue that rather than actually doing the free in the isr, it pushes the memory pointer on the queue, and then a task pops the pointer off and calls free. If you need to allocate in the isr, it gets a bit trickier, but often the buffer size needed is known ahead of time, so you can preallocate a buffer(s) for it to use.

RE: call vportfree from isr

Posted by stefano marini on August 18, 2010
this means that using the file heap_2.c create a file heap_2isr.c
and internally substitute to tasksuspendall the portENTER_CRITICAL()
and to taskresume all the portEXIT_CRITICAL()

is it right?


RE: call vportfree from isr

Posted by Richard Damon on August 19, 2010
Yes, and then create another function vPortFreeFromISR that is just like vPortFree except it omits the portENTER_CRITICAL() and portEXIT_CRITICAL() and use THAT function inside the ISR.

[ 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