/* shm_task.c Set up a periodic task that increments a heartbeat array in shared memory. */ #define MODULE #define __KERNEL__ #include <linux/kernel.h> #include <linux/module.h> #include <linux/errno.h> /* ENOMEM */ #include <stddef.h> /* sizeof() */ #include "rtai.h" #include "rtai_sched.h" #include "rtai_shm.h" #include "common.h" /* SHM_KEY, SHM_HOWMANY */ /* THIS SOFTWARE WAS PRODUCED BY EMPLOYEES OF THE U.S. GOVERNMENT AS PART OF THEIR OFFICIAL DUTIES AND IS IN THE PUBLIC DOMAIN. When linked into the Linux kernel the resulting work is GPL. You are free to use this work under other licenses if you wish. */ MODULE_LICENSE("GPL"); RT_TASK shm_task; static RTIME shm_period_ns = 100000; static int * shm_array = 0; static void shm_function(int arg) { int heartbeat = 0; int t; while (1) { heartbeat++; /* make sure the memory has been allocated before we write to it */ if (0 != shm_array) { /* now write to it */ for (t = 0; t < SHM_HOWMANY; t++) { shm_array[t] = heartbeat; } } rt_task_wait_period(); } return; } int init_module(void) { int retval; RTIME shm_period_count; shm_array = rtai_kmalloc(SHM_KEY, SHM_HOWMANY * sizeof(int)); if (0 == shm_array) { return -ENOMEM; } rt_set_periodic_mode(); shm_period_count = nano2count(shm_period_ns); start_rt_timer(shm_period_count); retval = rt_task_init(&shm_task, shm_function, 0, 1024, RT_LOWEST_PRIORITY, 0, 0); if (0 != retval) { return retval; } retval = rt_task_make_periodic(&shm_task, rt_get_time() + shm_period_count, shm_period_count); if (0 != retval) { return retval; } return 0; } void cleanup_module(void) { rt_task_delete(&shm_task); rtai_kfree(SHM_KEY); return; }