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

ISR management and FreeRTOS

Posted by jradoslav on November 25, 2014

Dear FreeRTOS developers

I have questions about event creation/memory management in ISR subroutines.

I need to create memory block(Event) in ISR and then send event pointer it to queue.

before i have written this: ISR() {

Event* e = pvPortmalloc();
fillEvent(e,&ISRData);
sendQueueFromISR(queue,e);

}

then I`ve read some docs that memory allocation in ISR is not good choice.

this code block seems to be better:

~~~~ ISR() {

Event* e;
if(receiveFromISR(freeMemEventQ,&e))
{
    sendMemoryRequirementForNextEvent(); -- requirements queue which process other mem generator task
    fillEvent(e,&ISRData);
    sendQueueFromISR(queue,e);
}

} ~~~~

My questions are:

1 How many calls **FromISR routines can be used in ISR? 2 how much ticks consume **FromISR, I`m using onlu sizeof(pointer) items 3 How can i use higher priority context switching (portYIELD) with more then 1 FromISR call in ISR subroutine. 4 how can i use higherPriorityWoken variable with more then 1 FromISR call in ISR subroutine. 5 portYIELD can be used only at end of ISR subroutine ? 6 How most time-ticks can consume ISR subroutine for safe FreeRTOS running 7 it is absolutely impossible to use malloc in ISR without memory generator task? ~~~~ ISR { BaseType_t hpw1=false,hpw2=false;

FromISR(q,data,&hpw1); FromISR(q,data,&hpw2);

portYIELDFromISR(hpw1|hpw2);

} ~~~~

OR

~~~~ ISR { BaseType_t hpw1;

FromISR(q,data,&hpw1); //hpw1 = true

FromISR(q,data,&hpw2); //hpw2 = false

portYIELDFromISR( what? );

} ~~~~

Thank you


ISR management and FreeRTOS

Posted by rtel on November 25, 2014

Allocating memory in an interrupt is rarely a good thing as it can be non deterministic. Although FreeRTOS has 5 difference memory allocation schemes to choose from none of them are designed to be called from an interrupt as they use scheduler locks (so interrupts remain enabled while the allocation takes place). It would be possible to edit one of those schemes to make it safe to use from an interrupt, but I think there could be better options available.

For example:

  • If the block being allocated is always the same size then pre-allocate a pool of blocks. Then you can just grab a free block that has already been allocated, rather than allocate a block in the interrupt itself.

  • Allocate a block outside of the interrupt so it is ready for use inside the interrupt. When the block gets used, allocate another, again from outside the interrupt, so the interrupt always has a block ready.

  • Defer the interrupt processing to a task. You can do that using a semaphore, or using the centralised deferred interrupt processing mechanism. See the following link - note if you want the processing to happen immediately after the interrupt exits you will need to ensure the timer task has a priority above that of any other application tasks. http://www.freertos.org/xTimerPendFunctionCallFromISR.html http://www.freertos.org/a00110.html#configTIMERTASKPRIORITY

1 How many calls */**FromISR routines can be used in ISR?

There is no limit. You can use the same "xHigherPriorityTaskWoken" parameter to each as the API functions will only ever set the value to pdTRUE - leaving it unchanged in all other cases.

2 how much ticks consume /***FromISR, I`m using onlu sizeof(pointer) items

It will not consume any ticks (that is, it won't last longer than a tick period, unless you have configTICKRATEMS set to something extremely fast). It will of course consume some time.

3 How can i use higher priority context switching (portYIELD) with more then 1 FromISR call in ISR subroutine.

As above - you can just pass the address of the same xHigherPriorityTaskWoken variable into each. You only need to initialise the variable to pdFALSE once, before the first 'FromISR' call.

4 how can i use higherPriorityWoken variable with more then 1 FromISR call in ISR subroutine.

I think I have answered that twice now ;o)

5 portYIELD can be used only at end of ISR subroutine ?

That deepens on the port you are using. For most ports it can be called anywhere. For a few ports it is essential it is called at the end.

Regards.


ISR management and FreeRTOS

Posted by jradoslav on November 27, 2014

Thank you for your comprehensive answer about ISR management. what are for me very important information.

xTimerPendFunctionCallFromISR is very usable and i think that can be used as event dispatch function

i solve event item generator problem with 1 memory requirement queue/memory pointer generator task, which generate memory allocation point from requirement item

this requirement item contains pointer to a destination queue and size of mem allocation requirement.

struct memReqItem { uint32_t memSize; xQueueHandle destinationQueue;

}

if this item generator task receive from 1 requirement queue , then allocate memory (memSize) and starst pointer sends to destination pointer queue (destinationQueue). ISR uses this queue and sends next requirement.

So. for each ISR is created one destinationQueue that is used only in depended ISR.

this pointer fills with ISR data and can be used as argument pointer in xTimerPendFunctionCallFromISR as dispatcher calls.


[ 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