Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Strange error with NIOS2 DMA ..

hello to everyone i am trying to make my DMA read from a PIO and write in a SDRAM

This is my adapted code to do this

Code:

#include <stdio.h>

#include <stdlib.h>

#include <stddef.h>

#include <string.h>

#include <system.h>

#include <io.h>

#include <alt_types.h>

#include "sys/alt_dma.h"

#include "sys/alt_cache.h"

#include "sys/alt_alarm.h"

#include "alt_types.h"

int i;

static volatile int txrx_done = 0;

//callback function when DMA transfer done

static void txrxDone(void * handle, void * data)

{

txrx_done = 1;

}

void initMEM(int base_addr,int len)

{

for ( i=0;i<len;i++)

{

IOWR_8DIRECT(base_addr,i,i);

}

}

int main()

{

printf("testing onchip & sdram : dma operation\n");

alt_16 buffer[10];

//memset((void *)SSRAM_0_BASE,0x7a,0x10);//this write base on byte

// initMEM(ONCHIP_MEMORY2_1_BASE,0x10);

memset((void *)(SDRAM_0_BASE),0x33,0x10);

printf("content of onchip:before DMA operation\n");

for ( i=0;i<0x10;i++)

{

printf("%d: %x\n",i,IORD_8DIRECT(DMA_0_READ_MASTER_ENTRADA_FIFO_BASE,i));

}

printf("content of sdram_1:before DMA operation\n");

for ( i=0;i<0x10;i++)

{

printf("%d: %x\n",i,IORD_8DIRECT(SDRAM_0_BASE,i));

}

int rc; //request

alt_dma_txchan txchan;

alt_dma_rxchan rxchan;

void* tx_data = (void*)DMA_0_READ_MASTER_ENTRADA_FIFO_BASE; /* pointer to data to send */

void* rx_buffer = (void*)(SDRAM_0_BASE); /* pointer to rx buffer */

/* Create the transmit channel */

if ((txchan = alt_dma_txchan_open("/dev/dma_0")) == NULL)

{

printf ("Failed to open transmit channel\n");

exit (1);

}

/* Create the receive channel */

if ((rxchan = alt_dma_rxchan_open("/dev/dma_0")) == NULL)

{

printf ("Failed to open receive channel\n");

exit (1);

}

/* Post the transmit request */

if ((rc = alt_dma_txchan_send (txchan,

tx_data,

0x10,

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,

rx_buffer,

0x10,

txrxDone,

NULL)) < 0)

{

printf ("Failed to post read request, reason = %i\n", rc);

//exit (1);

}

/* wait for transfer to complete */

while (!txrx_done);

printf ("Transfer successful!\n");

printf("content of onchip:after DMA operation\n");

for ( i=0;i<0x10;i++)

{

printf("%d: %x\n",i,IORD_8DIRECT(DMA_0_READ_MASTER_ENTRADA_FIFO_BASE,i));

}

printf("content of sdram_1:after DMA operation\n");

for ( i=0;i<0x10;i++)

{

printf("%d: %x\n",i,IORD_8DIRECT(SDRAM_0_BASE,i));

}

return 0;

}

this is my output

[code]

it starts reading from my SDRAM (1: FF, 2:FF..)but when it reads the fitfh addres it starts to appear [][][][][][[][][][][][][][][[][][][][][][][][[][][] .. etc

really weird.. what could it be

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I've changed

    
      /* Post the transmit request */
        if ((rc = alt_dma_txchan_send (txchan,
                tx_data,
                0x00,
                NULL,
                NULL)) < 0)

    And now it is reading, i guess since my PIO had no other adress after the base it got lost..

    It isnt working as it should throught.

    My PIO has FF in all adresses and my SDRAM is changing the value only after the 7th adress!

    PIO:

    1. ff

    2.ff

    3.ff

    SDRAM should be like the PIO but instead it is like that after the transaction:

    1. old value

    2.old value

    3..4..

    5.33

    6.33

    7.33

    8.33

    .. untill 15.33

    Any ideas? 33 may be correct if the width of the bits are different i guess.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    That's normal: you have put zero DMA data length, then you have no DMA transfer at all.

    As I told you in the other thread you must set the RCON control bit instead.

    Cris
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok, but why did the values change in the sdram then?

    And how can i set that control bit? (I am new to embedded software :( )

    Thanks a lot for answering Cris
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Cris i must set the RCON bit then i shouldnt use transmit and recieve request? Please enlight me heh .. the transfer isnt happening at all from PIO to SDRAM.

    thanks