創(chuàng)新互聯(lián)建站長期為上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為江北企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè),江北網(wǎng)站改版等技術(shù)服務(wù)。擁有10多年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
* 芯靈思SinlinxA33開發(fā)板
本節(jié)實驗?zāi)繕?biāo)實現(xiàn)按鍵觸發(fā)中斷終端顯示按鍵松開或按下
實驗平臺 芯靈思Sinlinx A33 開發(fā)板
step1 查看原理圖,三個按鍵都連接到LRADC0引腳,通過判斷電壓大小來確定是按的哪個鍵。
step2 內(nèi)核關(guān)于 CPU 的中斷號linux 中斷注冊函數(shù)中的 irq 中斷號并不是芯片物理上的編號,而是由芯片商在移植 Linux 系統(tǒng)時定在構(gòu)架相
關(guān)的頭文件中定義好的, 在內(nèi)核源碼中,名字一般是 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
不知道開發(fā)板用的哪個平臺,直接在.config中找
由此找到芯片在內(nèi)核中的中斷號
step 3 簡要介紹中斷驅(qū)動要用到的函數(shù)
查看 irq.h 文件 里面有關(guān)于中斷的函數(shù)結(jié)構(gòu)體聲明 /root/work/sinlinx/a33/lichee/linux-3.4/include/linux/irq.h
* struct irq_data - per irq and irq chip data passed down to chip functions
* @irq: interrupt number
* @hwirq: hardware interrupt number, local to the interrupt domain
* @node: node index useful for balancing
* @state_use_accessors: status information for irq chip functions.
* Use accessor functions to deal with it
* @chip: low level interrupt hardware access
* @domain: Interrupt translation domain; responsible for mapping
* between hwirq number and linux irq number.
* @handler_data: per-IRQ data for the irq_chip methods
* @chip_data: platform-specific per-chip private data for the chip
* methods, to allow shared chip implementations
* @msi_desc: MSI descriptor
* @affinity: IRQ affinity on SMP
*
* The fields here need to overlay the ones in irq_desc until we
* cleaned up the direct references and switched everything over to
* irq_data.
*/
struct irq_data {
unsigned int irq;
unsigned long hwirq;
unsigned int node;
unsigned int state_use_accessors;
struct irq_chip *chip;
struct irq_domain *domain;
void *handler_data;
void *chip_data;
struct msi_desc *msi_desc;
#ifdef CONFIG_SMP
cpumask_var_t affinity;
#endif
};
struct irqaction 結(jié)構(gòu)體在 /root/work/sinlinx/a33/lichee/linux-3.4/include/linux/interrupt.h
/**
* struct irqaction - per interrupt action descriptor
* @handler: interrupt handler function
* @flags: flags (see IRQF_* above)
* @name: name of the device
* @dev_id: cookie to identify the device
* @percpu_dev_id: cookie to identify the device
* @next: pointer to the next irqaction for shared interrupts
* @irq: interrupt number
* @dir: pointer to the proc/irq/NN/name entry
* @thread_fn: interrupt handler function for threaded interrupts
* @thread: thread pointer for threaded interrupts
* @thread_flags: flags related to @thread
* @thread_mask: bitmask for keeping track of @thread activity
*/
struct irqaction {
irq_handler_t handler; 中斷服務(wù)函數(shù) handler
unsigned long flags;
void *dev_id;
void __percpu *percpu_dev_id;
struct irqaction *next;
int irq;
irq_handler_t thread_fn;
struct task_struct *thread;
unsigned long thread_flags;
unsigned long thread_mask;
const char *name;
struct proc_dir_entry *dir;
} ____cacheline_internodealigned_in_smp;
在 interrupt.h 中有許多和中斷相干的函數(shù)
exmple:
request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev)
功能 向內(nèi)核注冊一個中斷服務(wù)函數(shù),當(dāng)發(fā)生中斷號為 irq 的中斷時候,會執(zhí)行 handler 指針函數(shù)。
void free_irq(unsigned int irq, void *dev_id)
功能 從內(nèi)核中斷鏈表上刪除一個中斷結(jié)構(gòu)void disable_irq(unsigned int irq)
功能 關(guān)閉指定的中斷,并等待中斷服務(wù)函數(shù)運行結(jié)束后才會返回, 在中斷函數(shù)外調(diào)用,
不能在中斷服務(wù)程序中調(diào)用。void disable_irq_nosync(unsigned int irq)
功能 關(guān)閉指定的中斷,不等待中斷服務(wù)函數(shù)結(jié)束,調(diào)用完這個函數(shù)立即返回。 可以中斷服務(wù)函數(shù)
中調(diào)用。void enable_irq(unsigned int irq)
功能 使能指定的中斷
宏 local_save_flags(flags)
功能 禁止本 CPU 全部中斷,并保存 CPU 狀態(tài)信息。
宏local_irq_disable()
功能 禁止本 CPU 全部中斷
Linux 內(nèi)核和 GPIO 口相關(guān)的內(nèi)核 API
exmple:
static inline int gpio_get_value(unsigned int gpio)
功能 獲取指定 IO 口的電平狀態(tài)
返回 IO 電平狀態(tài),非 0:表示高電平 , 0 表示低電平
static inline void gpio_set_value(unsigned int gpio, int value)
功能 設(shè)置 gpio 口的電平狀態(tài)為 value
返回 IO 電平狀態(tài),非 0:表示高電平 , 0 表示低電平
static inline int gpio_to_irq(unsigned int gpio)
功能 通過 gpio 口編號獲得出現(xiàn)這個 IO 上的外部中斷編號
返回 這個 IO 上對應(yīng)的外部中斷編號
step 4關(guān)于 Linux 中斷共享
共享中斷是指多個設(shè)備共享一根中斷線的情況, 在中斷到來時,會遍歷共享此中斷的所有中斷處理程序, 直
到某一個中斷服務(wù)函數(shù)時返回 IRQ_HANDLED
網(wǎng)站標(biāo)題:全志A33lichee開發(fā)板Linux中斷編程原理說明
標(biāo)題URL:http://muchs.cn/article2/jpidoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、定制網(wǎng)站、ChatGPT、、網(wǎng)站建設(shè)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)