FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > FPGA

FPGA comp.arch.fpga newsgroup (usenet)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2008, 07:58 AM
[email protected]
Guest
 
Posts: n/a
Default regarding DMA memory to memory copy in NIOS II

here is my codes. I want to verify the result and display at the end,
however I got like "cdcd", what's wrong? thanks


/*
* "Hello World" example.
*
* This example prints 'Hello from Nios II' to the STDOUT stream. It
runs on
* the Nios II 'standard', 'full_featured', 'fast', and 'low_cost'
example
* designs. It runs with or without the MicroC/OS-II RTOS and requires
a STDOUT
* device in your system's hardware.
* The memory footprint of this hosted application is ~69 kbytes by
default
* using the standard reference design.
*
* For a reduced footprint version of this template, and an
explanation of how
* to reduce the memory footprint for a given application, see the
* "small_hello_world" template.
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/alt_dma.h>
#include "system.h"

static volatile int rx_done = 0;

/*
* Callback function that obtains notification that the data has
* been received.
*/
static void done (void* handle, void* data)
{
rx_done++;
}

int main(int argc, char* argv[], char* envp[])
{
int rc;
static char buff[256]="abcdefghijklmn\0";
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;

void* tx_data = (void*) buff; /* pointer to data to
send */
void* rx_buffer = (void*) 0x01000000; /* on_chip_memory addr*/


/* 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,128,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,128,done,NULL)) <
0)
{
printf ("Failed to post read request, reason = %i\n", rc);
exit (1);
}

/* wait for transfer to complete */
while (!rx_done);
printf ("Transfer successful!\n");
printf ("%s",(ONCHIP_MEMORY_0_BASE));
return 0;
}
Reply With Quote
  #2 (permalink)  
Old 01-29-2008, 02:04 PM
Górski Adam
Guest
 
Posts: n/a
Default Re: regarding DMA memory to memory copy in NIOS II

[email protected] pisze:
> here is my codes. I want to verify the result and display at the end,
> however I got like "cdcd", what's wrong? thanks
>
>
> /*
> * "Hello World" example.
> *
> * This example prints 'Hello from Nios II' to the STDOUT stream. It
> runs on
> * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost'
> example
> * designs. It runs with or without the MicroC/OS-II RTOS and requires
> a STDOUT
> * device in your system's hardware.
> * The memory footprint of this hosted application is ~69 kbytes by
> default
> * using the standard reference design.
> *
> * For a reduced footprint version of this template, and an
> explanation of how
> * to reduce the memory footprint for a given application, see the
> * "small_hello_world" template.
> *
> */
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/alt_dma.h>
> #include "system.h"
>
> static volatile int rx_done = 0;
>
> /*
> * Callback function that obtains notification that the data has
> * been received.
> */
> static void done (void* handle, void* data)
> {
> rx_done++;
> }
>
> int main(int argc, char* argv[], char* envp[])
> {
> int rc;
> static char buff[256]="abcdefghijklmn\0";
> alt_dma_txchan txchan;
> alt_dma_rxchan rxchan;
>
> void* tx_data = (void*) buff; /* pointer to data to
> send */
> void* rx_buffer = (void*) 0x01000000; /* on_chip_memory addr*/
>
>
> /* 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,128,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,128,done,NULL)) <
> 0)
> {
> printf ("Failed to post read request, reason = %i\n", rc);
> exit (1);
> }
>
> /* wait for transfer to complete */
> while (!rx_done);
> printf ("Transfer successful!\n");
> printf ("%s",(ONCHIP_MEMORY_0_BASE));
> return 0;
> }

What is set in system configuration ?

Adam
Reply With Quote
  #3 (permalink)  
Old 01-30-2008, 12:20 AM
Mark McDougall
Guest
 
Posts: n/a
Default Re: regarding DMA memory to memory copy in NIOS II

[email protected] wrote:

> here is my codes. I want to verify the result and display at the end,
> however I got like "cdcd", what's wrong? thanks


You need to ensure that the memory involved in the transfer is not cached
- you can simply set bit 31 of the address to bypass the NIOS cache. I use
a macro thusly:
#define UNCACHED(addr) ((1<<31)|(addr))

What's the width on your DMA register? Not 7 bits I hope! :O

You also use 0x01000000 for the rx_buffer yet you're printing the contents
of INCHIP_MEMORY_0_BASE, which IMHO is bad practise.

Otherwise it looks OK to me...

Regards,

--
Mark McDougall, Engineer
Virtual Logic Pty Ltd, <http://www.vl.com.au>
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
Reply With Quote
  #4 (permalink)  
Old 01-30-2008, 04:58 AM
[email protected]
Guest
 
Posts: n/a
Default Re: regarding DMA memory to memory copy in NIOS II

quartus II sopc builder, jtag debugging mode, tri-state avalon bridge,
sdram, on-chip ram, etc



On Jan 29, 5:04 am, Górski Adam
<gorskia@.................wp....................pl ..................>
wrote:
> BigJames...@gmail.com pisze:
>
> > here is my codes. I want to verify the result and display at the end,
> > however I got like "cdcd", what's wrong? thanks

>
> > /*
> > * "Hello World" example.
> > *
> > * This example prints 'Hello from Nios II' to the STDOUT stream. It
> > runs on
> > * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost'
> > example
> > * designs. It runs with or without the MicroC/OS-II RTOS and requires
> > a STDOUT
> > * device in your system's hardware.
> > * The memory footprint of this hosted application is ~69 kbytes by
> > default
> > * using the standard reference design.
> > *
> > * For a reduced footprint version of this template, and an
> > explanation of how
> > * to reduce the memory footprint for a given application, see the
> > * "small_hello_world" template.
> > *
> > */

>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <sys/alt_dma.h>
> > #include "system.h"

>
> > static volatile int rx_done = 0;

>
> > /*
> > * Callback function that obtains notification that the data has
> > * been received.
> > */
> > static void done (void* handle, void* data)
> > {
> > rx_done++;
> > }

>
> > int main(int argc, char* argv[], char* envp[])
> > {
> > int rc;
> > static char buff[256]="abcdefghijklmn\0";
> > alt_dma_txchan txchan;
> > alt_dma_rxchan rxchan;

>
> > void* tx_data = (void*) buff; /* pointer to data to
> > send */
> > void* rx_buffer = (void*) 0x01000000; /* on_chip_memory addr*/

>
> > /* 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,128,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,128,done,NULL)) <
> > 0)
> > {
> > printf ("Failed to post read request, reason = %i\n", rc);
> > exit (1);
> > }

>
> > /* wait for transfer to complete */
> > while (!rx_done);
> > printf ("Transfer successful!\n");
> > printf ("%s",(ONCHIP_MEMORY_0_BASE));
> > return 0;
> > }

>
> What is set in system configuration ?
>
> Adam


Reply With Quote
  #5 (permalink)  
Old 01-30-2008, 01:30 PM
Górski Adam
Guest
 
Posts: n/a
Default Re: regarding DMA memory to memory copy in NIOS II

[email protected] pisze:
> quartus II sopc builder, jtag debugging mode, tri-state avalon bridge,
> sdram, on-chip ram, etc
>

Not in quartus.
NIOS IDE -> Project -> System lib config

Adam
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nios memory cruzin FPGA 0 01-14-2004 01:36 AM
verilog memory array copy Nahum Barnea Verilog 1 01-07-2004 10:49 PM
Memory map for Nios Maxlim FPGA 0 08-06-2003 05:33 PM


All times are GMT +1. The time now is 02:50 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved