Создал следующий проект:
SOPC: пробовал два варианта (из примера для DDR2):
и
подключил полученный компонент в проект квартуса, подцепил все внешние ноги.
Создал проект в Ниосе, с-код (на основе примера):
Код
#include "count_binary.h"
static volatile int rx_done = 0;
static void dma_done (void* handle, void* data)
{
rx_done++;
}
static void set_leds(alt_u8 data)
{
alt_u8 b = data;
/* Logic to make the LEDs count from right-to-left,
LSB on the right. */
IOWR_ALTERA_AVALON_PIO_DATA(
PIO_BASE,
((b * 0x0802LU & 0x22110LU) |
(b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16
);
}
int main(void)
{
alt_u64 w;
alt_u64 r;
int rc;
int pattern, offset;
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
void* data_written;
void* data_read;
int compare;
/* Get a couple buffers for the test */
data_written = (void*)alt_uncached_malloc(0x1000);
data_read = (void*)alt_uncached_malloc(0x1000);
set_leds(0x0f);
usleep(100000);
set_leds(0xf0);
printf("leds ok...\n");
w = 0xf0f0f0f0;
IOWR(DMA_WRITE_MASTER_ALTMEMDDR_BASE,0,w);
r = IORD(DMA_READ_MASTER_ALTMEMDDR_BASE,0);
printf("%x\n",r);
/* Fill write buffer with known values */
for (pattern = 1, offset = 0; offset < 0x1000; pattern++, offset+=4)
{
IOWR_32DIRECT((int)data_written, offset, pattern);
}
/* Create the transmit channel */
if ((txchan = alt_dma_txchan_open("/dev/dma")) == NULL)
{
printf ("Failed to open transmit channel\n");
exit (1);
}
/* Create the receive channel */
if ((rxchan = alt_dma_rxchan_open("/dev/dma")) == NULL)
{
printf ("Failed to open receive channel\n");
exit (1);
}
//--------------------------------------------
/* Use DMA to transfer from write buffer to memory under test */
/* Post the transmit request */
if ((rc = alt_dma_txchan_send(txchan, data_written, 0x1000, NULL, NULL)) < 0)
{
printf ("Failed to post transmit request, reason = %i\n", rc);
exit (1);
}
/* Post the receive request */
if ((rc = alt_dma_rxchan_prepare(rxchan, (void*)DMA_WRITE_MASTER_ALTMEMDDR_BASE, 0x1000, dma_done, NULL)) < 0)
{
printf ("Failed to post read request, reason = %i\n", rc);
exit (1);
}
/* Wait for transfer to complete */
printf("wait rx_done...\n");
while (!rx_done);
printf("rx_done is here\n");
rx_done = 0;
/* Clear the read buffer before we fill it */
memset(data_read, 0, 0x1000);
/* Use DMA to read data back into read buffer from memory under test */
/* Post the transmit request */
if ((rc = alt_dma_txchan_send(txchan, (void*)DMA_READ_MASTER_ALTMEMDDR_BASE, 0x1000, NULL, NULL)) < 0)
{
printf ("Failed to post transmit request, reason = %i\n", rc);
exit (1);
}
/* Post the receive request */
if ((rc = alt_dma_rxchan_prepare(rxchan, data_read, 0x1000, dma_done, NULL)) < 0)
{
printf ("Failed to post read request, reason = %i\n", rc);
exit (1);
}
/* Wait for transfer to complete */
printf("wait rx_done...\n");
while (!rx_done);
printf("rx_done is here\n");
rx_done = 0;
compare = memcmp(data_written, data_read, 0x1000);
printf("compare = %i\n",compare);
//--------------------------------------------
alt_uncached_free(data_written);
alt_uncached_free(data_read);
return 0;
}
После запуска проекта на кристалле (StratixIV GX) в консоли печатается следующее:
leds ok... (это просто моргание лампочками для визуализации начала работы)
ffffffff (это результат выполнения
printf("%x\n",r);)
wait rx_done... (после выполнения первого
alt_dma_rxchan_prepare(...)) - на этом всё заканчивается.
Подключил СигналТап и получаю картинку:
на которой видно, что адрес=0, local_size почему-то =1(??), а данные тоже = 0.
Подскажите, что я делаю не так? Ну и просто можно прокомментировать получившийся проект.
Сообщение отредактировал billidean - Dec 1 2011, 05:38