Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:25 03 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: Bug/unexpected behaviour wien Sub called by SetTick

     Page 2 of 2    
Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 10:31am 10 Jul 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4311
Posted: 10:32am 10 Jul 2021
Copy link to clipboard 
Print this post

Double posted again, wtf!
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 11:59am 10 Jul 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4311
Posted: 12:20pm 10 Jul 2021
Copy link to clipboard 
Print this post

  Geoffg said  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


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 Kingdom
Posts: 4044
Posted: 02:54pm 10 Jul 2021
Copy link to clipboard 
Print this post

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: Canada
Posts: 1134
Posted: 04:58pm 10 Jul 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 3292
Posted: 07:30pm 10 Jul 2021
Copy link to clipboard 
Print this post

  thwill said  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"

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 Kingdom
Posts: 4311
Posted: 07:45pm 10 Jul 2021
Copy link to clipboard 
Print this post

  Geoffg said  To clarify... the interpreter checks for an interrupt at the end of a line or when the statement separator (":") is reached.

Geoff


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
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025