0% found this document useful (0 votes)
24 views7 pages

Interrupts Short & Simple - Part 2 - Variables, Buffers & Latencies - Embedded

Uploaded by

Ahana Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

Interrupts Short & Simple - Part 2 - Variables, Buffers & Latencies - Embedded

Uploaded by

Ahana Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Interrupts short & simple: Part 2 - Variables, buffers & latencies | Embedded http://www.embedded.com/design/programming-languages-and-tools/43...

Sign In Sign Up

Home (/) Programming Languages & Tools Development Centers (/development/programming-languages-and-tools)

Design How-To (/development/programming-languages-and-tools/articles)

Share 1 Tweet Like 5

Editor's note: In this second part in an on-going series on the appropriate use of
interrupts in embedded systems design, Priyadeep Kaur discusses ISRs, global/local Download Datasheets
variables, data buffers, shared memory and the interrupt timing latencies.
PART NUMBER

In the first part of this series on interrupts, we discussed the importance of careful interrupt
Search
handling and some general interrupt handling practices related to the robust structuring of
ISRs. Now we will discuss the implications of the liberal use of global/local variables in an
ISR.

Global variables – Know when it’s modified


Global variables need to be carefully handled while used with ISRs, because interrupts
are generally asynchronous and if a global variable is being written into by an ISR, it can
get modified at any time. We need to be careful of the following aspects:

Reading/Writing Global Variables at multiple places Global variables should be


modified at only a few necessary places inside a program. If a global variable is being
modified by multiple threads (i.e., the main process, ISRs, and other hardware functions
like DMA inside an MCU), there is a chance of the variable getting corrupted.

Reading a global variable at multiple instances inside a main process is as worrisome


as its modification in different threads. Consider the following example:

1 of 7 9/12/2017, 9:58 AM
Interrupts short & simple: Part 2 - Variables, buffers & latencies | Embedded http://www.embedded.com/design/programming-languages-and-tools/43...

Click on image to enlarge.

else if(Command == 2)

Click on image to enlarge.

2 of 7 9/12/2017, 9:58 AM
Interrupts short & simple: Part 2 - Variables, buffers & latencies | Embedded http://www.embedded.com/design/programming-languages-and-tools/43...

Click on image to enlarge.

void ADC_ISR(void)
{
Data = ADC_MSB;

(Data<<8)|ADC_LSB;

3 of 7 9/12/2017, 9:58 AM
Interrupts short & simple: Part 2 - Variables, buffers & latencies | Embedded http://www.embedded.com/design/programming-languages-and-tools/43...

4 of 7 9/12/2017, 9:58 AM
Interrupts short & simple: Part 2 - Variables, buffers & latencies | Embedded http://www.embedded.com/design/programming-languages-and-tools/43...

Share 1 Tweet Like 5

5 of 7 9/12/2017, 9:58 AM
Interrupts short & simple: Part 2 - Variables, buffers & latencies | Embedded http://www.embedded.com/design/programming-languages-and-tools/43...

all articles (/rss/all) category ▼

6 of 7 9/12/2017, 9:58 AM
Interrupts short & simple: Part 2 - Variables, buffers & latencies | Embedded http://www.embedded.com/design/programming-languages-and-tools/43...

ASPENCORE NETWORK

EBN (http://www.ebnonline.com/) EDN (http://www.edn.com/) EE Times (http://www.eetimes.com/) EEWeb (https://www.eeweb.com/) Electronic Products

(http://www.electronicproducts.com/) Electronics-Tutorials (http://www.electronics-tutorials.ws/) Embedded (http://www.embedded.com/) Planet Analog (http://www.planetanalog.com/)

ElectroSchematics (http://www.electroschematics.com/) Power Electronics News (http://www.powerelectronicsnews.com/) TechOnline (http://www.techonline.com/) Datasheets.com

(http://www.datasheets.com/) Embedded Control Europe (http://www.embedded-control-europe.com/) Embedded Know How (http://www.embedded-know-how.com/ ) Embedded News

(http://embedded-news.tv/) IOT Design Zone (http://iot-design-zone.com/) Motor Control Design (http://motor-control-design.com/) Electronics Know How (http://electronics-know-how.com/)

GLOBAL NETWORK

EE Times Asia (http://www.eetasia.com/) EE Times China (http://www.eet-china.com/) EE Times India (http://www.eetindia.co.in/) EE Times Japan (http://eetimes.jp/) EE Times Taiwan

(http://www.eettaiwan.com/) EDN Asia (http://www.ednasia.com/) EDN China (http://www.ednchina.com/) EDN Taiwan (http://www.edntaiwan.com/) EDN Japan (http://ednjapan.com/)

ESM China (http://www.esmchina.com/)

Working With Us: About (http://www.aspencore.com/) | Contact Us (http://mac.aspencore.com/AspenCore_Contact-Us.html) | Media Kits (http://mac.aspencore.com/AspenCore_Media-Guide.html)
Terms of Service (http://www.aspencore.com/terms-of-use) | Privacy Statement (http://www.aspencore.com/privacy-policy) | Copyright ©2017 AspenCore All Rights Reserved

7 of 7 9/12/2017, 9:58 AM

You might also like