Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner