File: simple.c

package info (click to toggle)
rtlinux 3.1pre3-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 4,896 kB
  • ctags: 4,228
  • sloc: ansic: 26,204; sh: 2,069; makefile: 1,414; perl: 855; tcl: 489; asm: 380; cpp: 42
file content (71 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download | duplicates (3)
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]);
}