OSDN Git Service

カーネルのターゲット非依存部1.7.0およびCFGをマージ
[toppersasp4lpc/asp.git] / asp / include / t_syslog.h
1 /*
2  *  TOPPERS/ASP Kernel
3  *      Toyohashi Open Platform for Embedded Real-Time Systems/
4  *      Advanced Standard Profile Kernel
5  * 
6  *  Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7  *                              Toyohashi Univ. of Technology, JAPAN
8  *  Copyright (C) 2004-2008 by Embedded and Real-Time Systems Laboratory
9  *              Graduate School of Information Science, Nagoya Univ., JAPAN
10  * 
11  *  上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
12  *  ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
13  *  変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
14  *  (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
15  *      権表示,この利用条件および下記の無保証規定が,そのままの形でソー
16  *      スコード中に含まれていること.
17  *  (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
18  *      用できる形で再配布する場合には,再配布に伴うドキュメント(利用
19  *      者マニュアルなど)に,上記の著作権表示,この利用条件および下記
20  *      の無保証規定を掲載すること.
21  *  (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
22  *      用できない形で再配布する場合には,次のいずれかの条件を満たすこ
23  *      と.
24  *    (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
25  *        作権表示,この利用条件および下記の無保証規定を掲載すること.
26  *    (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
27  *        報告すること.
28  *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
29  *      害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
30  *      また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
31  *      由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
32  *      免責すること.
33  * 
34  *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
35  *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
36  *  に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
37  *  アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
38  *  の責任を負わない.
39  * 
40  *  @(#) $Id: t_syslog.h 1900 2010-08-14 02:31:44Z ertl-hiro $
41  */
42
43 /*
44  *              システムログ出力を行うための定義
45  *
46  *  システムログサービスは,システムのログ情報を出力するためのサービス
47  *  である.カーネルからのログ情報の出力にも用いるため,内部で待ち状態
48  *  にはいることはない.
49  *
50  *  ログ情報は,カーネル内のログバッファに書き込むか,低レベルの文字出
51  *  力関数を用いて出力する.どちらを使うかは,拡張サービスコールで切り
52  *  換えることができる.
53  *
54  *  ログバッファ領域がオーバフローした場合には,古いログ情報を消して上
55  *  書きする.
56  *
57  *  アセンブリ言語のソースファイルからこのファイルをインクルードする時
58  *  は,TOPPERS_MACRO_ONLYを定義しておくことで,マクロ定義以外の記述を
59  *  除くことができる.
60  *
61  *  このファイルをインクルードする前に,t_stddef.hをインクルードしてお
62  *  くことが必要である.
63  */
64
65 #ifndef TOPPERS_T_SYSLOG_H
66 #define TOPPERS_T_SYSLOG_H
67
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71
72 /*
73  *  ログ情報の種別の定義
74  */
75 #define LOG_TYPE_COMMENT        UINT_C(0x01)    /* コメント */
76 #define LOG_TYPE_ASSERT         UINT_C(0x02)    /* アサーションの失敗 */
77
78 #define LOG_TYPE_INH            UINT_C(0x11)    /* 割込みハンドラ */
79 #define LOG_TYPE_ISR            UINT_C(0x12)    /* 割込みサービスルーチン */
80 #define LOG_TYPE_CYC            UINT_C(0x13)    /* 周期ハンドラ */
81 #define LOG_TYPE_ALM            UINT_C(0x14)    /* アラームハンドラ */
82 #define LOG_TYPE_OVR            UINT_C(0x15)    /* オーバランハンドラ */
83 #define LOG_TYPE_EXC            UINT_C(0x16)    /* CPU例外ハンドラ */
84 #define LOG_TYPE_TEX            UINT_C(0x17)    /* タスク例外処理ルーチン */
85 #define LOG_TYPE_TSKSTAT        UINT_C(0x18)    /* タスク状態変化 */
86 #define LOG_TYPE_DSP            UINT_C(0x19)    /* ディスパッチャ */
87 #define LOG_TYPE_SVC            UINT_C(0x1a)    /* サービスコール */
88
89 #define LOG_ENTER                       UINT_C(0x00)    /* 入口/開始 */
90 #define LOG_LEAVE                       UINT_C(0x80)    /* 出口/終了 */
91
92 /*
93  *  ログ情報の重要度の定義
94  */
95 #define LOG_EMERG                       UINT_C(0)               /* シャットダウンに値するエラー */
96 #define LOG_ALERT                       UINT_C(1)
97 #define LOG_CRIT                        UINT_C(2)
98 #define LOG_ERROR                       UINT_C(3)               /* システムエラー */
99 #define LOG_WARNING                     UINT_C(4)               /* 警告メッセージ */
100 #define LOG_NOTICE                      UINT_C(5)
101 #define LOG_INFO                        UINT_C(6)
102 #define LOG_DEBUG                       UINT_C(7)               /* デバッグ用メッセージ */
103
104 #ifndef TOPPERS_MACRO_ONLY
105
106 /*
107  *  ログ情報のデータ構造
108  */
109
110 #define TMAX_LOGINFO    6
111
112 typedef struct {
113         uint_t          logtype;                                /* ログ情報の種別 */
114         SYSTIM          logtim;                                 /* ログ時刻 */
115         intptr_t        loginfo[TMAX_LOGINFO];  /* その他のログ情報 */
116 } SYSLOG;
117
118 /*
119  *  ログ情報の重要度のビットマップを作るためのマクロ
120  */
121 #define LOG_MASK(prio)          (1U << (prio))
122 #define LOG_UPTO(prio)          ((1U << ((prio) + 1)) - 1)
123
124 /*
125  *  パケット形式の定義
126  */
127 typedef struct t_syslog_rlog {
128         uint_t  count;          /* ログバッファ中のログの数 */
129         uint_t  lost;           /* 失われたログの数 */
130         uint_t  logmask;        /* ログバッファに記録すべき重要度 */
131         uint_t  lowmask;        /* 低レベル出力すべき重要度 */
132 } T_SYSLOG_RLOG;
133
134 /*
135  *  ログ情報を出力するためのライブラリ関数
136  */
137
138 #ifndef TOPPERS_OMIT_SYSLOG
139
140 extern ER       syslog_wri_log(uint_t prio, const SYSLOG *p_syslog) throw();
141
142 Inline void
143 _syslog_0(uint_t prio, uint_t type)
144 {
145         SYSLOG  syslog;
146
147         syslog.logtype = type;
148         (void) syslog_wri_log(prio, &syslog);
149 }
150
151 Inline void
152 _syslog_1(uint_t prio, uint_t type, intptr_t arg1)
153 {
154         SYSLOG  syslog;
155
156         syslog.logtype = type;
157         syslog.loginfo[0] = arg1;
158         (void) syslog_wri_log(prio, &syslog);
159 }
160
161 Inline void
162 _syslog_2(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2)
163 {
164         SYSLOG  syslog;
165
166         syslog.logtype = type;
167         syslog.loginfo[0] = arg1;
168         syslog.loginfo[1] = arg2;
169         (void) syslog_wri_log(prio, &syslog);
170 }
171
172 Inline void
173 _syslog_3(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
174                                                                                                                 intptr_t arg3)
175 {
176         SYSLOG  syslog;
177
178         syslog.logtype = type;
179         syslog.loginfo[0] = arg1;
180         syslog.loginfo[1] = arg2;
181         syslog.loginfo[2] = arg3;
182         (void) syslog_wri_log(prio, &syslog);
183 }
184
185 Inline void
186 _syslog_4(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
187                                                                                 intptr_t arg3, intptr_t arg4)
188 {
189         SYSLOG  syslog;
190
191         syslog.logtype = type;
192         syslog.loginfo[0] = arg1;
193         syslog.loginfo[1] = arg2;
194         syslog.loginfo[2] = arg3;
195         syslog.loginfo[3] = arg4;
196         (void) syslog_wri_log(prio, &syslog);
197 }
198
199 Inline void
200 _syslog_5(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
201                                                         intptr_t arg3, intptr_t arg4, intptr_t arg5)
202 {
203         SYSLOG  syslog;
204
205         syslog.logtype = type;
206         syslog.loginfo[0] = arg1;
207         syslog.loginfo[1] = arg2;
208         syslog.loginfo[2] = arg3;
209         syslog.loginfo[3] = arg4;
210         syslog.loginfo[4] = arg5;
211         (void) syslog_wri_log(prio, &syslog);
212 }
213
214 Inline void
215 _syslog_6(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
216                                 intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6)
217 {
218         SYSLOG  syslog;
219
220         syslog.logtype = type;
221         syslog.loginfo[0] = arg1;
222         syslog.loginfo[1] = arg2;
223         syslog.loginfo[2] = arg3;
224         syslog.loginfo[3] = arg4;
225         syslog.loginfo[4] = arg5;
226         syslog.loginfo[5] = arg6;
227         (void) syslog_wri_log(prio, &syslog);
228 }
229
230 /*
231  *  ログ情報(コメント)を出力するためのライブラリ関数(vasyslog.c)
232  */
233 extern void     syslog(uint_t prio, const char *format, ...) throw();
234
235 #else /* TOPPERS_OMIT_SYSLOG */
236
237 /*
238  *  システムログ出力を抑止する場合
239  */
240
241 Inline void
242 _syslog_0(uint_t prio, uint_t type)
243 {
244 }
245
246 Inline void
247 _syslog_1(uint_t prio, uint_t type, intptr_t arg1)
248 {
249 }
250
251 Inline void
252 _syslog_2(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2)
253 {
254 }
255
256 Inline void
257 _syslog_3(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
258                                                                                                                 intptr_t arg3)
259 {
260 }
261
262 Inline void
263 _syslog_4(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
264                                                                                 intptr_t arg3, intptr_t arg4)
265 {
266 }
267
268 Inline void
269 _syslog_5(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
270                                                         intptr_t arg3, intptr_t arg4, intptr_t arg5)
271 {
272 }
273
274 Inline void
275 _syslog_6(uint_t prio, uint_t type, intptr_t arg1, intptr_t arg2,
276                                 intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6)
277 {
278 }
279
280 Inline void
281 syslog(uint_t prio, const char *format, ...)
282 {
283 }
284
285 #endif /* TOPPERS_OMIT_SYSLOG */
286
287 /*
288  *  ログ情報(コメント)を出力するためのマクロ
289  *
290  *  formatおよび後続の引数から作成したメッセージを,重大度prioでログ情
291  *  報として出力するためのマクロ.arg1〜argnはintptr_t型にキャストする
292  *  ため,intptr_t型に型変換できる任意の型でよい.
293  */
294
295 #define syslog_0(prio, format) \
296                                 _syslog_1(prio, LOG_TYPE_COMMENT, (intptr_t) format)
297
298 #define syslog_1(prio, format, arg1) \
299                                 _syslog_2(prio, LOG_TYPE_COMMENT, (intptr_t) format, \
300                                                                                                                 (intptr_t)(arg1))
301
302 #define syslog_2(prio, format, arg1, arg2) \
303                                 _syslog_3(prio, LOG_TYPE_COMMENT, (intptr_t) format, \
304                                                                                 (intptr_t)(arg1), (intptr_t)(arg2))
305
306 #define syslog_3(prio, format, arg1, arg2, arg3) \
307                                 _syslog_4(prio, LOG_TYPE_COMMENT, (intptr_t) format, \
308                                                 (intptr_t)(arg1), (intptr_t)(arg2), (intptr_t)(arg3))
309
310 #define syslog_4(prio, format, arg1, arg2, arg3, arg4) \
311                                 _syslog_5(prio, LOG_TYPE_COMMENT, (intptr_t) format, \
312                                                 (intptr_t)(arg1), (intptr_t)(arg2), (intptr_t)(arg3), \
313                                                                                                                 (intptr_t)(arg4))
314
315 #define syslog_5(prio, format, arg1, arg2, arg3, arg4, arg5) \
316                                 _syslog_6(prio, LOG_TYPE_COMMENT, (intptr_t) format, \
317                                                 (intptr_t)(arg1), (intptr_t)(arg2), (intptr_t)(arg3), \
318                                                                                 (intptr_t)(arg4), (intptr_t)(arg5))
319
320 /*
321  *  ログ情報(アサーションの失敗)を出力するためのマクロ
322  */
323 #ifndef TOPPERS_assert_fail
324 #define TOPPERS_assert_fail(exp, file, line) \
325                                 _syslog_3(LOG_EMERG, LOG_TYPE_ASSERT, (intptr_t)(file), \
326                                                                                 (intptr_t)(line), (intptr_t)(exp))
327 #endif /* TOPPERS_assert_fail */
328
329 #endif /* TOPPERS_MACRO_ONLY */
330
331 #ifdef __cplusplus
332 }
333 #endif
334
335 #endif /* TOPPERS_T_SYSLOG_H */