Quality RTOS & Embedded Software

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




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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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