FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > FPGA

FPGA comp.arch.fpga newsgroup (usenet)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-13-2005, 11:20 AM
Marco
Guest
 
Posts: n/a
Default Troubles when mapping registers into microblaze address space

Hallo,
I have developed an opb spi 16 bit peripheral with regiter support to
interface it to bus.

Here c code:

unsigned int (*control_reg) = (unsigned
int(*))XPAR_OPB_SPI_16_BIT_0_BASEADDR + OPB_SPI_16_BIT_SLAVE_REG2_OFFSET;


int main (void) {

(*control_reg) = 10;


xil_printf("%X %X\n", &(*control_reg), XPAR_OPB_SPI_16_BIT_0_BASEADDR +
OPB_SPI_16_BIT_SLAVE_REG2_OFFSET);


Using "unsigned int" the two address to be printed don't match. If I use
"unsigned char" they match, but in this way I truncate some datas because
they are 16 bit registers.

What could I do?

Many Thanks
Marco



Reply With Quote
  #2 (permalink)  
Old 08-13-2005, 01:28 PM
Marco
Guest
 
Posts: n/a
Default Re: Troubles when mapping registers into microblaze address space

I solved a part of my trouble.

Here the c code:

#define OPB_SPI_16_BIT_SLAVE_REG0 (XPAR_OPB_SPI_16_BIT_0_BASEADDR +
OPB_SPI_16_BIT_SLAVE_REG0_OFFSET)
#define OPB_SPI_16_BIT_SLAVE_REG1 (XPAR_OPB_SPI_16_BIT_0_BASEADDR +
OPB_SPI_16_BIT_SLAVE_REG1_OFFSET)
#define OPB_SPI_16_BIT_SLAVE_REG2 (XPAR_OPB_SPI_16_BIT_0_BASEADDR +
OPB_SPI_16_BIT_SLAVE_REG2_OFFSET)

unsigned int (*buffer_rx) = (unsigned int(*))OPB_SPI_16_BIT_SLAVE_REG0;
unsigned int (*buffer_tx) = (unsigned int(*))OPB_SPI_16_BIT_SLAVE_REG1;
unsigned int (*control_reg) = (unsigned int(*))OPB_SPI_16_BIT_SLAVE_REG2;


int main (void) {

(*control_reg) = 125;

xil_printf("%d\n", (*control_reg));
xil_printf("%d\n",
OPB_SPI_16_BIT_mReadSlaveReg2(XPAR_OPB_SPI_16_BIT_ 0_BASEADDR));


Now I should see:
125
125

Instead, even if now the address of (*control_reg) seems to be correct, I
see:
125
0

What could I do?

Many Thanks
Marco


Reply With Quote
  #3 (permalink)  
Old 08-13-2005, 05:25 PM
Guest
 
Posts: n/a
Default Re: Troubles when mapping registers into microblaze address space

> Here c code:
>
> unsigned int (*control_reg) = (unsigned int(*))XPAR_OPB_SPI_16_BIT_0_BASEADDR + OPB_SPI_16_BIT_SLAVE_REG2_OFFSET;
>
> int main (void) {
> (*control_reg) = 10;
> xil_printf("%X %X\n", &(*control_reg), XPAR_OPB_SPI_16_BIT_0_BASEADDR + OPB_SPI_16_BIT_SLAVE_REG2_OFFSET);
>
> Using "unsigned int" the two address to be printed don't match. If I use
> "unsigned char" they match, but in this way I truncate some datas because
> they are 16 bit registers.


Hi Marco,

You're doing pointer arithmatic here, which is not the same as just adding
addresses. If you add a number to a pointer of a specific type, the pointer
will be increased by the number times the size of the type.

for example, on a 32 bit system, the following snippet of code

int *p = 100;
p = p + 5;

wil result in p being 120, not 105 as you might expect, since sizeof(int) equals 4, and
100 + (5*4) = 120.

If you want to add a specific number of bytes to a pointer, typecase the
pointer to char before adding :

int *p = 100;
p = (char *)p + 5;

will result in p = 105.

_Ico


--
:wq
^X^Cy^K^X^C^C^C
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mapping Dual Port Ram into Microblaze address space Marco FPGA 3 06-25-2005 03:00 AM
Microblaze address space and variables Marco FPGA 12 06-22-2005 08:17 PM
Address Mapping in 4K RAM Blocks in Altera Cyclone Devices Vazquez FPGA 1 10-31-2003 02:50 PM


All times are GMT +1. The time now is 02:08 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved