[Android]Linux kernel 開發基礎 (六)- Interrupt

首頁 >> google協作平臺 >> [Android]Linux kernel 開發基礎 (六)- Interrupt

系統運作,有時要停下處理event,

這時候,可利用interrupt中斷去處理event之後再繼續運作,

尤其是輸入裝置通知有資料要送給系統時候,interrupt是一個好方法.

這就是今天要介紹的主題:

 

Linux kernel 開發基礎 (六)- Interrupt

 

1.設定interrupt pin,以及觸發條件

(
IRQF_TRIGGER_RISING ,    上升緣觸發
IRQF_TRIGGER_FALLING ,下降緣觸發
IRQF_TRIGGER_HIGH,         高準位觸發
IRQF_TRIGGER_LOW           低準位觸發

)

 

hello_irq_gpio = gpio_to_irq(/*put the interrupt pin here .*/);
ret = request_threaded_irq(hello_irq_gpio, NULL, hello_interrupt,
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
“hello”, hello_data);
if (ret < 0) {
printk(“[hello.c]Failed to register interruptn”);
}

2.設定觸發條件之後的處理:
static irqreturn_t hello_interrupt(int irq, void *dev_id)
{
printk(“interrupt enter and define the behavior here n”);
return IRQ_HANDLED;
}

範例程式下載

 



================================
分享與讚美,是我們繼續打拼的原動力.
若文章對您有幫助,望請不吝按讚或分享.
或者對影片有興趣可以訂閱頻道接收通知
================================
YouTube 頻道
FB 粉絲專頁
================================

guangyaw

重點主題: 程式設計: Python , Django,Android 工具與軟體: Open edX,Linux工具,Blender教學 分享各地美景與產品使用心得,遊戲實況,甚至影視戲劇等, 您的訂閱就是頻道成長的原動力。 YouTube 頻道: https://youtube.com/xyawli

You may also like...

發表迴響