Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SAFE attribute for variables

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
hzz

Bascom Member



Joined: 20 Feb 2007
Posts: 270

spain.gif
PostPosted: Sun Aug 02, 2020 12:05 pm    Post subject: SAFE attribute for variables Reply with quote

What does the SAFE attribute do?

BASCOM help explains the problem for which SAFE has been implemented, but it does not explain what SAFE does.
Is it just for the compiler to alert you when the same variable is used inside and outside of an ISR in cases when it could change its value unintentionally?
Does it solve the problem by actually preventing the unintentional change of the variable value in the cases explained?
Does it work only for "Incr" and for variables longer than 1 byte or also for other functions that can be affected by the same problem?

(BASCOM-AVR version : 2.0.8.3 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5071
Location: Holland

blank.gif
PostPosted: Sun Aug 02, 2020 12:24 pm    Post subject: Reply with quote

Quote:
The SAFE option will disable interrupts and enables them, whenever you write or read a safe variable.


This means that the compiler will handle it for you. And since variable is any type , it means for all variables.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1827

blank.gif
PostPosted: Sun Aug 02, 2020 12:46 pm    Post subject: Re: SAFE attribute for variables Reply with quote

hzz wrote:
but it does not explain what SAFE does.

This statement is wrong, it's explained in the help further down the page, and it shows it is ISR-related only.
SAFE encapsulates variable access by a 'disable interrupts'[varaccess]'restore interrupts status' and assures that a variable's access, which consists out of a sequence of opcodes, is completely done by the accessing code.
'Accessing code' means usually main-code, as within ISR access to variables is limited to interrupt code by default.
Back to top
View user's profile
hzz

Bascom Member



Joined: 20 Feb 2007
Posts: 270

spain.gif
PostPosted: Sun Aug 02, 2020 1:03 pm    Post subject: Reply with quote

This is great.
Although errors due to this problem are very rear, they are also very dificult to debug so thanks!
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum