Hi Steve,
I've used extended mode for a couple of projects now - basically you just sacrifice a bunch of IO pins and you get a multiplexed data and address bus. It's then fairly trivial to hang external RAM or FLASH from these, or just to memory map the entire project. I use this feature on an 18F8722 so there's plenty of IO pins left.
Structures seem like a good idea! I've lashed up some code to test it out:
Code: Select all
Device = 18F4520
Clock = 20
Public Structure TBigStructure
x As Byte,
y As Byte,
bigstring As String($200)
BigArray(1000) As Float
End Structure
Dim BigStruct As TBigStructure absolute $1000
Dim iCount As Word
BigStruct.x=123
BigStruct.y=123
BigStruct.bigstring = "This is a big string for testing external memory using Swordfish.... blah blah blah blah blah..."
For iCount=1 To 999
BigStruct.BigArray(iCount) = 1.234
Next
Unfortunately, compilation fails with an error
[ASM Error]: Error[126] XRam.asm 951: Argument out of range (4610 not between 0 and 4095)
The offending code in the ASM file is:
Code: Select all
Error[126] : Argument out of range (4610 not between 0 and 4095)
0000C0 EE02 F002 00951 LFSR 0,ADF_M4610_U16
This is because the FSR register cannot take a value larger than 12 bits... I can change the absolute to $800 and then it compiles, but I haven't checked it in hardware yet.
As a comparison, C18 compiles this:
Code: Select all
002772 0e00 MOVLW 0x0 wibble=1234; X:\Firmware\Code template\F8720\main.c
002774 6ef6 MOVWF 0xf6,0x0
002776 0e00 MOVLW 0x0
002778 6ef7 MOVWF 0xf7,0x0
00277a 0e08 MOVLW 0x8
00277c 6ef8 MOVWF 0xf8,0x0
00277e 0ed2 MOVLW 0xd2
002780 6ef5 MOVWF 0xf5,0x0
002782 000d TBLWTPOSTINC
002784 0e04 MOVLW 0x4
002786 6ef5 MOVWF 0xf5,0x0
002788 000e TBLWTPOSTDEC
from this:
Code: Select all
CODEPAGE NAME=externram START=0x080000 END=0x0BFFFF PROTECTED //EXTERNAL MEMORY
SECTION NAME=SRAM ROM=externram
#pragma romdata SRAM
far rom int wibble;
#pragma romdata
wibble=1234;
As you can see, C18 uses table writes to access the external memory - is this something that Swordfish can do? I'd really like to press on with Swordfish, but I'm wondering if I'll have to create some form of helper routine to wrap some assembly code rather than getting the compiler to do it.
Ed.