Quality RTOS & Embedded Software

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


Loading

Accessing variables from ISRs

Posted by Nobody/Anonymous on February 26, 2005
Is it safe to access global variables that are used by both ISRs and tasks by simply enclosing the access to the variable(s) with enter/exit critical calls? (see method 1)

Or is the proper way to use the method found in tasks.c to get the TickCount? (like method 2)

(Using a PIC - ask me if i'm lovin it - NOT)

Thanks!
Ron.



------------ Method 1 -------------

interrrupts.c

volatile unsigned char ucPeriodDivider = 1;

#pragma interruptlow vIRQfunction save=PRODH, PRODL, section(".tmpdata")
void vIRQfunction (void)
{
....
OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_EDGE_RISE & ucPeriodDivider);
....
}

monitor.c

extern volatile unsigned char ucPeriodDivider;

void vChangeThePeriod(void)
{
taskENTER_CRITICAL();
ucPeriodDivider = 3;
taskEXIT_CRITICAL();
}

-------------- Method 2 -------------


interrrupts.c

static volatile unsigned char ucPeriodDivider = 1;

#pragma interruptlow vIRQfunction save=PRODH, PRODL, section(".tmpdata")
void vIRQfunction (void)
{
....
OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_EDGE_RISE & ucPeriodDivider);
....
}

void vChangeThePeriod(volatile unsigned char ucPeriod)
{
taskENTER_CRITICAL();
ucPeriodDivider = ucPeriod;
taskEXIT_CRITICAL();
}

monitor.c

extern volatile unsigned char ucPeriodDivider;

void vMonitor(void)
{
....
vChangeThePeriod (3);
....
}

RE: Accessing variables from ISRs

Posted by Richard on February 27, 2005
Method 1 is not dangerous from a mutual exclusion point of view. As long as you are in the critical region the interrupt function cannot touch the variable.


[ 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