wiringPi之中断

来源:互联网 发布:算法导论第三版4 2 编辑:程序博客网 时间:2024/05/21 05:19

 wiringPi对于中断的相关的设置函数是在箭头所在的链接。

With a newer kernel patched with the GPIO interrupt handling code, you can now wait for an interrupt in your program. This frees up the processor to do other tasks while you’re waiting for that interrupt. The GPIO can be set to interrupt on a rising, falling or both edges of the incoming signal.

打了一个更新的补丁在GPIO中断控制代码,你现在可以在你的项目里面使用中断了。当你在等待中断的时候,它释放了处理器去做其他任务。GPIO可以设置在高电平,低电平或者是上升,下降沿的信号。

Note: Jan 2013: The waitForInterrupt() function is deprecated – you should use the newer and easier to use wiringPiISR() function below.

标注:2013一月:函数waitForInterrupt()被弃用,你可以使用更新和更容易的函数wiringPiISR()

里面只有一个函数:int wiringPiISR (int pin, int edgeType,  void (*function)(void)) ;

This function registers a function to received interrupts on the specified pin. The edgeType parameter is either INT_EDGE_FALLINGINT_EDGE_RISING,INT_EDGE_BOTH or INT_EDGE_SETUP. If it is INT_EDGE_SETUP then no initialisation of the pin will happen – it’s assumed that you have already setup the pin elsewhere (e.g. with the gpio program), but if you specify one of the other types, then the pin will be exported and initialised as specified. This is accomplished via a suitable call to the gpio utility program, so it need to be available.

这个函数是接收一个特定引脚的中断。

edgeType可以是:INT_EDGE_FALLINGINT_EDGE_RISING,INT_EDGE_BOTH or INT_EDGE_SETUP

如果是 INT_EDGE_SETUP,然后没有对引脚初始化将会出现:假如你已经启动了这个引脚在其他地方(例如是一个gpio项目),但是如果你是指定为其他的其中一个模式,然后引脚将会被到处然后初始化为特殊的引脚。只是通过一个实用的gpio项目区完成的,所以这是需要存在的

The pin number is supplied in the current mode – native wiringPi, BCM_GPIO, physical or Sys modes.

引脚的号码可以是 native wiringPi, BCM_GPIO, physical or Sys modes 其中一个模式。

This function will work in any mode, and does not need root privileges to work.

无论是哪种模式,函数都会工作,和不需要管理员的权限就可以工作

The function will be called when the interrupt triggers. When it is triggered, it’s cleared in the dispatcher before calling your function, so if a subsequent interrupt fires before you finish your handler, then it won’t be missed. (However it can only track one more interrupt, if more than one interrupt fires while one is being handled then they will be ignored)

当中断触发的时候函数就会被调用。当触发的时候,在调用你的函数之前就会清除调度函数,所以如果你完成了你的中断处理程序之后,随后中断才触发,那之前的中断就不会被错过。(但是它可以追踪到一个或更多的中断,假如前面的中断正在处理,但是一个或更多的中断正在处理的时候,之前的中断就会被忽略)

This function is run at a high priority (if the program is run using sudo, or as root) and executes concurrently with the main program. It has full access to all the global variables, open file handles and so on.

函数是以高优先级的权限来运行(如果程序是用sudo或者是以管理员权限),然后同时执行主程序。它对全局变量,打开文件等等有全部的权限

 树莓派用的是linux系统,是一个非实时操作系统,所以不能像单片机那样直接使用中断,但是操作系统有定时器概念,可以通过C/Python代码来操作定时器完成你要的功能

int wiringPiISR (int pin, int edgeType,  void (*function)(void)) ;函数的意思是,对于特定的引脚,设置一个模式,假如产生中断就执行函数function

使用案例:http://www.eeboard.com/bbs/thread-11538-1-1.html

从中也可以看到,中断没有所谓的优先级,所有的中断等级是一样的

wiringPi和物理板子接口对应:


0 0
原创粉丝点击