亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2934 | 回復: 9
打印 上一主題 下一主題

請教一下, 關于 timer 的調(diào)用 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-01-13 17:44 |只看該作者 |倒序瀏覽
本帖最后由 fifodct 于 2011-01-14 10:31 編輯

想在Atmel AT9G20的平臺上跑Linux 2.6.30.  開發(fā)板是SBC6020. 編譯環(huán)境啥的基礎工作應該都OK了,kernel下載到板子里,也能跑起來了。

現(xiàn)在在寫主應用程序,由于里面需要頻繁調(diào)用timer定時器, 我先寫了個timer的測試程序。 相關源代碼在附件里。 timer_test.rar (8.67 KB, 下載次數(shù): 30)


現(xiàn)在苦惱的是,對驅(qū)動模塊編譯時,總是出錯。























后面三個error已經(jīng)解決了,我在 /linux/miscdevice.h里 加上 #define irSIGNALRT4_MINOR  18   然后就ok了。
前面幾個error還是不知道如何解決。 感覺/kernel/signal.c 里的函數(shù)沒有被編譯,或者沒有被link過來. 反正是沒什么頭緒,不知道這邊是否有高手能閃亮出現(xiàn)來解救我~~~


Thanks~~








源代碼:

irsigrt4.c




/***********************************************************************
*        irsigrt4.c module to generate SIGRT4 periodically
*       
*        This module is used to generat SIGRT4 signal periodically
*        as timer base ticks every 50 ms to support up to 10 processes.
*       
*        This file entry is /dev/misc/irSIGRT4
*        Two APIs: open and close
*        open the file entry will start SIGRT4 generating for the process
*        close the file entry will stop SIGRT4 generationg
*
* 6-1-2005        v0.2        change minor number to 18 and defined it in miscdevice.h instead of defined locally
*********************************************************************/

//#include <linux/config.h>         /* custom configuration */
#include <linux/module.h>         /* module_init */
#include <linux/init.h>           /* __init */
#include <linux/signal.h>
#include <linux/miscdevice.h>
#include <linux/timer.h>
#include <linux/fs.h>

#define RT4_MINOR        (irSIGNALRT4_MINOR)       

#define VER                        "1.0 - 2.6.12"
#define DRIVER_NAME        "SIGRT4 generator"

#define MAX_TASK        (10)        /* change needed based on multi-process system */

#define TIMER_CT        (5)        /* counts in jiffies to generate the signal */

#define SIGRT4                (SIGRTMIN+4)       

//static unsigned int        testingct;

// structure for each task
struct task_signal_t {
        struct timer_list        rt4_timer;        // timer
        struct task_struct        *rt4_task;        // current task
        pid_t                        pid;                // id
};                               

static struct task_signal_t        tasks[MAX_TASK];

// timer service
static void rt4_timer_handler( unsigned long data)
{
#if 0
        if( data == 0 )                // testing only for first task
        {
                if( ((++testingct) % 20) == 0 )
                {
                        printk( KERN_INFO "c-jiffies = %u\n", (unsigned int) jiffies);
                }
               
        }
#endif

        // issue SIGRT4 signal to the task
        send_sig(SIGRT4, tasks[data].rt4_task, 1);
        // restart the timer
        tasks[data].rt4_timer.expires = jiffies + TIMER_CT;        // 50ms
        add_timer(&tasks[data].rt4_timer);

        return;
}

static int rt4_open(struct inode *inode, struct file *file)
{
        int        i;
       
        for( i = 0; i < MAX_TASK; i++)
        {
                if( tasks.pid == 0 )
                {
                        break;
                }
               
                if( tasks.pid == current->pid )
                {       
                        // already opened
                        return -EBUSY;
                }
               
        }
       
        if( i == MAX_TASK )
        {       
                // no more slot left
                return -EMFILE;
        }

#if 0
        if( i == 0 )
        {
                // initial testing count for timer 0 only.
                testingct = 0;
        }
#endif       
        // set timer function to be handled

        tasks.rt4_timer.expires = jiffies + TIMER_CT;
        tasks.rt4_timer.data = i; //data to be passed to the timer handler
       
        add_timer(&tasks.rt4_timer);        // start timer
       
        // mark current processor for receiving signal.
        tasks.rt4_task = current;
        tasks.pid = current->pid;
       
//        printk( KERN_INFO "SIGRT4 timer resource: %d for process pid %d \n", i, current->pid);
       
        return 0;
}

/*
*        Shut off the timer.
*        Note: if we really have enabled the watchdog, there
*        is no way to turn off.
*/
static int rt4_release(struct inode *inode, struct file *file)
{
        int i;
        for( i = 0; i < MAX_TASK; i++ )
        {
                if( tasks.pid == current->pid )
                {
                        tasks.pid = 0;
                        del_timer_sync(&tasks.rt4_timer);
                }
        }
        return 0;
}

// kernel interface

static struct file_operations rt4_fops = {
        .owner                = THIS_MODULE,
        .open                = rt4_open,
        .release        = rt4_release,
};

static struct miscdevice rt4_miscdev = {
        .minor                = RT4_MINOR,
        .name                = "irSIGRT4",
        .fops                = &rt4_fops,
};
// module initial
static int __init rt4_init_module( void )
{
        int        i;
       
        if( misc_register(&rt4_miscdev) )
        {
                return -ENODEV;
        }
       
        for( i= 0; i < MAX_TASK; i++ )
        {
                // initial timer
                init_timer(&tasks.rt4_timer);
                tasks.rt4_timer.function = &rt4_timer_handler;
                tasks.pid = 0;       
        }
        printk( KERN_INFO DRIVER_NAME " $Revision: " VER "$ initializing\n");
        return 0;

}

// module cleanup -- no need if use __initcall
static void __exit rt4_cleanup_module( void )
{
        int i;
       
        for( i = 0; i < MAX_TASK; i++ )
        {
                // stop timer
                del_timer_sync(&tasks.rt4_timer);
        }
        misc_deregister(&rt4_miscdev);       
        printk( KERN_INFO "SIGRT4 generator is unloaded\n");
}

// after testing, following two lines can be commented out
// and use last line of the code __initcall(), it will be called
// in the linux initial procedure and the module will be installed
// for an embedded system.
module_init( rt4_init_module );
module_exit( rt4_cleanup_module );

MODULE_AUTHOR( "Qunyi Cao" );
MODULE_DESCRIPTION( "A module to generating SIGRT4 signal" );
MODULE_LICENSE( "GPL" );

論壇徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16賽季CBA聯(lián)賽之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金雞報曉
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年紀念徽章
日期:2016-11-09 13:19:1015-16賽季CBA聯(lián)賽之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序設計版塊每日發(fā)帖之星
日期:2015-12-03 06:20:002015七夕節(jié)徽章
日期:2015-08-21 11:06:17IT運維版塊每日發(fā)帖之星
日期:2015-08-09 06:20:002015亞冠之吉達阿赫利
日期:2015-07-03 08:39:42
2 [報告]
發(fā)表于 2011-01-13 21:18 |只看該作者
大家都好懶,不愿下載的

論壇徽章:
0
3 [報告]
發(fā)表于 2011-01-14 09:39 |只看該作者
本帖最后由 EZWORD 于 2011-01-14 14:08 編輯

看起來是類型在其它文件中定義了,本文件中卻沒有,頭文件問題?

論壇徽章:
0
4 [報告]
發(fā)表于 2011-01-14 10:23 |只看該作者
驅(qū)動模塊里包含了這些文件,大家?guī)臀铱纯词遣皇沁漏了其他什么文件:
#include <linux/module.h>         /* module_init */
#include <linux/init.h>           /* __init */
#include <linux/signal.h>
#include <linux/miscdevice.h>
#include <linux/timer.h>
#include <linux/fs.h>


看起來是變量類型在其它文件中定義了,本文件中卻沒有,頭文件問題?
EZWORD 發(fā)表于 2011-01-14 09:39

論壇徽章:
0
5 [報告]
發(fā)表于 2011-01-17 09:24 |只看該作者
有氣無力地頂一下~~~

論壇徽章:
0
6 [報告]
發(fā)表于 2011-01-18 09:06 |只看該作者
面黃肌瘦地頂一下~~~

論壇徽章:
0
7 [報告]
發(fā)表于 2011-01-19 13:11 |只看該作者
內(nèi)牛滿面地頂一下~~~

我用的是SBC6020的開發(fā)板, AT91SAM9G20平臺。

論壇徽章:
0
8 [報告]
發(fā)表于 2011-01-21 02:59 |只看該作者
回復 1# fifodct


加上#include <linux/sched.h>試試?

我這編譯同過了。。。

論壇徽章:
0
9 [報告]
發(fā)表于 2011-01-21 09:48 |只看該作者
謝謝兄弟指教, 我加了 #include <linux/interrupt.h>編譯就通過了。
請問這個頭文件的功能,跟你說的有什么區(qū)別嗎?

回復  fifodct


加上#include 試試?

我這編譯同過了。。。
miis 發(fā)表于 2011-01-21 02:59

論壇徽章:
0
10 [報告]
發(fā)表于 2011-01-21 10:07 |只看該作者
回復 9# fifodct


指教不敢當,我也是新手。

主要是看編譯器報錯,報的是隱式聲明。就是說你call的函數(shù)“send_sig”沒有出現(xiàn)在頭文件里。所以我找了一個聲明“send_sig”的頭文件。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP