中斷程式之 定時器使用

2021-10-19 09:31:32 字數 2431 閱讀 5952

舉例說明:

jiffies  : 全域性變數, 表示系統時鐘滴答, 增加1 表示  系統時鐘+1; 時間上乙個系統滴答 10ms

struct pin_desc * temp_pin_des =null;

static declare_mutex(sem_button_lock); //定義互斥鎖

static struct class *six_drvdrv_class;

static struct class_device *six_drvdrv_class_dev;

volatile unsigned long *gpfcon;

volatile unsigned long *gpfdat;

volatile unsigned long *gpgcon;

volatile unsigned long *gpgdat;

static struct timer_list button_timer; //定義乙個定時器

static declare_wait_queue_head(button_waitq);

/* 中斷事件標誌, 中斷服務程式將它置1,six_drv_drv_read將它清0 */

static volatile int ev_press = 0;

static struct fasync_struct *button_async;

struct pin_desc;

/* 鍵值: 按下時, 0x01, 0x02, 0x03, 0x04 */

/* 鍵值: 鬆開時, 0x81, 0x82, 0x83, 0x84 */

static unsigned char key_val;

struct pin_desc pins_desc[4] = ,

, ,,};

/* * 確定按鍵值

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

static void buttons_timeout(unsigned long data)

else

ev_press = 1; /* 表示中斷發生了 */

wake_up_interruptible(&button_waitq); /* 喚醒休眠的程序 */

/* 非同步通知 */

kill_fasync (&button_async, sigio, poll_in);

}static int six_drv_drv_open(struct inode *inode, struct file *file)

else

//阻塞

/* 註冊中斷 */

request_irq(irq_eint0, buttons_irq, irqt_bothedge, "s2", &pins_desc[0]);

request_irq(irq_eint2, buttons_irq, irqt_bothedge, "s3", &pins_desc[1]);

request_irq(irq_eint11, buttons_irq, irqt_bothedge, "s4", &pins_desc[2]);

request_irq(irq_eint19, buttons_irq, irqt_bothedge, "s5", &pins_desc[3]);

return 0;

}ssize_t six_drv_drv_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)

}else

/* 如果有按鍵動作, 返回鍵值 */

copy_to_user(buf, &key_val, 1);

ev_press = 0;

return 1;

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

static unsigned six_drv_drv_poll(struct file *file, poll_table *wait)

static int six_drv_drv_fasync (int fd, struct file *filp, int on)

static struct file_operations sencod_drv_fops = ;

int major;

static int six_drv_drv_init(void)

static void six_drv_drv_exit(void)

module_init(six_drv_drv_init);

module_exit(six_drv_drv_exit);

module_license("gpl");

定時器使用

dword winapi checksendinfovector lpvoid lpparameter return 0 void callback dotimer hwnd hwnd,uint umsg,uint ptr idevent,dword dwtime timerproc的引數hwnd是...

Delphi Timer定時器使用

timer定時器是乙個非視覺化元件,能夠定時觸發ontimer事件,完成模擬時鐘 系統延時 倒計時等工作。在system選項卡中。1 timer的主要屬性 1 enabled屬性 當值為true時,開啟定時器,否則關閉定時器。預設值為true。2 interval屬性 控制ontimer事件觸發的時...

workman定時器使用

workerman 定時器例子,可單獨使用,稍加改善可以開啟乙個守護程序,用來做一些定時發布等等類似的任務,使用方便,不需要額外的擴充套件或者類似 crontab 等工具。以下是測試程式 php view plain copy use workerman autoloader use workerm...