Forum Discussion
How to setup a time interrupt on de10 standard using C language
Hi, I'm a rookie of the SoCFPGA and I wanted to use it to build a FSM in HPS.
I have already finished building the system design as "User Manu" said and get the hps_0.h header file out.
I built my system based on the GHRD, and added a timer(100ms) using the Altera IP.
Now I want to play with it,yet there are little information about a timer or an interrupt working on SOC.
The board I'm using is a DE10-standard board.
Could anyone show me where to start?
And it will be better if you can provide a document/example on how to play with the Altera IP on C.
Thank you for your help.
36 Replies
- tehjingy_Altera
Regular Contributor
Hi Alex
Yes, you are right.
The HWlibs are for baremetal only.
Sorry for assuming you are working on baremetal.
For linux development you could include the linux kernel header
#include <linux/interrupt.h>
You could refer to the example project repo here:
https://github.com/altera-opensource/linux-refdesigns
Regards
Jingyang, Teh
- CAlex
Contributor
Hi,
Thank you very much,
I'll check that ASAP.
reguards.
- tehjingy_Altera
Regular Contributor
Hi Alex
Any update on this case?
Regards
Jingyang, Teh
- CAlex
Contributor
Hi,
still trying to understand what happened in the kernel, also I tried to make the KML but there are some part missing on my SD card. The Kernel source can't be found in /usr/src menu and now I'm trying to build another sdcard and hope the source code is in the path I hoped.
I'll update the case when I get some progress.
Thank you for your help.
reguards.
- tehjingy_Altera
Regular Contributor
Hi Alex
What do you mean the KML?
Could you explain more what error you got or what you are trying to achive?
Regards
Jingyang, Teh
- CAlex
Contributor
Hi,
My bad,
I mean I'm trying to use <linux/interrupt.h> but it seems can't call in user space code. I supposed to be done in Linux Kernel module.
So I want to use the kernel source code to compile my kernel module.
What I need for the compile is the kernel source code supposed located on /usr/src/$(uname -r).
Yet it is empty, so I download the Kernel source code and make it as zImage as my embedded system did.
What I want to know is that is there an easier way to compile the KML(I mean kernel module)?
Or can <linux/interrupt.h> can be used on user space code?
reguards.
- CAlex
Contributor
And what I really confused is that I wrote my own IP device on FPGA, in order to use it in kernel module(basicly it only sends out the interrupt signal to irq_0 every 50 us), what should I do?
Do I need to update the Device Tree and refresh the u-boot?
Do I need to write my own driver for my timer IP?
What should I treat this IP, is it a device_platform?
How to communicate with my user space code. make a char device? Use /proc? Or is there a easy way that can achieve the goal: To tell the userspace it is the time to go.
Sorry for so many questions.
reguards.
- tehjingy_Altera
Regular Contributor
Hi Alex
Sorry for the confusion.
We could not register a call back directly from hardware.
You would need to create your own kernel driver to send a signal your user application.
In the user application you would wait for the signal from the kernel to handle.
Below are some useful links regarding this :
https://man7.org/linux/man-pages/man7/signal.7.html
Regards
Jingyang, Teh
- tehjingy_Altera
Regular Contributor
Hi Alex
Any update on this case?
Regards
Jingyang, Teh
- CAlex
Contributor
Hi,
Yes, I wrote a kernel module to create an interrupt request.(which should be irq 73)
But I can't insmod the module for stack overflow.
Then I checked the other GIC turtour and it turns to be 72+personal_irq_num-32 = 41.
And when I checked the /proc/interrupt, there is an irq already. I assume it's duel to the DTB setting.
Now I wonder is that means I have to update the DTB file for my linux?
Thank you for all your help by the way.
Having a nice day
Reguards.
- tehjingy_Altera
Regular Contributor
HI Alex
Could you try the GIC number 75?
From your design in previous case. Your interrupt is connected to f2h_iirq0 number 3.
From the GIC table, it should be 75.
Regards
Jingyang, Teh
- CAlex
Contributor
Hi,
when I use 75 as the number in my kernel module,
the insmod failed
insmod: ERROR: could not insert module p3.ko: Invalid parameters
duel to request_irq()
Reguards.
- CAlex
Contributor
Hi,
to make sure we are on the same page,
I attached the kernel module for anyone else want to see what happened on this case.
Reguards.
- CAlex
Contributor
The return Error is -22
Which indicate handler is NULL(checked) or IRQ can't be used.
And when I checked the /proc/interrupts , the result is as followed:
But as the DTB on my board shows,there should be at least 3 FPGA interrupts.
When I use linux module to install the irq, it is not relay on DTB right?
- tehjingy_Altera
Regular Contributor
Hi
Could you try adding the timer into the linux device tree?
I am not quite familiar with linux device tree, but could you try the following:
timer4@FF200000 {
compatible = "snps,dw-apb-timer";
interrupts = <0x0 0x6B 0x4>;
reg = <0xFF200000 0x1F>;
clocks = <0x38>;
};
Regards
Jingyang, Teh