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

What is the best method to update flag from interrupt?

Posted by mukeshtalks on October 8, 2015

Hi, I have to implement one comparator intrrupt in Stm32F3 for protection of my circuit. When Ever interrupt comes i need to set one flag and need to check into task which i can not out into wait state/ bloack state for waiting the flag is set. I am using FreeRTOS 7.6 in my project. I am right now using One global flag variable of volatile type and updating it. 1. Can you please let me know is there any issue i can face in updating the flag this way? 2. Any other safe alternative of this? So that my task should not enter into wait/block state .

Mukesh


What is the best method to update flag from interrupt?

Posted by rtel on October 8, 2015

Sorry - I don't understand your requirements, can you try re-phrasing "When Ever interrupt comes i need to set one flag and need to check into task which i can not out into wait state/ bloack state for waiting the flag is set."


What is the best method to update flag from interrupt?

Posted by mukeshtalks on October 9, 2015

sorry for typo. I mean one flag should be set into by Comparator interrupt. And based on this flag want to take decission in one task. This task i can not put into block/wait state.


What is the best method to update flag from interrupt?

Posted by heinbali01 on October 10, 2015

Hello Muku,

1 Can you please let me know is there any issue i can face in updating the flag this way?

You are accessing a memory location from both an interrupt as well as from a task. That is perfectly legal. You already made the shared variable volatile, which forces the compiler not to use caching but in stead to access the physical memory each time you read or write it:

~~~~~ volatile BaseType_t xCounter = 0; void ISR() { /* No critical section is needed because nobody will access xCounter while this ISR is active. */ xCounter++; }

void vMyTask( void pvParameter ) { for( ;; ) { / When reading the variable no critical section is needed. / if( xCounter > 0 ) { / * Need a critical section because: * ld.w r9,r8[0x0] // load * sub r9,1 // decrement * st.w r8[0x0],r9 // store */ taskENTERCRITICAL(); xCounter--; taskEXITCRITICAL(); } } } ~~~~~

2 Any other safe alternative of this? So that my task should not enter into wait/block state

As stated here above, you can read the common variable without a problem. When changing the variable (increment/decrement), make sure this is done in a critical section. If not you might miss changes that are made in the ISR.

Just curious, wouldn't it be profitable to use some blocking mechanism? Why can't you do that?

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