开发平台

  1. * 芯灵思SinlinxA33开发板

淘宝店铺: https://sinlinx.taobao.com/

嵌入式linux 开发板交流 QQ:641395230

本节实验目标实现按键触发中断终端显示按键松开或按下

实验平台 芯灵思Sinlinx A33 开发板

step1 查看原理图,三个按键都连接到LRADC0引脚,通过判断电压大小来确定是按的哪个键。

step2 内核关于 CPU 的中断号linux 中断注册函数中的 irq 中断号并不是芯片物理上的编号,而是由芯片商在移植 Linux 系统时定在构架相

关的头文件中定义好的, 在内核源码中,名字一般是 irqs.h。

打开vim /root/work/sinlinx/a33/lichee/linux-3.4/arch/ARM/mach-sunxi/include/mach/irqs.h

这里全志A33 是#include "sun8i/irqs-sun8iw5p1.h"

打开vim /root/work/sinlinx/a33/lichee/linux-3.4/arch/arm/mach-sunxi/include/mach/sun8i/irqs-sun8iw5p1.h

不知道开发板用的哪个平台,直接在.config中找

由此找到芯片在内核中的中断号

step 3 简要介绍中断驱动要用到的函数

查看 irq.h 文件 里面有关于中断的函数结构体声明 /root/work/sinlinx/a33/lichee/linux-3.4/include/linux/irq.h

  1. * struct irq_data - per irq and irq chip data passed down to chip functions
  2. * @irq: interrupt number
  3. * @hwirq: hardware interrupt number, local to the interrupt domain
  4. * @node: node index useful for balancing
  5. * @state_use_accessors: status information for irq chip functions.
  6. * Use accessor functions to deal with it
  7. * @chip: low level interrupt hardware access
  8. * @domain: Interrupt translation domain; responsible for mapping
  9. * between hwirq number and linux irq number.
  10. * @handler_data: per-IRQ data for the irq_chip methods
  11. * @chip_data: platform-specific per-chip private data for the chip
  12. * methods, to allow shared chip implementations
  13. * @msi_desc: MSI descriptor
  14. * @affinity: IRQ affinity on SMP
  15. *
  16. * The fields here need to overlay the ones in irq_desc until we
  17. * cleaned up the direct references and switched everything over to
  18. * irq_data.
  19. */
  20. struct irq_data {
  21. unsigned int irq;
  22. unsigned long hwirq;
  23. unsigned int node;
  24. unsigned int state_use_accessors;
  25. struct irq_chip *chip;
  26. struct irq_domain *domain;
  27. void *handler_data;
  28. void *chip_data;
  29. struct msi_desc *msi_desc;
  30. #ifdef CONFIG_SMP
  31. cpumask_var_t affinity;
  32. #endif
  33. };

struct irqaction 结构体在 /root/work/sinlinx/a33/lichee/linux-3.4/include/linux/interrupt.h

  1. /**
  2. * struct irqaction - per interrupt action descriptor
  3. * @handler: interrupt handler function
  4. * @flags: flags (see IRQF_* above)
  5. * @name: name of the device
  6. * @dev_id: cookie to identify the device
  7. * @percpu_dev_id: cookie to identify the device
  8. * @next: pointer to the next irqaction for shared interrupts
  9. * @irq: interrupt number
  10. * @dir: pointer to the proc/irq/NN/name entry
  11. * @thread_fn: interrupt handler function for threaded interrupts
  12. * @thread: thread pointer for threaded interrupts
  13. * @thread_flags: flags related to @thread
  14. * @thread_mask: bitmask for keeping track of @thread activity
  15. */
  16. struct irqaction {
  17. irq_handler_t handler; 中断服务函数 handler
  18. unsigned long flags;
  19. void *dev_id;
  20. void __percpu *percpu_dev_id;
  21. struct irqaction *next;
  22. int irq;
  23. irq_handler_t thread_fn;
  24. struct task_struct *thread;
  25. unsigned long thread_flags;
  26. unsigned long thread_mask;
  27. const char *name;
  28. struct proc_dir_entry *dir;
  29. } ____cacheline_internodealigned_in_smp;

在 interrupt.h 中有许多和中断相干的函数

exmple:

request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev)

功能 向内核注册一个中断服务函数,当发生中断号为 irq 的中断时候,会执行 handler 指针函数。

void free_irq(unsigned int irq, void *dev_id)

功能 从内核中断链表上删除一个中断结构

void disable_irq(unsigned int irq)

功能 关闭指定的中断,并等待中断服务函数运行结束后才会返回, 在中断函数外调用,

不能在中断服务程序中调用。

void disable_irq_nosync(unsigned int irq)

功能 关闭指定的中断,不等待中断服务函数结束,调用完这个函数立即返回。 可以中断服务函数

中调用。

void enable_irq(unsigned int irq)

功能 使能指定的中断

local_save_flags(flags)

功能 禁止本 CPU 全部中断,并保存 CPU 状态信息。

local_irq_disable()

功能 禁止本 CPU 全部中断

Linux 内核和 GPIO 口相关的内核 API

exmple:

static inline int gpio_get_value(unsigned int gpio)

功能 获取指定 IO 口的电平状态

返回 IO 电平状态,非 0:表示高电平 , 0 表示低电平

static inline void gpio_set_value(unsigned int gpio, int value)

功能 设置 gpio 口的电平状态为 value

返回 IO 电平状态,非 0:表示高电平 , 0 表示低电平

static inline int gpio_to_irq(unsigned int gpio)

功能 通过 gpio 口编号获得出现这个 IO 上的外部中断编号

返回 这个 IO 上对应的外部中断编号

step 4关于 Linux 中断共享

共享中断是指多个设备共享一根中断线的情况, 在中断到来时,会遍历共享此中断的所有中断处理程序, 直

到某一个中断服务函数时返回 IRQ_HANDLED

全志A33 lichee 开发板 Linux中断编程原理说明的更多相关文章

  1. 全志A33 lichee 搭建Qt App开发环境编写helloworld

    开发平台 * 芯灵思SinlinxA33开发板 淘宝店铺: https://sinlinx.taobao.com/ 嵌入式linux 开发板交流 QQ:641395230 Step 1 在虚拟机(Ce ...

  2. 全志A33 lichee怎样编译镜像

    对于全志A33 lichee编译镜像文件需要先搭建好交叉编译环境,这个搭建环境可以看之前的文档 "SINA33开发板怎样创建编译环境" 开发平台 * 芯灵思SinlinxA33开发 ...

  3. 在开发板Linux上挂载"驱动"挂载不成功,出现提示server 172.27.52.100 not responding, still trying

    1.在开发板具体操作步骤如下:   1.1 :设置IP ifconfig eth0 172.27.52.200   1.2 :ping通 虚拟机Linux 主机Linux ping XXX.XXX.X ...

  4. SecureCRT访问开发板linux系统

    前言: 最近在用OK6410开发板跑linux系统,经常在终端上敲一些指令,无奈开发板屏幕太小用起来非常不方便,所以使用终端一款能运行在windows上的软件与开发板连接,直接在电脑上操作开发板了,这 ...

  5. [分享] IMX6嵌入式开发板linux QT挂载U盘及TF卡

    本文转自迅为开发板:http://www.topeetboard.com 开发平台:iMX6开发板 linux QT 系统下挂载 u 盘如下图所示,qt 启动之后,在超级终端中使用命令“mknod / ...

  6. 全志A33开发板Linux内核定时器编程

    开发平台 * 芯灵思SinlinxA33开发板 淘宝店铺: https://sinlinx.taobao.com/ 嵌入式linux 开发板交流 QQ:641395230 Linux 内核定时器是内核 ...

  7. 芯灵思SinlinxA33开发板Linux内核定时器编程

    开发平台 * 芯灵思SinlinxA33开发板 淘宝店铺: https://sinlinx.taobao.com/ 嵌入式linux 开发板交流 QQ:641395230 Linux 内核定时器是内核 ...

  8. 芯灵思Sinlinx A64开发板Linux内核定时器编程

    开发平台 芯灵思Sinlinx A64 内存: 1GB 存储: 4GB 开发板详细参数 https://m.tb.cn/h.3wMaSKm 开发板交流群 641395230 Linux 内核定时器是内 ...

  9. 全志A33 lichee Linux内核原子操作(附实测代码)

    开发平台 * 芯灵思SinlinxA33开发板 淘宝店铺: https://sinlinx.taobao.com/ 嵌入式linux 开发板交流 QQ:641395230 原子操作是指不会被线程调度机 ...

随机推荐

  1. Linux下更新Git

     查看git版本,卸载旧版本(如果没有安装git请直接到下一步) git --version yum remove git  安装依赖软件 yum install curl-devel expat-d ...

  2. 02.Vue基本代码

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Yahoo Programming Contest 2019 E - Odd Subrectangles

    E - Odd Subrectangles 思路: 对于行方案固定的情况下,假设和为奇数的列为a个,和为偶数的列为b个,a+b = m 那么从奇数里面选奇数个,即C(a, 1) + C(a, 3) + ...

  4. windows常见软件库

    1.护卫神软件库 http://soft.huweishen.com/special/1.html 2.护卫神windows资料库 http://v.huweishen.com/ 3.国超软件下载 h ...

  5. Orchard是如何呈现内容的

    首先Orchard是一个建立在ASP.NET MVC框架上的CMS应用框架.Orchard在呈现内容的时候也遵循MVC的规律,也是通过Controller来处理Url请求并决定用那个View来呈现那种 ...

  6. day052-53 django框架

    一.MVC和MTV模型 这就是web开发中的一种思维模式或者说一套理念,MTV也是基于MVC发展出来的,本质相同,都是使各组件保持松耦合 MVC  把web应用分为模型(model),控制器(cont ...

  7. 『PyTorch × TensorFlow』第十七弹_ResNet快速实现

    『TensorFlow』读书笔记_ResNet_V2 对比之前的复杂版本,这次的torch实现其实简单了不少,不过这和上面的代码实现逻辑过于复杂也有关系. 一.PyTorch实现 # Author : ...

  8. 『TensorFlow』SSD源码学习_其二:基于VGG的SSD网络前向架构

    Fork版本项目地址:SSD 参考自集智专栏 一.SSD基础 在分类器基础之上想要识别物体,实质就是 用分类器扫描整张图像,定位特征位置 .这里的关键就是用什么算法扫描,比如可以将图片分成若干网格,用 ...

  9. latex中使用listings显示代码

    \documentclass[12pt,a4paper]{article}\usepackage{ctex}\usepackage{listings}\usepackage{xcolor}\begin ...

  10. os、os.path模块(文件/目录方法)

    1.模块的概念:模块是一个包含所有定义的变量.函数的文件,模块可以被其余模块调用. 2.利用OS模块实现对系统文件的. os模块中常见的方法: gercwd()     返回当前工作目录 chdir( ...