/* * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Xenomai; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include #include #define TASK_PRIO 99 /* Highest RT priority */ #define TASK_MODE T_CPU(0) /* Bound to CPU #0 */ #define TASK_STKSZ 4096 /* Stack size (in bytes) */ static RT_TASK task_desc; static RT_PIPE pipe_desc; int task_period_ns = 1000000000; module_param(task_period_ns,int,0444); MODULE_PARM_DESC(task_period_ns, "period in ns (default: 1s)"); static void demo_task(void *cookie) { int err, count; char c; err = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns)); if (err) { printk("rt_task_set_periodic() failed: code %d\n", err); rt_task_suspend(NULL); } for (count = 0;;) { err = rt_task_wait_period(NULL); if (err) { if (err != -ETIMEDOUT) { printk("rt_task_wait_period() failed: code %d\n", err); rt_task_suspend(NULL); } continue; } rt_pipe_write(&pipe_desc, &count, sizeof(count), P_NORMAL); if (rt_pipe_read(&pipe_desc, &c, sizeof(c), TM_INFINITE) == 1) ++count; } } int demo_init(void) { int err; err = rt_pipe_create(&pipe_desc, "data_pipe", P_MINOR_AUTO, 0); if (err) { printk("rt_pipe_create() failed: code %d\n", err); goto fail; } err = rt_task_create(&task_desc, "kernel_task", TASK_STKSZ, TASK_PRIO, TASK_MODE); if (err) { printk("rt_task_create() failed: code %d\n", err); goto fail; } err = rt_task_start(&task_desc, &demo_task, NULL); if (err) printk("rt_task_start() failed: code %d\n", err); fail: return err; } void demo_cleanup(void) { rt_task_delete(&task_desc); rt_pipe_delete(&pipe_desc); } module_init(demo_init); module_exit(demo_cleanup); MODULE_LICENSE("GPL v2");