source: UsbWattMeter/trunk/asp_dcre/syssvc/logtask.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 4.9 KB
Line 
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-2011 by Embedded and Real-Time Systems Laboratory
9 * Graduate School of Information Science, Nagoya Univ., JAPAN
10 *
11 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
12 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
13 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
14 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
15 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
16 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
17 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
18 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
19ƒƒ“ƒgi—˜—p
20 * ŽÒƒ}ƒjƒ…
21ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
22 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
23 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
24 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
25 * ‚ƁD
26 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
27ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
28ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
29 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
30 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
31 * •ñ‚·‚邱‚ƁD
32 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
33 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
34 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
35 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
36 * –Ɛӂ·‚邱‚ƁD
37 *
38 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
39 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
40 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
41 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
42 * ‚̐ӔC‚𕉂í‚È‚¢D
43 *
44 * @(#) $Id: logtask.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * ƒVƒXƒeƒ€ƒƒOƒ^ƒXƒN
49 */
50
51#include <kernel.h>
52#include <t_syslog.h>
53#include <log_output.h>
54#include "syssvc/serial.h"
55#include "syssvc/syslog.h"
56#include "logtask.h"
57
58/*
59 * ƒVƒXƒeƒ€ƒƒOƒ^ƒXƒN‚̏o—͐æ‚̃|[ƒgID
60 */
61static ID logtask_portid;
62
63/*
64 * ƒVƒŠƒAƒ‹ƒCƒ“ƒ^ƒtƒF[ƒX‚Ö‚Ì1•¶Žšo—Í
65 */
66static void
67logtask_putc(char c)
68{
69 (void) serial_wri_dat(logtask_portid, &c, 1);
70}
71
72/*
73 * ƒVƒXƒeƒ€ƒƒOo—Í‚Ì‘Ò‚¿‡‚킹
74 */
75ER
76logtask_flush(uint_t count)
77{
78 T_SYSLOG_RLOG rlog;
79 T_SERIAL_RPOR rpor;
80 ER ercd, rercd;
81
82 if (sns_dpn()) {
83 ercd = E_CTX;
84 }
85 else {
86 for (;;) {
87 if (syslog_ref_log(&rlog) < 0) {
88 ercd = E_SYS;
89 goto error_exit;
90 }
91 if (rlog.count <= count) {
92 if (count == 0U) {
93 /*
94 * count‚ª0‚̏ꍇ‚ɂ́CƒVƒŠƒAƒ‹ƒoƒbƒtƒ@‚ª‹ó‚©‚ðŠm
95 * ”F‚·‚éD
96 */
97 if (serial_ref_por(logtask_portid, &rpor) < 0) {
98 ercd = E_SYS;
99 goto error_exit;
100 }
101 if (rpor.wricnt == 0U) {
102 ercd = E_OK;
103 goto error_exit;
104 }
105 }
106 else {
107 ercd = E_OK;
108 goto error_exit;
109 }
110 }
111
112 /*
113 * LOGTASK_FLUSH_WAITƒ~ƒŠ•b‘҂D
114 */
115 rercd = dly_tsk(LOGTASK_FLUSH_WAIT);
116 if (rercd < 0) {
117 ercd = (rercd == E_RLWAI) ? rercd : E_SYS;
118 goto error_exit;
119 }
120 }
121 }
122
123 error_exit:
124 return(ercd);
125}
126
127/*
128 * ƒVƒXƒeƒ€ƒƒOƒ^ƒXƒN‚Ì–{‘Ì
129 */
130void
131logtask_main(intptr_t exinf)
132{
133 SYSLOG logbuf;
134 uint_t lostlog;
135 ER_UINT rercd;
136
137 logtask_portid = (ID) exinf;
138 (void) serial_opn_por(logtask_portid);
139 (void) syslog_msk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG));
140 syslog_1(LOG_NOTICE, "System logging task is started on port %d.",
141 logtask_portid);
142 for (;;) {
143 lostlog = 0U;
144 while ((rercd = syslog_rea_log(&logbuf)) >= 0) {
145 lostlog += (uint_t) rercd;
146 if (logbuf.logtype >= LOG_TYPE_COMMENT) {
147 if (lostlog > 0U) {
148 syslog_lostmsg(lostlog, logtask_putc);
149 lostlog = 0U;
150 }
151 syslog_print(&logbuf, logtask_putc);
152 logtask_putc('\n');
153 }
154 }
155 if (lostlog > 0U) {
156 syslog_lostmsg(lostlog, logtask_putc);
157 }
158 (void) dly_tsk(LOGTASK_INTERVAL);
159 }
160}
161
162/*
163 * ƒVƒXƒeƒ€ƒƒOƒ^ƒXƒN‚̏I—¹ˆ—
164 */
165void
166logtask_terminate(intptr_t exinf)
167{
168 char c;
169 SYSLOG logbuf;
170 bool_t msgflg = false;
171 ER_UINT rercd;
172
173 /*
174 * ƒVƒŠƒAƒ‹ƒCƒ“ƒ^ƒtƒF[ƒXƒhƒ‰ƒCƒo‚Ì‘—Mƒoƒbƒtƒ@‚É’~Ï‚³‚ꂽƒf[ƒ^
175 * ‚ðC’჌ƒxƒ‹o—Í‹@”\‚ð—p‚¢‚ďo—Í‚·‚éD
176 */
177 while (serial_get_chr(logtask_portid, &c)) {
178 target_fput_log(c);
179 }
180
181 /*
182 * ƒƒOƒoƒbƒtƒ@‚É‹L˜^‚³‚ꂽƒƒOî•ñ‚ðC’჌ƒxƒ‹o—Í‹@”\‚ð—p‚¢‚ďo
183 * —Í‚·‚éD
184 */
185 while ((rercd = syslog_rea_log(&logbuf)) >= 0) {
186 if (!msgflg) {
187 /*
188 * ƒƒOƒoƒbƒtƒ@‚ÉŽc‚Á‚½ƒƒOî•ñ‚Å‚ ‚邱‚Æ‚ðŽ¦‚·•¶Žš—ñ‚ðo
189 * —Í‚·‚éD
190 */
191 syslog_printf("-- buffered messages --\n", NULL, target_fput_log);
192 msgflg = true;
193 }
194 if (rercd > 0) {
195 syslog_lostmsg((uint_t) rercd, target_fput_log);
196 }
197 if (logbuf.logtype >= LOG_TYPE_COMMENT) {
198 syslog_print(&logbuf, target_fput_log);
199 target_fput_log('\n');
200 }
201 }
202}
Note: See TracBrowser for help on using the repository browser.