<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Is there something like &#34;atomic read&#34; for accessing a volatile variable?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1112</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:06 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1112" rel="self" type="application/rss+xml" />

		<item>
			<title>poslathian on "Is there something like &#34;atomic read&#34; for accessing a volatile variable?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1112#post-6861</link>
			<pubDate>Thu, 13 Oct 2011 10:29:09 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">6861@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;darth - perry is right, you and I are both living on the edge.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Darth Maker on "Is there something like &#34;atomic read&#34; for accessing a volatile variable?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1112#post-6856</link>
			<pubDate>Wed, 12 Oct 2011 17:18:47 +0000</pubDate>
			<dc:creator>Darth Maker</dc:creator>
			<guid isPermaLink="false">6856@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I've written programs that have a volatile tick variable that is incremented by a timer interrupt, then cleared the variable in the main program without issue.  It's possible that it just never collided, but it did work.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>perry on "Is there something like &#34;atomic read&#34; for accessing a volatile variable?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1112#post-6850</link>
			<pubDate>Wed, 12 Oct 2011 16:08:48 +0000</pubDate>
			<dc:creator>perry</dc:creator>
			<guid isPermaLink="false">6850@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;frpr: This is fine as written provided you only READ and do not modify the volatile&#60;br /&#62;
in loop(). Whether or not you need these atomic operations will depend on the context in&#60;br /&#62;
which you're accessing the variables. If you only ever modify it in interrupt&#60;br /&#62;
context and ensure that no other interrupt (you may get preempted by a higher&#60;br /&#62;
priority interrupt) modifies that counter, then you won't require locks or anything. &#60;/p&#62;
&#60;p&#62;If you want to safely modify the variable, you will need to either disable interrupts&#60;br /&#62;
(nvic_globalirq_disable()), or use some form of strex/ldrex, which are ARM-specific&#60;br /&#62;
instructions that lock and tag the memory bus to allow you to implement things like&#60;br /&#62;
atomic operations, mutexes, semaphores, etc. I'd suggest a google on these instructions&#60;br /&#62;
if you decide to go this route.&#60;/p&#62;
&#60;p&#62;The easiest route is probably to just disable interrupts and reenable them when you're done.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Is there something like &#34;atomic read&#34; for accessing a volatile variable?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1112#post-6847</link>
			<pubDate>Wed, 12 Oct 2011 15:48:09 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">6847@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;perhaps I am missing something but that should just work. By declaring my_timeflag to be volatile, the compiler should expect that that var may be modified by hardware or interrupts and not stash it in a register. &#60;/p&#62;
&#60;p&#62;did this not work for you?&#60;/p&#62;
&#60;p&#62;btw, I do this all the time, where a variable is incremented or set in an ISR and then read or reset from the main loop. Very handy, its also how millis/micros() work.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>frpr on "Is there something like &#34;atomic read&#34; for accessing a volatile variable?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1112#post-6835</link>
			<pubDate>Wed, 12 Oct 2011 10:55:56 +0000</pubDate>
			<dc:creator>frpr</dc:creator>
			<guid isPermaLink="false">6835@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello,&#60;br /&#62;
I'm just a newbie at Maple IDE. Normally, I can use functions: cli(); y=x; sti(); in Arduino IDE. Is there something like &#34;atomic read&#34; for accessing a volatile variable in Maple IDE? My situation is like the code below. Please, is there also some &#34;atomic write&#34; func.?&#60;/p&#62;
&#60;p&#62;[code]&#60;br /&#62;
volatile uint32 my_timeflag;&#60;br /&#62;
uint32 currentValue;&#60;/p&#62;
&#60;p&#62;void isr_TIM2OVF(void){&#60;br /&#62;
  my_timeflag++;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;setup(){&#60;br /&#62;
  // init TIM2 code&#60;br /&#62;
  // ...&#60;br /&#62;
  // reset counter&#60;br /&#62;
  my_timeflag=0;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;loop(){&#60;br /&#62;
//&#60;br /&#62;
// A PROBLEM HERE.&#60;br /&#62;
// I'd like to do &#34;atomic read&#34; of the&#60;br /&#62;
// &#34;my_timeflag&#34; var.&#60;br /&#62;
// &#60;/p&#62;
&#60;p&#62;currentValue = my_timeflag; //???&#60;/p&#62;
&#60;p&#62;// do something in loop&#60;br /&#62;
}&#60;br /&#62;
[/code]
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
