Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12612 Discussions

About DMA and user logic ,help!

Altera_Forum
Honored Contributor II
1,028 Views

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/huh.gif Hello.  

I have a DMA controller and LCD controller in my sopc system. LCD controller is adder to system as the user logic. The purpose is to transmit image data to LCD controller via DMA. As a result of the performance, the transmission should be implemented in ISR.  

I use the following code for the task, but the ISR can not work. 

 

 

void init_dma(char *image_addr) 

np_dma *pdma= np_dma; 

alt_irq_register(AVALON_DMA_IRQ, NULL, isr_dma); 

pdma->np_dmacontrol=0; //dma interrupt disable 

pdma->np_dmastatus=0; //clear interrupt status 

pdma->np_dmalength=176*144;//the length of data to transmit 

pdma->np_dmareadaddress=(char)image_addr; 

pdma->np_dmawriteaddress=(int)XVGA_BASE; 

/*pdma->np_dmacontrol= np_dmacontrol_go_mask| 

np_dmacontrol_i_en_mask| 

np_dmacontrol_word_mask| 

np_dmacontrol_ween_mask| 

np_dmacontrol_wcon_mask| 

np_dmacontrol_leen_mask;*/ 

pdma->np_dmacontrol=1;  

 

 

void isr_dma(void* context, alt_u32 id) 

np_dma *pdma; 

np_dma *pdma=(np_dma *)dma; 

if(pdma->np_dmastatus & np_dmastatus_done_mask) 

pdma->np_dmacontrol=0; //disable dma interrupt 

pdma->np_dmastatus=0; //clear dma interrupt status 

pdma->np_dmalength=176*144;  

pdma->np_dmareadaddress=(int)outBuf; 

pdma->np_dmawriteaddress=(int)XVGA_BASE; 

pdma->np_dmacontrol= np_dmacontrol_go_mask| 

np_dmacontrol_i_en_mask| 

np_dmacontrol_word_mask| 

np_dmacontrol_ween_mask| 

np_dmacontrol_wcon_mask| 

np_dmacontrol_leen_mask; 

}
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
312 Views

Hello Yks, 

 

I had to recently design a DMA LCD system. I used the HAL paradigm for the DMA, bascially using the template found in the software guide and a recursive ISR. I borrowed this code from a VGA application and changed a few things for the LCD system. Everything works fine! 

 

Here are the code snippet highlights: 

 

//open the dma channel 

//Set Dma mode transfers 

//Set DMA for streaming 

// queue transfers 

 

// queue the dma transfer to copy frame buffer 

temp = alt_dma_txchan_send ( tx_chan, 

(const void*)(main_frame_buffer), 

(( PIX_MAP_WIDTH * PIX_MAP_HEIGHT ) + PIX_MAP_WIDTH) * 2 * 2, 

(alt_txchan_done *)(vga_dma_done), 

(void*)(&my_isr_context)); 

 

// Where my_isr_context is address of block where your image resides 

 

void vga_dma_done(vga_dma_done_context *context) // VGA DMA ISR 

 

// setup another dma to feed the frame buffer out the vga 

alt_dma_txchan_send ( tx_chan, 

(const void*)(context->frame_buffer_base), 

((PIX_MAP_WIDTH * PIX_MAP_HEIGHT) + PIX_MAP_WIDTH) * 2 *2, 

(alt_txchan_done *)(vga_dma_done), 

(void*)(context)); 

 

// Above function is called recursively. 

 

Two more notes: I used the streaming mode, this works well with the DMA. 

Also, When you design your LCD logic make sure latency is zero. 

 

Hope this helps a bit. 

 

-Baycool
0 Kudos
Altera_Forum
Honored Contributor II
312 Views

Thanks for your replying, baycool ! 

I have tried the code you provided ,but the ISR in my program can not works. I guess the interrupt does not occur.  

And I have two quesstions: 

(1) Is it necessary to post the address of read-slave port and write-slave port to the ISR? 

(2) What is the difference between "main_frame_buffer" and "my_isr_context"? 

 

Thank you again!
0 Kudos
Altera_Forum
Honored Contributor II
312 Views

Hello yks, 

 

To answer your questions. 

 

1. No, The code that I showed only needs to show where the read address is located( Like the array holding your image) 

2. My code is a little convoluted but essentially I am passing a structure to vga_dma_done called vga_dma_done_context. 

This structure has an element that I am defining as the array for my_isr_context, which is the address that I want my function to implement 

when the fuction vga_dma_done is called, which is really just the completion of the DMA access, which is alt_dma_txchan_done. 

 

I know that sounds a little "wordy"; But reply if you have more questions and I would be glad to help... 

 

Really, what is happening is that it is hard to get real-time control while the DMA function is running, that is why I think it is hard to implement an ISR. I tried earlier this year to measure performance of this system with timestamps and I had a real mess. Of course, I may have self-inflicted harm on myself when trying to make those measurements. 

 

-Baycool
0 Kudos
Altera_Forum
Honored Contributor II
312 Views

Hi guys. 

Is there someone who could help me about DMA use? 

I need to transfer images from a Camera C3088 to memory (DDR / SSRAM) 

I have a look to Portable Reference Platform and i decided to use camera_if and camera_dma block. 

Even if this project it&#39;s for a VGA camera, making some changes do you think that should function,or it&#39;s better use dma block by Altera available in SOPC? 

Many thanks 

Paolo
0 Kudos
Reply