Skip to contentSkip to conversation

RT Task as a kernel module halts the whole system

Xenomai-help Shashank Bhatia 2 participants 2 messages May 25, 2009

lore
Share & tools
lore
#0 lore raw

Dear All,

            I wrote a simple RT task to be run as kernel module and tried to run it. As soon as i issue the insmod command, it halts the whole system. Please help me out,

The code is as follows:

#include <linux/module.h>   // required by all modules #include <linux/kernel.h>   // required by printk() #include <linux/init.h>
#include <posix/sys/mman.h>
#include <native/task.h>
#include <native/alarm.h>

#define TASK_PRI  50
#define TASK_MODE T_FPU|T_CPU(0)
#define STAK_SIZE 4096

#define ALARM_VAL 500000
#define ALRAM_INT 25000000

RT_ALARM alarm;
RT_TASK  alarm_handler;
int err;

void alarm_hand_func(void *cookie)
{

                if(!err)
                {
                        // do the periodic task
                }
}

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Shashank");

// Start/Init function
static int hello_init(void) {

        printk(KERN_ALERT "Hello world!\n");  // A logging mechanism for kernel

        err = rt_alarm_create(&alarm,"myAlarm");

        err = rt_alarm_start(&alarm,ALARM_VAL,ALARM_INT);

err=rt_task_create(&alarm_handler, "ALARMtask",STAK_SIZE,TASK_PRI,TASK_MODE);

        if(!err) rt_task_start(&alarm_handler,&alarm_hand_func,NULL);

        return 0;                             // A non-zero return means hello_init failed; the module can't be loaded.
}

// End/Cleanup function
static void hello_exit(void) {

        //rt_task_delete(&alarm_handler);

        rt_alarm_delete(&alarm);

        printk(KERN_ALERT "Goodbye world!\n");
}

module_init(hello_init);
module_exit(hello_exit);

-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India

#1 lore raw

Hi,

Quoted 10 lines · Shashank Bhatia

Dear All,

I wrote a simple RT task to be run as kernel module and tried to
run it. As soon as i issue the insmod command, it halts the whole system. Please help me out,

The code is as follows:
[...]

        err = rt_alarm_create(&alarm,"myAlarm");

looking at the xenomai docs [1], there are two rt_alarm_create() functions, one for kernel-space and one for userspace:

int rt_alarm_create (RT_ALARM *alarm, const char *)
Create an alarm object from user-space.

int rt_alarm_create (RT_ALARM *alarm, const char *name, rt_alarm_t handler, void *cookie)
Create an alarm object from kernel space.

It seems you are using the wrong one.

For a user-space alarm example and other code-snippets look in the directory ksrc/skins/native/snippets/

kisda

[1] http://www.xenomai.org/documentation/branches/v2.4.x/html/api/index.html

Quoted 36 lines
        err = rt_alarm_start(&alarm,ALARM_VAL,ALARM_INT);

err=rt_task_create(&alarm_handler, "ALARMtask",STAK_SIZE,TASK_PRI,TASK_MODE);

        if(!err)
                rt_task_start(&alarm_handler,&alarm_hand_func,NULL);

        return 0;                             // A non-zero return means 

hello_init failed; the module can't be loaded.
}

// End/Cleanup function
static void hello_exit(void) {

        //rt_task_delete(&alarm_handler);

        rt_alarm_delete(&alarm);

        printk(KERN_ALERT "Goodbye world!\n");
}

module_init(hello_init);
module_exit(hello_exit);

-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help