FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [February 2005 Threads] Accessing variables from ISRsPosted 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 ISRsPosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|