Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
noob question 1

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
stevech



Joined: 23 Feb 2006
Posts: 657

Posted: 23 February 2006, 5:11 AM    Post subject: noob question 1 Reply with quote

New user w/apologies...
In ZBasic, if one reads or writes a RAM variable that is larger than one byte, say, using Register.RTCtick, or any such that is altered by an interrupt routine, how does one code to protect the volatility? I would normally do CLI and SEI while reading or writing that variable, if an ISR might change its value. Perhaps Register.RTCtick takes care of this. But what about other cases?
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 23 February 2006, 6:02 AM    Post subject: Reply with quote

This is a good question and would be a concern if you were using the AVR directly but you are not. The answer to the question is that you don't need to worry about such things as the Virtual Machine inside the ATmega32 (the ZBasic runtime) takes care of this for you. ZVM is an acronym for ZBasic Virtual Machine

The longer answer involves explaining why this is the case. The ZBasic compiler converts your Basic program into an intermediate language (the ZXB file) that is then downloaded to the SPI EEPROM. The ZBasic runtime loads this program and interprets each instruction and executes it. The instructions can be seen if you generate a list file from the compiler. Each instruction (e.g. push long onto stack) executes as a single unit before the next instruction in the same or different task is executed. While executing the instruction it is possible to receive an interrupt. This is serviced by the ZBasic runtime which may set or clear interrupts (the SEI/CLI) and then completes execution of the virtual machine instruction.

On my website (see below) I have an article that explain the ZBasic architecture (the ZBasic intro one). There is also a series of 6 articles that explains the BasicX internal architecture and virtual machine. ZBasic is similar is many ways but the virtual machine instructions are different.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 23 February 2006, 6:04 AM    Post subject: Reply with quote

The ZBasic Virtual Machine firmware takes care of that for you as long as you access the data item by the "normal means". By this I mean using a value in an expression or assigning to a (register) variable. On the other hand, if you were to read the value of Register.RTCTick by using BlockMove(), the transfer is not guaranteed to be atomic and may produce incorrect results.

There is no mechanism for disabling interrupts in user code.


Last edited by dkinzer on 23 February 2006, 6:21 AM; edited 1 time in total
Back to top
stevech



Joined: 23 Feb 2006
Posts: 657

Posted: 23 February 2006, 6:10 AM    Post subject: Reply with quote

thanks. Got it.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group