| Author |
Message |
stevech
Joined: 23 Feb 2006
|
|
Posted: 22 September 2006, 2:47 AM Post subject: RAM for data across a reset |
|
|
Is there a way to hide some data in RAM so that (as a hack) I can use it after the micro is reset (without loss of power)?
such as, some kludgey way to put data where I (hope/know) that the heap won't go? |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 22 September 2006, 3:10 AM Post subject: |
|
|
It would be cleaner to use Persistent Memory or Program Memory.
That said, depending on how you're going to use it, the following technique may work:
| Code: | Sub Main()
Dim addr as UnsignedInteger
Dim val as UnsignedInteger Based addr
addr = Register.RamStart + Register.RamUsed + 100
val = val + 1
Debug.Print CStrHex(addr)
Debug.Print CStr(val)
End Sub |
This code relies on the fact that the RAM that is not statically allocated is not initialized (an implementation detail that could change in the future). Note that the stack for Main() begins at Register.RamStart + Register.RamUsed. The offset of 100 puts the address well past what might be used in this simple case.
If you compile and run this code, the value displayed should be incremented on each reset. |
|
| Back to top |
|
 |
stevech
Joined: 23 Feb 2006
|
|
Posted: 22 September 2006, 5:00 AM Post subject: |
|
|
thanks. I'll look at that technique.
I tried using system.alloc to see if that memory was altered by a reset, and it is.
use of persistent memory is a concern because I'd have to re-write it too frequently.
One issue is the ATN signal. I need to arrange a terminal program that doesn't cause DTR to toggle when the COM port is opened. Seems like Windows wants to do so. This of course causes the ZX24 to reset each time a terminal program opens the serial port.
Also, the debug window in the ZBasic IDE always toggles DTR when the IDE opens the port. |
|
| Back to top |
|
 |
|