base/include/rtai_wd.h

Go to the documentation of this file.
00001 /*
00002  * Development of this (watchdog) module was sponsored by Alcatel, Strasbourg
00003  * as part of general debugging enhancements to RTAI.
00004  *
00005  * Copyright (©) 2001 Ian Soanes <ians@lineo.com>, All rights reserved
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef _RTAI_WD_H
00023 #define _RTAI_WD_H
00024 
00025 #include <rtai_types.h>
00026 
00027 // Useful bits and pieces
00028 #define NSECS_PER_SEC 1000000000
00029 
00030 // For logging stuff
00031 #define WDLOG(fmt, args...) rt_printk("RTAI[watchdog]: " fmt, ##args)
00032 
00033 // What should happen to misbehaving tasks
00034 typedef enum watchdog_policy { 
00035     WD_NOTHING,                 // Not recommended
00036     WD_RESYNC,              // Good for occasional overruns
00037     WD_DEBUG,               // Good for debugging oneshot tasks
00038     WD_STRETCH,             // Good for overrunning tasks
00039     WD_SLIP,                // Good for infinite loops
00040     WD_SUSPEND,                 // Good for most things
00041     WD_KILL                 // Death sentence
00042 } wd_policy;
00043 
00044 // Information about a misbehaving task
00045 typedef struct bad_rt_task {
00046     RT_TASK     *task;      // Pointer to the bad task
00047     int          in_use;    // Allocated (static memory management)
00048     int          slipping;  // In the process of being slipped
00049     int          countdown; // Watchdog ticks to stay suspended
00050     int          count;     // How many times it's offended
00051     int          valid;     // Still an existing RT task
00052     int          forced;    // Forcibly suspended
00053     RTIME        orig_period;   // Original period before adjustments
00054     wd_policy        policy;    // Policy at time of last offence
00055     struct bad_rt_task  *next;      // Next in list
00056 } BAD_RT_TASK;
00057 
00058 #define WD_INDX          2
00059 
00060 #define WD_SET_GRACE     1
00061 #define WD_SET_GRACEDIV  2 
00062 #define WD_SET_SAFETY    3 
00063 #define WD_SET_POLICY    4
00064 #define WD_SET_SLIP      5
00065 #define WD_SET_STRETCH   6
00066 #define WD_SET_LIMIT     7 
00067 
00068 #ifdef __KERNEL__
00069 
00070 #ifdef __cplusplus
00071 extern "C" {
00072 #endif /* __cplusplus */
00073 
00074 int __rtai_wd_init(void);
00075 
00076 void __rtai_wd_exit(void);
00077 
00078 // API for setting parameters
00079 RTAI_SYSCALL_MODE int rt_wdset_grace(int new_value);
00080 
00081 RTAI_SYSCALL_MODE int rt_wdset_gracediv(int new_value);
00082 
00083 RTAI_SYSCALL_MODE wd_policy rt_wdset_policy(wd_policy new_value);
00084 
00085 RTAI_SYSCALL_MODE int rt_wdset_slip(int new_value);
00086 
00087 RTAI_SYSCALL_MODE int rt_wdset_stretch(int new_value);
00088 
00089 RTAI_SYSCALL_MODE int rt_wdset_limit(int new_value);
00090 
00091 RTAI_SYSCALL_MODE int rt_wdset_safety(int new_value);
00092 
00093 #ifdef __cplusplus
00094 }
00095 #endif /* __cplusplus */
00096 
00097 #else /* !__KERNEL__ */
00098 
00099 #ifdef __cplusplus
00100 extern "C" {
00101 #endif /* __cplusplus */
00102 
00103 // API for setting parameters
00104 RTAI_PROTO(int, rt_wdset_grace, (int new_value))
00105 {
00106     struct { long new_value; } arg = { new_value };
00107     return rtai_lxrt(WD_INDX, SIZARG, WD_SET_GRACE, &arg).i[LOW];
00108 }
00109 
00110 RTAI_PROTO(int, rt_wdset_gracediv, (int new_value))
00111 {
00112     struct { long new_value; } arg = { new_value };
00113     return rtai_lxrt(WD_INDX, SIZARG, WD_SET_GRACEDIV, &arg).i[LOW];
00114 }
00115 
00116 RTAI_PROTO(wd_policy, rt_wdset_policy, (wd_policy new_value))
00117 {
00118     struct { long new_value; } arg = { new_value };
00119     return (wd_policy)rtai_lxrt(WD_INDX, SIZARG, WD_SET_POLICY, &arg).i[LOW];
00120 }
00121 
00122 RTAI_PROTO(int, rt_wdset_slip, (int new_value))
00123 {
00124     struct { long new_value; } arg = { new_value };
00125     return rtai_lxrt(WD_INDX, SIZARG, WD_SET_SLIP, &arg).i[LOW];
00126 }
00127 
00128 RTAI_PROTO(int, rt_wdset_stretch, (int new_value))
00129 {
00130     struct { long new_value; } arg = { new_value };
00131     return rtai_lxrt(WD_INDX, SIZARG, WD_SET_STRETCH, &arg).i[LOW];
00132 }
00133 
00134 RTAI_PROTO(int, rt_wdset_limit, (int new_value))
00135 {
00136     struct { long new_value; } arg = { new_value };
00137     return rtai_lxrt(WD_INDX, SIZARG, WD_SET_LIMIT, &arg).i[LOW];
00138 }
00139 
00140 RTAI_PROTO(int, rt_wdset_safety, (int new_value))
00141 {
00142     struct { long new_value; } arg = { new_value };
00143     return rtai_lxrt(WD_INDX, SIZARG, WD_SET_SAFETY, &arg).i[LOW];
00144 }
00145 
00146 #ifdef __cplusplus
00147 }
00148 #endif /* __cplusplus */
00149 
00150 #endif /* __KERNEL__ */
00151 
00152 #endif /* !_RTAI_WD_H */

Generated on Tue Feb 2 17:46:05 2010 for RTAI API by  doxygen 1.4.7