Hi BadOmen,
Thanks a lot for your advice. But could you please go in more details about it? I have read the document and the sgdma seems working through the program below. But still how can I send the data to the hardware? Should I wire some pio to the sgdma?
If possible can you show me some diagram/function call to get the data back to the hardware? Thanks!
This is the program:
int main()
{
int i;
// int timeout=0;
for (i=0;i<1000;i++) // buf initialization
buf[i]=i%256;
desc=(alt_sgdma_descriptor *)ONCHIP_MEM_BASE; // redefine the base address ?
// ***************** open sgdma_tx ********************//
sgdma_tx_dev=alt_avalon_sgdma_open(SGDMA_TX_NAME);
if(!sgdma_tx_dev)
{
printf("ERROR: can't open TX SGDMA");
return -1;
}
// ***************** open sgdma_rx ********************//
sgdma_rx_dev=alt_avalon_sgdma_open(SGDMA_RX_NAME);
if(!sgdma_rx_dev)
{
printf("ERROR: can't open RX SGDMA");
return -1;
}
// ***************** reset RX SGDMA ********************//
IOWR_ALTERA_AVALON_SGDMA_CONTROL(SGDMA_RX_BASE,ALTERA_AVALON_SGDMA_CONTROL_SOFTWARERESET_MSK);
IOWR_ALTERA_AVALON_SGDMA_CONTROL(SGDMA_RX_BASE,0x0);
// ***************** reset TX SGDMA ********************//
IOWR_ALTERA_AVALON_SGDMA_CONTROL(SGDMA_TX_BASE,0); // Why these two are different here?
IOWR_ALTERA_AVALON_SGDMA_CONTROL(SGDMA_TX_BASE,0xFF);
// ***************** register rx callback ********************//
alt_avalon_sgdma_register_callback(
sgdma_rx_dev,
(alt_avalon_sgdma_callback) &sgdma_rx_isr, // ?
(alt_u16) ALTERA_AVALON_SGDMA_CONTROL_IE_DESC_COMPLETED_MSK |
ALTERA_AVALON_SGDMA_CONTROL_IE_CHAIN_COMPLETED_MSK |
ALTERA_AVALON_SGDMA_CONTROL_IE_GLOBAL_MSK,
0
);
// ***************** construct a descriptor for ST to MM transfer ********************//
alt_avalon_sgdma_construct_stream_to_mem_desc(
&desc[0],
&desc[1],
rx_payload,
0,
0
);
// ***************** construct a descriptor for MM to ST transfer ********************//
alt_avalon_sgdma_construct_mem_to_stream_desc(
&desc[2],
&desc[3],
(unsigned int*) buf,
(256),
0,
1,
1,
0
);
// ***************** start sgdna_rx ********************//
alt_avalon_sgdma_do_async_transfer(sgdma_rx_dev, &desc[0]);
// ***************** start sgdna_tx ********************//
alt_avalon_sgdma_do_sync_transfer(sgdma_tx_dev, &desc[2]);
}