zynq Linux软件中断,zynq linux驱动之PL-PS中断【转】
PC:Windows 10
虛擬機(jī):ubuntu 16.04
vivado:2017.04
的的PetaLinux:2017.04
開(kāi)發(fā)板:黑金AX7010
根文件系統(tǒng):debian8
-------------------------------------------------- --------------------傳說(shuō)中的分割線------------------------- -------------------------------------------------- ----
將? zynq linux驅(qū)動(dòng)之傳統(tǒng)開(kāi)發(fā) ?里的vivado工程另存為interrupt7010
接下來(lái)配置一下中斷
這里會(huì)出現(xiàn)中斷的接口
接下來(lái)添加一個(gè)引腳
連起來(lái)
重新生成一下頂層文件
打開(kāi)頂層文件,加一個(gè)非門(mén)(因?yàn)镻S這邊貌似只支持上升沿中斷和高電平中斷)
在約束文件里面添加觸發(fā)IRQ的引腳(這里用的是KEY4,HDMI座子旁邊的那個(gè)按鍵)
執(zhí)行生成位文件
結(jié)束之后將原來(lái)的SDK目錄刪掉
重新導(dǎo)入硬件和位文件之后打開(kāi)SDK
將該文件夾拷貝到Ubuntu的里
使用的PetaLinux編譯fsbl,u-boot的,內(nèi)核,設(shè)備樹(shù)文件:
過(guò)程略.....
用的PetaLinux制作BOOT.BIN文件,將BOOT.BIN,image.ub,system.dtb文件拷貝到SD卡的胖分區(qū)里(這里沒(méi)有用的PetaLinux生成的根文件系統(tǒng),用的是debian8)
接下來(lái)打開(kāi)數(shù)據(jù)表
找到中斷號(hào)是61
然后先到開(kāi)板上看一下
cat /proc/interrupts
再看看數(shù)據(jù)表上
沒(méi)有問(wèn)題中斷號(hào)都對(duì)得上
然后再來(lái)看看設(shè)備樹(shù)
vim components/plnx_workspace/device-tree/device-tree-generation/zynq-7000.dtsi
發(fā)現(xiàn)這里的中斷號(hào)跟數(shù)據(jù)表和/ PROC /中斷里面的對(duì)不上
仔細(xì)觀察發(fā)現(xiàn)設(shè)備樹(shù)里面的中斷號(hào)是數(shù)據(jù)表上的中斷號(hào)減去32得到的值
接下來(lái)仿照這個(gè)寫(xiě)一個(gè)自己的
vim project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
/include/ "system-conf.dtsi"
/ {
amba_pl: amba_pl{
#address-cells = <1>;
#size-cells = <1>;
compatible = "simple-bus";
ranges;
irq: irq@0{
compatible = "hello,irq";
interrupt-parent = ;
interrupts = <0 29 2>;
};
};
};
執(zhí)行的PetaLinux建造編譯
編譯完成之后
到開(kāi)發(fā)板上,掛接NFS文件系統(tǒng),然后把編譯好的設(shè)備樹(shù)文件(system.dts)拷貝到開(kāi)發(fā)板SD卡的脂肪分區(qū)里,重啟開(kāi)發(fā)板
ls /proc/device-tree/amba_pl/
可以看到設(shè)備樹(shù)節(jié)點(diǎn)增加了IRQ @ 0
編寫(xiě)驅(qū)動(dòng):
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include /* error codes */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//
static char devname[16];
static int major;
static int mijor;
static struct class* cls;
static void __iomem* base_address;
static resource_size_t remap_size;
static int irq;
static struct device* dev;
//
#define DEVICE_NAME "irq_drv"
static volatile int irq_is_open = 0;
static struct fasync_struct *irq_async;
static int irq_drv_open(struct inode *Inode, struct file *File)
{
irq_is_open = 1;
return 0;
}
int irq_drv_release (struct inode *inode, struct file *file)
{
irq_is_open = 0;
return 0;
}
static ssize_t irq_drv_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
return 0;
}
static ssize_t irq_drv_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
return 0;
}
static int irq_drv_fasync (int fd, struct file *filp, int on)
{
return fasync_helper (fd, filp, on, &irq_async);
}
static struct file_operations irq_fops = {
.owner = THIS_MODULE,
.open = irq_drv_open,
.read = irq_drv_read,
.write = irq_drv_write,
.fasync = irq_drv_fasync,
.release = irq_drv_release,
};
static irqreturn_t irq_interrupt(int irq, void *dev_id)
{
printk("irq = %d\n", irq);
if(irq_is_open)
{
kill_fasync (&irq_async, SIGIO, POLL_IN);
}
return IRQ_HANDLED;
}
static int irq_probe(struct platform_device *pdev)
{
int err;
struct device *tmp_dev;
memset(devname,0,16);
strcpy(devname, DEVICE_NAME);
major = register_chrdev(0, devname, &irq_fops);
cls = class_create(THIS_MODULE, devname);
mijor = 1;
tmp_dev = device_create(cls, &pdev->dev, MKDEV(major, mijor), NULL, devname);
if (IS_ERR(tmp_dev)) {
class_destroy(cls);
unregister_chrdev(major, devname);
return 0;
}
irq = platform_get_irq(pdev,0);
if (irq <= 0)
return -ENXIO;
dev = &pdev->dev;
err = request_threaded_irq(irq, NULL,
irq_interrupt,
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
devname, NULL);
if (err) {
printk(KERN_ALERT "irq_probe irq error=%d\n", err);
goto fail;
}
else
{
printk("irq = %d\n", irq);
printk("devname = %s\n", devname);
}
//保存dev
//platform_set_drvdata(pdev, &xxx);
return 0;
fail:
free_irq(irq, NULL);
device_destroy(cls, MKDEV(major, mijor));
class_destroy(cls);
unregister_chrdev(major, devname);
return -ENOMEM;
}
static int irq_remove(struct platform_device *pdev)
{
device_destroy(cls, MKDEV(major, mijor));
class_destroy(cls);
unregister_chrdev(major, devname);
free_irq(irq, NULL);
printk("irq = %d\n", irq);
return 0;
}
static int irq_suspend(struct device *dev)
{
return 0;
}
static int irq_resume(struct device *dev)
{
return 0;
}
static const struct dev_pm_ops irq_pm_ops = {
.suspend = irq_suspend,
.resume = irq_resume,
};
//MODULE_DEVICE_TABLE(platform, irq_driver_ids);
static const struct of_device_id irq_of_match[] = {
{.compatible = "hello,irq" },
{ }
};
MODULE_DEVICE_TABLE(of, irq_of_match);
static struct platform_driver irq_driver = {
.probe = irq_probe,
.remove = irq_remove,
.driver = {
.owner = THIS_MODULE,
.name = "irq@0",
.pm = &irq_pm_ops,
.of_match_table = irq_of_match,
},
};
module_platform_driver(irq_driver);
MODULE_LICENSE("GPL v2");
Makefile文件:
export ARCH=arm
KERN_DIR = /home/zynq/work/kernel/linux-4.9
all:
make -C $(KERN_DIR) M=`pwd` modules
clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order
obj-m += irq_drv.o
編譯驅(qū)動(dòng)
開(kāi)發(fā)板掛接NFS文件系統(tǒng),加載驅(qū)動(dòng)
然后按一下按鍵,內(nèi)核就能打印出IRQ
編寫(xiě)測(cè)試程序:
#include
#include
#include
#include
#include
#include
#include
#include
#include
int fd;
void my_signal_fun(int signum)
{
printf("irq app printf!\n");
}
int main(int argc, char **argv)
{
unsigned char key_val;
int ret;
int Oflags;
signal(SIGIO, my_signal_fun);
fd = open("/dev/irq_drv", O_RDWR);
if (fd < 0)
{
printf("can't open!\n");
}
fcntl(fd, F_SETOWN, getpid());
Oflags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, Oflags | FASYNC);
while (1)
{
sleep(1000);
}
return 0;
}
編譯
arm-linux-gnueabihf-gcc -o irq irq.c
回到開(kāi)發(fā)板運(yùn)行測(cè)試程序
按下按鍵之后能夠看到內(nèi)核和測(cè)試程序的打印信息
---------------------
作者:h244259402
來(lái)源:CSDN
原文:https://blog.csdn.net/h244259402/article/details/83993524
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)附上博文鏈接!
總結(jié)
以上是生活随笔為你收集整理的zynq Linux软件中断,zynq linux驱动之PL-PS中断【转】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 马光远:“全球最贵股市”是一针清醒剂
- 下一篇: RC5T620-1017电源管理IC规格