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) 2005-2016 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$
|
---|
41 | */
|
---|
42 |
|
---|
43 | /*
|
---|
44 | * システムログタスク
|
---|
45 | */
|
---|
46 |
|
---|
47 | #include <kernel.h>
|
---|
48 | #include "tLogTaskMain_tecsgen.h"
|
---|
49 | #include <t_syslog.h>
|
---|
50 | #include <log_output.h>
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * シリアルインタフェースへの1文字出力
|
---|
54 | */
|
---|
55 | static void
|
---|
56 | logtask_putc(char c)
|
---|
57 | {
|
---|
58 | cSerialPort_write(&c, 1);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * 低レベル出力への1文字出力
|
---|
63 | */
|
---|
64 | static void
|
---|
65 | target_fput_log(char c)
|
---|
66 | {
|
---|
67 | cPutLog_putChar(c);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * システムログ出力の待ち合わせ(受け口関数)
|
---|
72 | */
|
---|
73 | ER
|
---|
74 | eLogTask_flush(uint_t count)
|
---|
75 | {
|
---|
76 | T_SYSLOG_RLOG rlog;
|
---|
77 | T_SERIAL_RPOR rpor;
|
---|
78 | ER ercd, rercd;
|
---|
79 |
|
---|
80 | if (sns_dpn()) {
|
---|
81 | ercd = E_CTX;
|
---|
82 | }
|
---|
83 | else {
|
---|
84 | for (;;) {
|
---|
85 | if (cSysLog_refer(&rlog) < 0) {
|
---|
86 | ercd = E_SYS;
|
---|
87 | goto error_exit;
|
---|
88 | }
|
---|
89 | if (rlog.count <= count) {
|
---|
90 | if (count == 0U) {
|
---|
91 | /*
|
---|
92 | * countが0の場合には,シリアルバッファが空かを確
|
---|
93 | * 認する.
|
---|
94 | */
|
---|
95 | if (cSerialPort_refer(&rpor) < 0) {
|
---|
96 | ercd = E_SYS;
|
---|
97 | goto error_exit;
|
---|
98 | }
|
---|
99 | if (rpor.wricnt == 0U) {
|
---|
100 | ercd = E_OK;
|
---|
101 | goto error_exit;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | else {
|
---|
105 | ercd = E_OK;
|
---|
106 | goto error_exit;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * フラッシュ待ちの単位時間(ATTR_flushWaitμ秒)待つ.
|
---|
112 | */
|
---|
113 | rercd = dly_tsk(ATTR_flushWait);
|
---|
114 | if (rercd < 0) {
|
---|
115 | ercd = (rercd == E_RLWAI) ? rercd : E_SYS;
|
---|
116 | goto error_exit;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | error_exit:
|
---|
122 | return(ercd);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /*
|
---|
126 | * システムログタスクの本体(受け口関数)
|
---|
127 | */
|
---|
128 | void
|
---|
129 | eLogTaskBody_main(void)
|
---|
130 | {
|
---|
131 | SYSLOG syslog;
|
---|
132 | uint_t lost;
|
---|
133 | ER_UINT rercd;
|
---|
134 |
|
---|
135 | cSerialPort_open();
|
---|
136 | syslog_0(LOG_NOTICE, "System logging task is started.");
|
---|
137 |
|
---|
138 | for (;;) {
|
---|
139 | lost = 0U;
|
---|
140 | while ((rercd = cSysLog_read(&syslog)) >= 0) {
|
---|
141 | lost += (uint_t) rercd;
|
---|
142 | if (lost > 0U) {
|
---|
143 | syslog_lostmsg(lost, logtask_putc);
|
---|
144 | lost = 0U;
|
---|
145 | }
|
---|
146 | syslog_print(&syslog, logtask_putc);
|
---|
147 | logtask_putc('\n');
|
---|
148 | }
|
---|
149 | if (lost > 0U) {
|
---|
150 | syslog_lostmsg(lost, logtask_putc);
|
---|
151 | }
|
---|
152 | dly_tsk(ATTR_interval);
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | /*
|
---|
157 | * システムログタスクの終了処理(受け口関数)
|
---|
158 | */
|
---|
159 | void
|
---|
160 | eLogTaskTerminate_main(intptr_t exinf)
|
---|
161 | {
|
---|
162 | char c;
|
---|
163 | SYSLOG syslog;
|
---|
164 | bool_t msgflg = false;
|
---|
165 | ER_UINT rercd;
|
---|
166 |
|
---|
167 | /*
|
---|
168 | * シリアルインタフェースドライバの送信バッファに蓄積されたデータ
|
---|
169 | * を,低レベル出力機能を用いて出力する.
|
---|
170 | */
|
---|
171 | while (cnSerialPortManage_getChar(&c)) {
|
---|
172 | target_fput_log(c);
|
---|
173 | }
|
---|
174 |
|
---|
175 | /*
|
---|
176 | * ログバッファに記録されたログ情報を,低レベル出力機能を用いて出
|
---|
177 | * 力する.
|
---|
178 | */
|
---|
179 | while ((rercd = cSysLog_read(&syslog)) >= 0) {
|
---|
180 | if (!msgflg) {
|
---|
181 | /*
|
---|
182 | * ログバッファに残ったログ情報であることを示す文字列を出
|
---|
183 | * 力する.
|
---|
184 | */
|
---|
185 | syslog_printf("-- buffered messages --\n", NULL, target_fput_log);
|
---|
186 | msgflg = true;
|
---|
187 | }
|
---|
188 | if (rercd > 0) {
|
---|
189 | syslog_lostmsg((uint_t) rercd, target_fput_log);
|
---|
190 | }
|
---|
191 | if (syslog.logtype >= LOG_TYPE_COMMENT) {
|
---|
192 | syslog_print(&syslog, target_fput_log);
|
---|
193 | target_fput_log('\n');
|
---|
194 | }
|
---|
195 | }
|
---|
196 | }
|
---|