![]() |
Forum Index : Microcontroller and PC projects : CMM2: Bug/unexpected behaviour wien Sub called by SetTick
![]() ![]() |
|||||
Author | Message | ||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
I was using a STATIC to implement a lock under the misapprehension that they were implemented as strangely scoped globals. Geoff could you clarify what operations can be considered to be atomic and what can be interrupted by an ISR ? Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Double posted again, wtf! MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
The only command that can be interrupted while it is executing is PAUSE, all others are atomic (ie, interrupts are checked when the command completes). Geoff Geoff Graham - http://geoffg.net |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
What about statements are they atomic ? i.e. what are the possible resulting values of "b" from "b = a + a" if there is an ISR that manipulates "a" ? Thanks, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Naming the two possible values of a (being before / after an interrupt) as a1 and a2, then I believe b is either a1+a1 or a2+a2. So yes they're atomic. John Edited 2021-07-11 00:55 by JohnS |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1134 |
My conclusion after sleeping on it - the SETTICK ISR shouldn't call the routine in question directly. I think the following example shows a working interlock. The key is that the ISR call to foo is delayed (but not lost) if the main routine is already using it. > list dim fooflag, s, a(50) settick 499, fooISR fooflag = 0 do fooflag = 1 do while fooflag foo inc foolfag, -1 loop if s mod 50 <> 0 then print s pause 1 loop sub foo local i s = 0 for i = 1 to 50 a(i) = a(i) + 1 s = s + a(i) next i end sub sub fooISR if fooflag then inc fooflag else foo endif end sub Visit Vegipete's *Mite Library for cool programs. |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
To clarify... the interpreter checks for an interrupt at the end of a line or when the statement separator (":") is reached. Geoff Geoff Graham - http://geoffg.net |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Lovely, that's what I thought had been said previously. Thanks Geoff, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |