[問題] polling function timer問題

看板C_and_CPP (C/C++)作者 (秘密)時間5年前 (2020/06/14 15:42), 編輯推噓1(103)
留言4則, 3人參與, 5年前最新討論串1/1
各位版友好 不知道能不能在這問linux kernel的問題 描述一下我的問題 我在driver實作一個function 我想定時約1~2sec polling它 每次都要根據偵測speed 自動做點燈的行為 架構如下, 我想把這function放在probe, init時自動polling static int mv88e6xxx_get_speed(struct mv88e6xxx_chip *chip) { /** Get_speed_status **/ mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS_CTL, &reg); /** 根據對應speed, 用mmio access做對應的gpio點燈行為 **/ switch (reg & MV88E6XXX_PORT_STS_SPEED_MASK) { case 10: ioread(); iowrite(); break; case 100: ioread(); iowrite(); break; case 1000: ioread(); iowrite(); break; . . . } 我想用timer 來做這件事 如下 /**************** Kernel_Timer *************/ struct timer_list danny_timer; static int danny_do(void) { struct mv88e6xxx_chip *chip; mv88e6xxx_get_speed(chip); danny_timer.expires = jiffies + HZ; add_timer(&danny_timer); } static void danny_timer_init(void) { /* Timer 初始化 */ init_timer(&danny_timer); /* define timer 要執行之函式 */ danny_timer.function = danny_do; /* define timer 傳入函式之 Data */ danny_timer.data = ((unsigned long) 0); /* define timer Delay 1秒的時間 */ danny_timer.expires = jiffies + HZ; /* 啟動 Timer*/ add_timer(&danny_timer); } /*********************************************/ 開機時會kernel panic, 不知道是跟mmio有關嗎? 如果單純printk(); 倒是很正常 kernel timer能做到call function嗎? 如果不行, 是要使用timer + wait_queue 機制這樣做嗎?? 有更簡單的作法嗎? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.198.167.208 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1592120550.A.C47.html

06/14 17:01, 5年前 , 1F
chip 變數的使用有點怪
06/14 17:01, 1F

06/14 17:53, 5年前 , 2F
你確定io速度來得及做完?
06/14 17:53, 2F

06/14 18:05, 5年前 , 3F
這樣秒數可能得拉長看看 看做io會掛掉嗎
06/14 18:05, 3F

06/14 18:09, 5年前 , 4F
想在driver 搞個類似while(1)的方式
06/14 18:09, 4F
文章代碼(AID): #1UvTJcn7 (C_and_CPP)
文章代碼(AID): #1UvTJcn7 (C_and_CPP)