Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
936 Views

DMA & Interrupt Problems...

I'm a newbie in Nios, and my English is not to good, but in this forum i found some topics to control NiosII device like pio, timer, uart by Nios syntax, but few topic about to teach me about dma & interrupt, so when i want to control dma & interrupt, i can't do it , and i found in kernel's system.h file didn't have include about this file, now i am so confuse , maybe i am wrong way to control it , so i think maybe it need to use uclinux syntax to control the device , not use nios syntax, but i really don't know what show i do , could anyone can give me some suggests or example to that me know what to do. Thank you.

0 Kudos
9 Replies
Highlighted
Valued Contributor III
4 Views

I haven't tested DMA myself but for IRQ you can just use the linux kernel functions.  

With a call to request_irq you can register your Interrupt service routine.  

Make sure to do this from kernel-space (a kernel module or compiled in the kernel) "normal" userspace programs can't (and shouldn't) recieve IRQ's. 

 

Iirc someone on this forum uses the kernel functions for DMA-transfers, maybe you can find the thread. 

 

Greetz wgoossens 

 

P.S.: Don't worry about your english!
0 Kudos
Highlighted
Valued Contributor III
4 Views

Hi,  

 

a little code snippet to play with dma. it works in userspace without an interrupt. This is dirty style and works without Kernel and interrupt. If you understand (read the dma chapter in the pdf about the peripheral) how it works, it will be easy to do this with kernel functions in a driver. You can find the kernel functions in 

$(KERNEL_PLUGIN)\linux-2.6.x\arch\nios2nommu\kernel\dma.c 

 

 

#define na_dma_0                                 0x12345678# define inl(addr)   ({              unsigned int __res;  __asm__ __volatile__(    "ldwio %0, 0(%1)"    : "=r"(__res)    : "r" (addr));    __res;         }) //----------------------------------------------------------------------- # define outl(b,addr)   ({              __asm__ __volatile__(    "stwio %0, 0(%1)"    : : "r"(b), "r" (addr));   }) void testdma (int source, int dest) {        outl (0,na_dma_0);        outl (0,na_dma_0+24);        outl (source,na_dma_0+4);        outl (dest,na_dma_0+8);        outl (1472,na_dma_0+12);        outl (0x8c,na_dma_0+24);        while (inl(na_dma_0)==0x2);   } 

 

replace in the snippet 0x12345678 with the address of your dma controller
0 Kudos
Highlighted
Valued Contributor III
4 Views

Thank you for replay, i think i know the way to solve thoses quests, but i wnat include the <linux/sched.h> to run linux kernel function but i can&#39;t complier it  

because it can&#39;t found the autoconf.h file so i can&#39;t complier it, maybe i include wrong header file ,so i want to knwo if i want to use interrupt & dma llinux kernel function what header files should i include? can help me ? thanks..
0 Kudos
Highlighted
Valued Contributor III
4 Views

Do you want to write a driver?

0 Kudos
Highlighted
Valued Contributor III
4 Views

I think i&#39;m not to write a driver, i just want to use this like use nios syntax. 

For example, in nios i can add some pios , button , timer , dma and use interrupt by my control program , because in nios syntax , it have function to control it, but  

in nios uclinux , i also can add what i wnat in sopc builder and to control it by nios  

syntax , but just ISR and dma i can&#39;t use nios syntax to control , i just want to know how can i to control interrupt & dma function (pio isr, timer isr, uart isr and dma), i don&#39;t know i&#39;m writing a driver now?
0 Kudos
Highlighted
Valued Contributor III
4 Views

Well, 

 

i ask this question, because i&#39;m confused. 

 

basicly under linux, there a two type of "programs". 

 

1) a normal application: a normal application doesn&#39;t access the hardware directly or uses kernel functions. it will use a driver -> system calls (program runs in user-space). 

if try to access kernel functions from an application i don&#39;t know. you might have to trick a lot. 

 

you can try to register the interrupt manually without linux (study the altera hal sources).  

 

2) a kernel module ("driver") gets direct access to the hardware and can use kernel function, so i was thinking you are going to write a driver...
0 Kudos
Highlighted
Valued Contributor III
4 Views

If you want to handle irq or dma on Linux, you are writing drivers or doing module programming in kernel space. You MUST NOT mix HAL and Linux. 

Read ch10 about irq and ch15 about dma on the book, " Linux device driver 3rd Ed."
0 Kudos
Highlighted
Valued Contributor III
4 Views

TO_BE_DONE

0 Kudos
Highlighted
Valued Contributor III
4 Views

Hi ucliane, 

 

It is great that you read the LDD book. 

It seems you mixed up the kernel space and user space. 

Please read LDD from beginning. 

 

Another (old) advice, do it on Linux. follow the thread 

http://forum.niosforum.com/forum/index.php?showtopic=3174 (http://forum.niosforum.com/forum/index.php?showtopic=3174

 

Then, you should try out the hello world module in ch2 of LDD. 

 

Next, take a look at some kernel codes, eg,  

arch/nios2nommu/kernel/time.c 

drivers/serial/NIOSserial.c . 

 

Finally back to your own code.
0 Kudos