博客
关于我
Linux中断相关函数
阅读量:504 次
发布时间:2019-03-07

本文共 1393 字,大约阅读时间需要 4 分钟。

request_irq 函数使用说明

函数申请

使用 devm_request_irq 是基于设备树的正式推荐方法。对于传统不支持设备树的内核开发者,可以通过查找 Fayette 的 "irqs.h" 文件获取平台具体中的中断号。支持设备树的内核中,中断号不直接暴露,需通过设备树配置文件获取并映射中断号。

功能概述

request_irq 函数用于申请中断号,注册中断处理函数(handler),并处理相关配置参数。该函数必须与 free_irq 配合使用,确保正确释放占用中的中断号。

功能参数

  • unsigned int irq:申请的硬件中断号。在支持设备树的内核中,需通过 device tree 获取实际使用的中断号。
  • irq_handler_t handler:系统注册的中断处理函数,需在处理完毕后返回 IRQ_HANDLED
  • unsigned long flags:中断处理属性,建议根据具体中断特性选择。支持 flags 值包括 IRQF_SHARED(多个设备共享中断)、IRQF_SAMPLE_RANDOM(有助于随机数生成)等。
  • *const char name:中断名称,通常为设备驱动名称,在 /proc/interrupts 查看确认。
  • *void dev:中断处理函数所关联的设备引用。若不使用,可设为 NULL,但需与 free_irq 对应参数配合使用。

返回值

  • 0:表示申请成功。
  • -EINVAL:参数无效或 handler 函数指针为空。
  • -EBUSY:表示中断号已占用,且不可共享。

使用注意事项

  • 在设备树支持的内核中,勿直接指定硬中断号,需通过 devicetree 映射获取。
  • 设备树中,中断号的获取需注意共享与私有中断的区别。如例子中,i2c0 的中断号为 89,设备树中 interrupt 节点给出的值为 57,需加上 32(共享中断)或 16(私有中断)。

驱动代码示例

static int i2c_probe(struct platform_device *pdev) {    struct device_node *node;    int irq;    node = pdev->node;    irq = platform_get_irq(pdev, 0);    if (irq < 0) {        dev_err(&pdev->dev, "failed to get IRQ number");        return 0;    }    if (request_irq(irq, i2c0_int_irq_handler, IRQF_SHARED, "i2c0-test", &pdev->dev)) {        printk(KERN_DEBUG "request irq failed\n");        return 0;    }    return 0;}

使用建议

  • 设备树支持内核:建议优先使用 irq_desc 数据结构,获取平台具体的中断号。
  • 传统内核处理:对于不支持设备树的内核,仍需手动查找中断号配置文件,或参考底板文档。
  • 中断处理优化:在处理函数中尽量减少延迟,避免占用CPU资源。
  • 通过遵循上述使用规范和注意事项,可以顺利申请和管理硬中断号,确保设备正常运行。

    转载地址:http://umvjz.baihongyu.com/

    你可能感兴趣的文章
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>