Hey all, I'm fairly new to Linux kernel module development, so I apologize 
in advance if I'm missing something really obvious here. I'm trying to 
write a simple module using the OMAP3730's GP timer in order to 
benchmark/timestamp with more resolution.

The relevant code looks like this:

static struct omap_dm_timer *timer_ptr; // Global timer

static int hrt_init(void)
{
    int result = 0;

    printk("hrt: inserting module\n");
 
    /* Register device with our requested major */
    result = register_chrdev(hrt_major, "hrt", &hrt_fops);
    if (result < 0) {
        printk("hrt: error: can't obtain major number %d\n", hrt_major);
        return result;
    }

    /* Reserve a timer */
    timer_ptr = omap_dm_timer_request();
    EXPORT_SYMBOL(timer_ptr);                                           
 
    if (timer_ptr == NULL){
        printk("hrt: error: no timer is available\n");
        return -1;
    }

    /* Set clock source to system clock, prescaler to 1:1, start the timer 
*/
    if (omap_dm_timer_set_source(timer_ptr, OMAP_TIMER_SRC_SYS_CLK) < 0)
    {
        printk("hrt: error setting OPMAP_TIMER_SRC_SYS_CLK\n");
        return -1;
    }
    omap_dm_timer_set_prescaler(timer_ptr, 0);
    omap_dm_timer_set_load_start(timer_ptr, 1, 0);

    /* Success */
    return 0;
}

static void hrt_exit(void)
{
    printk("hrt: removing module\n");

    /* Stop and release the timer */
    omap_dm_timer_stop(timer_ptr);
    omap_dm_timer_free(timer_ptr);
    timer_ptr = 0;

    /* Unregister the char device */
    unregister_chrdev(hrt_major, "hrt");
}

I'm compiling under Angstrom on

Linux beagleboard 3.6.7+ #1 SMP armv7l GNU/Linux

The first time I insert the module, it works fine. I can also remove it, 
and verify that the hrt_exit() function is run in the log. The problem 
comes when I try to re-insert it, and consequently re-allocate a timer. I 
get the following from the kernel:

[ 2546.762268] hrt: inserting module
[ 2546.765960] omap_dm_timer_set_source: failed to set timer_32k_ck as 
parent
[ 2546.773345] hrt: error: no timer is available
insmod: error inserting 'HRT.ko': -1 Operation not permitted

I haven't been able to find any info around the web on this particular 
error, I'm a little confused because I'm not trying to set_source until 
after I allocate the timer, but that message appears before the allocation 
failure error. In any case, I don't see why it is failing to allocate 
another timer, especially given that there are several on the SoC. Any 
ideas? Need more info? Thank you!

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to