DS80C400 and memory space with the SDCC compiler

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.

Reply to
Fred
Loading thread data ...

Fred said

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 to
Casey

Casey said

(correction)

FPGA_REGS *regs;

Well, that should work a little better ....

Casey

Reply to
Casey

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 to
Fred

Fred said

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:

formatting link

If you haven't already, you might take a look at this app note as well:

formatting link

Casey

Reply to
Casey

Try this: xdata at 0x60000 volatile FPGA_REGS * regs;

Reply to
Anthony Fremont

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 to
Anthony Fremont

Many thanks for the help. This is what I used in the end

xdata at 0x600000 unsigned char sdram_reset_reg;

which work such that I can read and write at this "location" in the FPGA using CS3.

Reply to
Fred

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.