User guide

System Generator for DSP User Guide www.xilinx.com 153
UG640 (v 12.2) July 23, 2010
Integrating a Processor with Custom Logic
Single-Word Reads
The following code snippet reads data stored in the "From Register" shared memory
named "fromreg" into "value".
uint32_t empty;
uint32_t value;
xc_iface_t *iface;
xc_from_fifo_t *fromfifo;
// initialize the software driver, assuming the Pcore device ID is 0
xc_create(&iface, &SG_PLBIFACE_ConfigTable[0]);
// obtain the memory location for storing the settings of shared memory
"fromfifo"
xc_get_shmem(iface, "fromreg", (void **) &fromfifo);
// check the "empty" port of shared memory "fromfifo"
do {
xc_read(iface, fromfifo->empty, Ø);
} while (empty == 1);
// read data from the "dout" port of shared memory "fromfifo" and store
at value
xc_read(iface, fromfifo->dout, &value);
Accessing "Shared Memory" Shared Memories
Single-Word Writes
The following code snippet writes "value" to the shared memory named "shram1".
uint32_t value;
xc_iface_t *iface;
xc_shram_t *shram;
// initialize the software driver, assuming the Pcore device ID is 0
xc_create(&iface, &SG_PLBIFACE_ConfigTable[0]);
// obtain the memory location for storing the settings of shared memory
"shram1"
xc_get_shmem(iface, "shram1", (void **) &shram);
// write value to the shared memory "shram1"
xc_write(iface, xc_get_addr(shram->addr, 2), (const unsigned) value);
Single-Word Reads
The following code snippet reads data stored in the shared memory named "shram2" into
"value".
uint32_t value;
xc_iface_t *iface;
xc_shram_t *shram;
// initialize the software driver, assuming the Pcore device ID is 0
xc_create(&iface, &SG_PLBIFACE_ConfigTable[0]);
// obtain the memory location for storing the settings of shared memory
"fromfifo"
xc_get_shmem(iface, "shram2", (void **) &shram);
// read data from the shared memory "shram2" and store at value
xc_read(iface, xc_get_addr(shram->addr, 2), &value);