1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#ifndef MODULE
#define MODULE
#endif
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <linux/cons.h>
#include <rtl_sched.h>
#include <rtl_fifo.h>
#include "control.h"
RT_TASK tasks[2];
static char *data[] = {"Frank ", "Zappa "};
/* t -- the fifo number */
void fun(int t) {
while (1) {
/* conpr(t - 1 ? "0" : "1"); */
conprll (rt_get_time()); conpr("\n");
/* rtf_put(t, data[t - 1], 6); */
rt_task_wait();
}
}
int my_handler(unsigned int fifo)
{
struct my_msg_struct msg;
int err;
RTIME now;
while ((err = rtf_get(3, &msg, sizeof(msg))) == sizeof(msg)) {
switch (msg.command) {
case START_TASK:
now = rt_get_time();
rt_task_make_periodic(&tasks[msg.task], now, msg.period);
break;
case STOP_TASK:
rt_task_suspend(&tasks[msg.task]);
break;
default:
return -EINVAL;
}
}
if (err != 0) {
return -EINVAL;
}
return 0;
}
int init_module(void)
{
RTIME now;
now = rt_get_time();
rt_task_init(&tasks[0], fun, 1, 3000, 4);
rt_task_init(&tasks[1], fun, 2, 3000, 5);
rt_task_make_periodic(&tasks[0], now, 500 * 10000);
/* rt_task_make_periodic(&tasks[1], now, 200 * 1000000); */
return 0;
}
void cleanup_module(void)
{
rt_task_delete(&tasks[0]);
rt_task_delete(&tasks[1]);
}
|