字元裝置驅動之Buttons 迴圈緩衝佇列

2021-05-28 04:51:24 字數 2468 閱讀 9146

buttons.c

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

static int major = 0;

static struct class *cls;

/* gpecon 0x56000040 */

/* gpfcon 0x56000050 */

/* gpgcon 0x56000060 */

static volatile unsigned long *gpecon;

static volatile unsigned long *gpedat;

static volatile unsigned long *gpfcon;

static volatile unsigned long *gpfdat;

static volatile unsigned long *gpgcon;

static volatile unsigned long *gpgdat;

struct key_desc ;

struct key_desc key_desc = , /* 鬆開: 1, 按下: 0x81 */

, /* 鬆開: 2, 按下: 0x82 */

, /* 鬆開: 3, 按下: 0x83 */

, /* 鬆開: 4, 按下: 0x84 */

};volatile char key = 0;

static wait_queue_head_t button_waitq;

#define buf_len    10

static char key_buf[buf_len];

static volatile int r = 0, w = 0;

static intisempty(void)

static intisfull(void)

static intputdata(char val)

else

}static intgetdata(char *p)

else

}static irqreturn_t buttons_irq(int irq, void *dev_id)

else

// printk("key = 0x%x\n", key);

putdata(key);

/* 喚醒應用程式 */

wake_up_interruptible(&button_waitq);

//printk("buttons_irq current %s , pid = %d \n", current->comm, current->pid);

return irq_handled; 

}int buttons_open(struct inode *inode, struct file *file)

/* 設定gpio為中斷引腳

* 設定觸發方式

* 使能中斷

*//* 設定kscan0(gpe11)為輸出引腳,輸出0 */

*gpecon &= ~(0x3 << 22);

*gpecon |= (1 << 22);

*gpedat &= ~(1<<11);

return 0;

}ssize_t buttons_read(struct file *inode, char __user *buf, size_t size, loff_t *offset)

int buttons_close(struct inode *inode, struct file *file)

return 0;

}static const struct file_operations buttons_fops = ;

int buttons_init(void)

void buttons_exit(void)

module_init(buttons_init);

module_exit(buttons_exit);

module_license("gpl"); 

buttons_test.c

#include

#include

#include

#include

#include

int main(int argc, char **argv)

while (1)

return 0;

}

字元裝置驅動之Buttons 中斷

buttons.c include include include include include include include include include include include include include static int major 0 static struct cla...

Linux裝置驅動之《字元裝置驅動》

linux裝置中最大的特點就是裝置操作猶如檔案操作一般,在應用層看來,硬體裝置只是乙個裝置檔案。應用程式可以像操作檔案一樣對硬體裝置進行操作,如open close read write 等。下面是乙個字元裝置驅動程式的簡單實現test.c 模組分析 1.初始化裝置驅動的結構體 struct fil...

Linux裝置驅動之字元裝置驅動

一 linux裝置的分類 linux系統將裝置分成三種基本型別,每個模組通常實現為其中某一類 字元模組 塊模組或網路模組。這三種型別有 字元裝置 字元裝置是個能夠像位元組流 類似檔案 一樣被訪問的裝置,由字元裝置驅動程式來實現這種特性。字元裝置可以通過檔案系統節點來訪問,比如 dev tty1等。這...