User guide

182 www.xilinx.com System Generator for DSP User Guide
UG640 (v 12.2) July 23, 2010
Chapter 2: Hardware/Software Co-Design
corresponding device software drivers. Right click on sg_plbiface in the System Assembly
View to see its API documentation.
Follow the instructions in the API documentation to include the following header file and
initialize the software driver in MyProject.c.
#include "sg_plbiface.h"
xc_iface_t *iface;
// initialize the software driver
xc_create(&iface, &SG_PLBIFACE_ConfigTable[0]);
Before reviewing the code to run on the processor, first consider how to write data to the a
register on the model. Look at the DSP48 Co-Processor model. Recall that the a port of the
DSP48 block is driven by the output of a shared register by the same name. You want to
write a value to that shared register from with-in MicroBlaze processor code. By referring
to the driver API, you can see that the shared memory called a is a “To Register” memory
type with xc_to_reg_t access data type, which contains the following data fields:
typedef struct {
xc_w_addr_t din;
uint32_t n_bits;
uint32_t bin_pt;
} xc_to_reg_t;
Once the software driver is initialized, din stores the memory-mapped address of the din
port of the shared memory a, while n_bits and bin_pt store the number of bits and
binary point information.
So in order to write a value to the a shared register, you need to first obtain the shared
register settings through xc_get_shmem and thus:
xc_to_reg_t *toreg_a;
xc_get_shmem(iface, "a", (void **) &toreg_a);
Note: Calling xc_get_shmem is expensive. You should cache the returned toreg_a for later use
and avoid calling xc_get_shmem multiple times in a program.