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