I have started playing with Xenomai
my first hello world code
//******************************hello.c***********************************************//
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
int init_module(void) {
printk("<1>Hello world 1.\n");
return 0;
}
void cleanup_module(void) {
printk(KERN_ALERT "Goodbye world 1.\n");
}
MODULE_LICENSE("GPL"); //To access Xenomai symbols
//*************************Makefile**************************************************//
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
EXTRA_CFLAGS := -I/usr/xenomai/include -I/usr/include/
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
//**********************************************************************************//
-put proper taps or else it will show error
-after this I compile the code
$make
-there would be .ko file generated in the folder. after this load the module
$insmod hello.ko
$dmesg
$rmmod hello.ko
$dmesg
-check all the commands and see the changes in output
-I more code for testing
//********************************************************************************//
#include <native/task.h>
#define TASK_PRIO 99 /* Highest RT priority */
#define TASK_MODE T_FPU|T_CPU(0) /* Uses FPU, bound to CPU #0 */
#define TASK_STKSZ 4096 /* Stack size (in bytes) */
RT_TASK task_desc;
//
//you can use the cookie accordingly, as needed !!!
//
void task_body (void *cookie)
{
//for (;;) {
/* actual real-time code comes here */
//}
}
int init_module (void)
{
int err;
err = rt_task_create(&task_desc,
"MyTaskName",
TASK_STKSZ,
TASK_PRIO,
TASK_MODE);
if (!err)
rt_task_start(&task_desc,&task_body,NULL);
}
void cleanup_module (void)
{
//undo what you have done in init_module()
rt_task_delete(&task_desc);
}
MODULE_LICENSE("GPL"); //To access Xenomai symbols
//********************************************************************************//
-We are done.Now in next post I would be working on timer API
enjoy........=)
my first hello world code
//******************************hello.c***********************************************//
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
int init_module(void) {
printk("<1>Hello world 1.\n");
return 0;
}
void cleanup_module(void) {
printk(KERN_ALERT "Goodbye world 1.\n");
}
MODULE_LICENSE("GPL"); //To access Xenomai symbols
//*************************Makefile**************************************************//
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
EXTRA_CFLAGS := -I/usr/xenomai/include -I/usr/include/
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
//**********************************************************************************//
-put proper taps or else it will show error
-after this I compile the code
$make
-there would be .ko file generated in the folder. after this load the module
$insmod hello.ko
$dmesg
$rmmod hello.ko
$dmesg
-check all the commands and see the changes in output
-I more code for testing
//********************************************************************************//
#include <native/task.h>
#define TASK_PRIO 99 /* Highest RT priority */
#define TASK_MODE T_FPU|T_CPU(0) /* Uses FPU, bound to CPU #0 */
#define TASK_STKSZ 4096 /* Stack size (in bytes) */
RT_TASK task_desc;
//
//you can use the cookie accordingly, as needed !!!
//
void task_body (void *cookie)
{
//for (;;) {
/* actual real-time code comes here */
//}
}
int init_module (void)
{
int err;
err = rt_task_create(&task_desc,
"MyTaskName",
TASK_STKSZ,
TASK_PRIO,
TASK_MODE);
if (!err)
rt_task_start(&task_desc,&task_body,NULL);
}
void cleanup_module (void)
{
//undo what you have done in init_module()
rt_task_delete(&task_desc);
}
MODULE_LICENSE("GPL"); //To access Xenomai symbols
//********************************************************************************//
-We are done.Now in next post I would be working on timer API
enjoy........=)
No comments:
Post a Comment