免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2910 | 回复: 9
打印 上一主题 下一主题

请教一下, 关于 timer 的调用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-13 17:44 |只看该作者 |倒序浏览
本帖最后由 fifodct 于 2011-01-14 10:31 编辑

想在Atmel AT9G20的平台上跑Linux 2.6.30.  开发板是SBC6020. 编译环境啥的基础工作应该都OK了,kernel下载到板子里,也能跑起来了。

现在在写主应用程序,由于里面需要频繁调用timer定时器, 我先写了个timer的测试程序。 相关源代码在附件里。 timer_test.rar (8.67 KB, 下载次数: 30)


现在苦恼的是,对驱动模块编译时,总是出错。























后面三个error已经解决了,我在 /linux/miscdevice.h里 加上 #define irSIGNALRT4_MINOR  18   然后就ok了。
前面几个error还是不知道如何解决。 感觉/kernel/signal.c 里的函数没有被编译,或者没有被link过来. 反正是没什么头绪,不知道这边是否有高手能闪亮出现来解救我~~~


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联赛之同曦
日期: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联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
2 [报告]
发表于 2011-01-13 21:18 |只看该作者
大家都好懒,不愿下载的

论坛徽章:
0
3 [报告]
发表于 2011-01-14 09:39 |只看该作者
本帖最后由 EZWORD 于 2011-01-14 14:08 编辑

看起来是类型在其它文件中定义了,本文件中却没有,头文件问题?

论坛徽章:
0
4 [报告]
发表于 2011-01-14 10:23 |只看该作者
驱动模块里包含了这些文件,大家帮我看看是不是还漏了其他什么文件:
#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 发表于 2011-01-14 09:39

论坛徽章:
0
5 [报告]
发表于 2011-01-17 09:24 |只看该作者
有气无力地顶一下~~~

论坛徽章:
0
6 [报告]
发表于 2011-01-18 09:06 |只看该作者
面黄肌瘦地顶一下~~~

论坛徽章:
0
7 [报告]
发表于 2011-01-19 13:11 |只看该作者
内牛满面地顶一下~~~

我用的是SBC6020的开发板, AT91SAM9G20平台。

论坛徽章:
0
8 [报告]
发表于 2011-01-21 02:59 |只看该作者
回复 1# fifodct


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

我这编译同过了。。。

论坛徽章:
0
9 [报告]
发表于 2011-01-21 09:48 |只看该作者
谢谢兄弟指教, 我加了 #include <linux/interrupt.h>编译就通过了。
请问这个头文件的功能,跟你说的有什么区别吗?

回复  fifodct


加上#include 试试?

我这编译同过了。。。
miis 发表于 2011-01-21 02:59

论坛徽章:
0
10 [报告]
发表于 2011-01-21 10:07 |只看该作者
回复 9# fifodct


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

主要是看编译器报错,报的是隐式声明。就是说你call的函数“send_sig”没有出现在头文件里。所以我找了一个声明“send_sig”的头文件。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP