I am using a version of the TINIm400 and the TINIs400 reference design with an FPGA connected to CE3 and CE4. I wish to access the registers I have placed in the FPGA but am wondering how to do it. I assume by default the FPGA is effectively at 0x60 0000 (for CE3) but how do I place a variable at this address so I can access with a C instruction. Apologies if it's very obvious.
DS80C400 and memory space with the SDCC compiler
Started by ●November 18, 2004
Reply by ●November 19, 20042004-11-19
Fred said> I am using a version of the TINIm400 and the TINIs400 reference design with > an FPGA connected to CE3 and CE4. > > I wish to access the registers I have placed in the FPGA but am wondering > how to do it. I assume by default the FPGA is effectively at 0x60 0000 (for > CE3) but how do I place a variable at this address so I can access with a C > instruction. > > Apologies if it's very obvious.Well, you could just set up a suitable structure pointer to that location along the lines of this: typedef struct { short int register_for_this; short int register_for_that; unsigned char register_for_8_bit_stuff; } FPGA_REGS; void my_fpga_reg_routine( void ) { FPGA_REGS regs; regs = (FPGA_REGS *)(0x600000); regs->register_for_this = 0x1234; regs->register_for_that = 0x5678; regs->register_for_8_bit_stuff = 0x9A; } Casey
Reply by ●November 19, 20042004-11-19
Casey said> Fred said > > I am using a version of the TINIm400 and the TINIs400 reference design with > > an FPGA connected to CE3 and CE4. > > > > I wish to access the registers I have placed in the FPGA but am wondering > > how to do it. I assume by default the FPGA is effectively at 0x60 0000 (for > > CE3) but how do I place a variable at this address so I can access with a C > > instruction. > > > > Apologies if it's very obvious. > > Well, you could just set up a suitable structure pointer to that > location along the lines of this: > > typedef struct > { > short int register_for_this; > short int register_for_that; > unsigned char register_for_8_bit_stuff; > } FPGA_REGS; > > > void my_fpga_reg_routine( void ) > { > FPGA_REGS regs;(correction) FPGA_REGS *regs;> regs = (FPGA_REGS *)(0x600000); > > regs->register_for_this = 0x1234; > regs->register_for_that = 0x5678; > regs->register_for_8_bit_stuff = 0x9A; > }Well, that should work a little better .... Casey
Reply by ●November 19, 20042004-11-19
Casey Many thanks for your illustration. I have written the following but I get an error: typedef struct { short int register_for_this; short int register_for_that; unsigned char sdram_reset_reg; } FPGA_REGS; FPGA_REGS *regs; void main() { regs = (FPGA_REGS *)(0x600000); regs->register_for_this = 0x1234; regs->register_for_that = 0x5678; regs->sdram_reset_reg = 0x9A; } on the command line: sdcc -c -mds400 --model-flat24 --stack-10bit --no-xinit-opt main.c I get this error: main.c:13 error: illegal cast of LITERAL value to 'generic' pointer from type 'literal-long-int' to type 'struct __00010000 generic* ' which essentially doesn't like: regs = (FPGA_REGS *)(0x600000); Although I have written a fair amount of code I am not that knowledgable of how to assign a varaible to a location and compilers sometimes treat things differently. This request is perhaps unusual for a 8051 processor which has a 24 bit linear addressing mode.
Reply by ●November 19, 20042004-11-19
Fred said> Casey > > Many thanks for your illustration. I have written the following but I get > an error: > > typedef struct > { > short int register_for_this; > short int register_for_that; > unsigned char sdram_reset_reg; > } FPGA_REGS; > > FPGA_REGS *regs; > > void main() > { > > regs = (FPGA_REGS *)(0x600000); > > regs->register_for_this = 0x1234; > regs->register_for_that = 0x5678; > regs->sdram_reset_reg = 0x9A; > > } > > on the command line: > sdcc -c -mds400 --model-flat24 --stack-10bit --no-xinit-opt main.c > > I get this error: > main.c:13 error: illegal cast of LITERAL value to 'generic' pointer > from type 'literal-long-int' > to type 'struct __00010000 generic* ' > > which essentially doesn't like: > regs = (FPGA_REGS *)(0x600000); > > Although I have written a fair amount of code I am not that knowledgable of > how to assign a varaible to a location and compilers sometimes treat things > differently. This request is perhaps unusual for a 8051 processor which has > a 24 bit linear addressing mode.The 8051 family addressing can be a pain ... you probably need to qualify the type of pointer being created. Your FPGA is probably in xdata memory space. I've never used the SDCC compiler, but you probably need to do something like this to explain that you're creating a pointer to xdata (far) memory: void main() { xdata FPGA_REGS *regs; regs = (xdata FPGA_REGS *)(0x600000); regs->register_for_this = 0x1234; regs->register_for_that = 0x5678; regs->sdram_reset_reg = 0x9A; } If you don't want your pointer as a stack variable for the function, you could move it outside the function and put the pointer itself in xdata space: xdata FPGA_REGS * xdata regs; I did a quick lookup of the SDCC storage classes at: http://tinyurl.com/6tfaa If you haven't already, you might take a look at this app note as well: http://www.maxim-ic.com/appnotes.cfm/appnote_number/3346 Casey
Reply by ●November 19, 20042004-11-19
Fred wrote:> Casey > > Many thanks for your illustration. I have written the following but > I get an error:<snip>> I get this error: > main.c:13 error: illegal cast of LITERAL value to 'generic' pointer > from type 'literal-long-int' > to type 'struct __00010000 generic* ' > > which essentially doesn't like: > regs = (FPGA_REGS *)(0x600000);Try this: xdata at 0x60000 volatile FPGA_REGS * regs;
Reply by ●November 19, 20042004-11-19
Anthony Fremont wrote:> Fred wrote: >> Casey >> >> Many thanks for your illustration. I have written the following but >> I get an error: > <snip> >> I get this error: >> main.c:13 error: illegal cast of LITERAL value to 'generic' pointer >> from type 'literal-long-int' >> to type 'struct __00010000 generic* ' >> >> which essentially doesn't like: >> regs = (FPGA_REGS *)(0x600000); > > Try this: > xdata at 0x60000 volatile FPGA_REGS * regs;After looking at it, that might not work. You may have to specify the size of the regs item. Like this: xdata at 0x600000 volatile UC regs[put size here];
Reply by ●November 22, 20042004-11-22