File: frank_module.c

package info (click to toggle)
rtlinux 3.1pre3-2
  • links: PTS
  • area: non-free
  • in suites: sarge, woody
  • size: 4,892 kB
  • ctags: 4,228
  • sloc: ansic: 26,204; sh: 2,069; makefile: 1,414; perl: 855; tcl: 489; asm: 380; cpp: 42
file content (86 lines) | stat: -rw-r--r-- 1,588 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#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"); */
		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;

//	conpr("h");
	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;
}


#define DEBUG 
int init_module(void)
{
	int c[3];
	rtf_destroy(1);
	rtf_destroy(2);
	rtf_destroy(3);
 	c[0] = rtf_create(1, 4000);
	c[1] = rtf_create(2, 4000);
	c[2] = rtf_create(3, 100);		/* input control channel */
	printk("Fifo return 1=%d 2=%d 3=%d\n",c[0],c[1],c[2]);
	rt_task_init(&tasks[0], fun, 1, 3000, 4);
	rt_task_init(&tasks[1], fun, 2, 3000, 5);
	rtf_create_handler(3, &my_handler); 
	return 0;
}


void cleanup_module(void)
{
#ifdef DEBUG
	printk("%d\n", rtf_destroy(1));
	printk("%d\n", rtf_destroy(2));
	printk("%d\n", rtf_destroy(3));
#else 
	rtf_destroy(1);
	rtf_destroy(2);
	rtf_destroy(3);
#endif
	rt_task_delete(&tasks[0]);
	rt_task_delete(&tasks[1]);
}