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

Last change on this file since 164 was 164, checked in by coas-nagasima, 7 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: 6.1 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-2010 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: syslog.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * ƒVƒXƒeƒ€ƒƒO‹@”\
49 */
50
51#include <sil.h>
52#undef TOPPERS_OMIT_SYSLOG
53#include <t_syslog.h>
54#include <log_output.h>
55#include "target_syssvc.h"
56#include "syslog.h"
57
58/*
59 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
60 */
61#ifndef LOG_SYSLOG_WRI_LOG_ENTER
62#define LOG_SYSLOG_WRI_LOG_ENTER(prio, p_syslog)
63#endif /* LOG_SYSLOG_WRI_LOG_ENTER */
64
65#ifndef LOG_SYSLOG_WRI_LOG_LEAVE
66#define LOG_SYSLOG_WRI_LOG_LEAVE(ercd)
67#endif /* LOG_SYSLOG_WRI_LOG_LEAVE */
68
69#ifndef LOG_SYSLOG_REA_LOG_ENTER
70#define LOG_SYSLOG_REA_LOG_ENTER(p_syslog)
71#endif /* LOG_SYSLOG_REA_LOG_ENTER */
72
73#ifndef LOG_SYSLOG_REA_LOG_LEAVE
74#define LOG_SYSLOG_REA_LOG_LEAVE(ercd, p_syslog)
75#endif /* LOG_SYSLOG_REA_LOG_LEAVE */
76
77#ifndef LOG_SYSLOG_MSK_LOG_ENTER
78#define LOG_SYSLOG_MSK_LOG_ENTER(logmask, lowmask)
79#endif /* LOG_SYSLOG_MSK_LOG_ENTER */
80
81#ifndef LOG_SYSLOG_MSK_LOG_LEAVE
82#define LOG_SYSLOG_MSK_LOG_LEAVE(ercd)
83#endif /* LOG_SYSLOG_MSK_LOG_LEAVE */
84
85#ifndef LOG_SYSLOG_REF_LOG_ENTER
86#define LOG_SYSLOG_REF_LOG_ENTER(pk_rlog)
87#endif /* LOG_SYSLOG_REF_LOG_ENTER */
88
89#ifndef LOG_SYSLOG_REF_LOG_LEAVE
90#define LOG_SYSLOG_REF_LOG_LEAVE(pk_rlog)
91#endif /* LOG_SYSLOG_REF_LOG_LEAVE */
92
93/*
94 * Œ»Ý‚̃VƒXƒeƒ€Žž
95 *
96 * ƒƒOŽž‚ðŽæ‚èo‚·‚½‚߂ɁC‚â‚Þ‚È‚­CƒJ[ƒlƒ‹‚Ì“à•”•Ï”‚ðŽQÆ‚µ‚Ä‚¢
97 * ‚éD
98 */
99extern ulong_t _kernel_current_time;
100
101/*
102 * ƒƒOƒoƒbƒtƒ@‚Æ‚»‚ê‚ɃAƒNƒZƒX‚·‚邽‚߂̃|ƒCƒ“ƒ^
103 */
104static SYSLOG syslog_buffer[TCNT_SYSLOG_BUFFER]; /* ƒƒOƒoƒbƒtƒ@ */
105static uint_t syslog_count; /* ƒƒOƒoƒbƒtƒ@’†‚̃ƒO‚̐” */
106static uint_t syslog_head; /* æ“ª‚̃ƒO‚ÌŠi”[ˆÊ’u */
107static uint_t syslog_tail; /* ŽŸ‚̃ƒO‚ÌŠi”[ˆÊ’u */
108static uint_t syslog_lost; /* Ž¸‚í‚ꂽƒƒO‚̐” */
109
110/*
111 * o—Í‚·‚ׂ«ƒƒOî•ñ‚̏d—v“xiƒrƒbƒgƒ}ƒbƒvj
112 */
113static uint_t syslog_logmask; /* ƒƒOƒoƒbƒtƒ@‚É‹L˜^‚·‚ׂ«d—v“x */
114static uint_t syslog_lowmask_not; /* ’჌ƒxƒ‹o—Í‚·‚ׂ«d—v“xi”½“]j*/
115
116/*
117 * ƒVƒXƒeƒ€ƒƒO‹@”\‚̏‰Šú‰»
118 */
119void
120syslog_initialize(intptr_t exinf)
121{
122 syslog_count = 0U;
123 syslog_head = 0U;
124 syslog_tail = 0U;
125 syslog_lost = 0U;
126 syslog_logmask = 0U;
127 syslog_lowmask_not = 0U;
128}
129
130/*
131 * ƒƒOî•ñ‚̏o—Í
132 *
133 * CPUƒƒbƒNó‘Ô‚âŽÀsƒRƒ“ƒeƒLƒXƒg‚É‚æ‚炸“®ì‚Å‚«‚é‚悤‚ÉŽÀ‘•‚µ‚Ä‚ ‚éD
134 */
135ER
136syslog_wri_log(uint_t prio, const SYSLOG *p_syslog)
137{
138 SIL_PRE_LOC;
139
140 LOG_SYSLOG_WRI_LOG_ENTER(prio, p_syslog);
141 SIL_LOC_INT();
142
143 /*
144 * ƒƒOŽž‚̐ݒè
145 */
146 ((SYSLOG *) p_syslog)->logtim = _kernel_current_time;
147
148 /*
149 * ƒƒOƒoƒbƒtƒ@‚É‹L˜^
150 */
151 if ((syslog_logmask & LOG_MASK(prio)) != 0U) {
152 syslog_buffer[syslog_tail] = *p_syslog;
153 syslog_tail++;
154 if (syslog_tail >= TCNT_SYSLOG_BUFFER) {
155 syslog_tail = 0U;
156 }
157 if (syslog_count < TCNT_SYSLOG_BUFFER) {
158 syslog_count++;
159 }
160 else {
161 syslog_head = syslog_tail;
162 syslog_lost++;
163 }
164 }
165
166 /*
167 * ’჌ƒxƒ‹o—Í
168 */
169 if (((~syslog_lowmask_not) & LOG_MASK(prio)) != 0U) {
170 syslog_print(p_syslog, target_fput_log);
171 target_fput_log('\n');
172 }
173
174 SIL_UNL_INT();
175 LOG_SYSLOG_WRI_LOG_LEAVE(E_OK);
176 return(E_OK);
177}
178
179/*
180 * ƒƒOƒoƒbƒtƒ@‚©‚ç‚̓Ǐo‚µ
181 *
182 * CPUƒƒbƒNó‘Ô‚âŽÀsƒRƒ“ƒeƒLƒXƒg‚É‚æ‚炸“®ì‚Å‚«‚é‚悤‚ÉŽÀ‘•‚µ‚Ä‚ ‚éD
183 */
184ER_UINT
185syslog_rea_log(SYSLOG *p_syslog)
186{
187 ER_UINT ercd;
188 SIL_PRE_LOC;
189
190 LOG_SYSLOG_REA_LOG_ENTER(p_syslog);
191 SIL_LOC_INT();
192
193 /*
194 * ƒƒOƒoƒbƒtƒ@‚©‚ç‚ÌŽæo‚µ
195 */
196 if (syslog_count > 0U) {
197 *p_syslog = syslog_buffer[syslog_head];
198 syslog_count--;
199 syslog_head++;
200 if (syslog_head >= TCNT_SYSLOG_BUFFER) {
201 syslog_head = 0U;
202 }
203 ercd = (ER_UINT) syslog_lost;
204 syslog_lost = 0U;
205 }
206 else {
207 ercd = E_OBJ;
208 }
209
210 SIL_UNL_INT();
211 LOG_SYSLOG_REA_LOG_LEAVE(ercd, p_syslog);
212 return(ercd);
213}
214
215/*
216 * o—Í‚·‚ׂ«ƒƒOî•ñ‚̏d—v“x‚̐ݒè
217 */
218ER
219syslog_msk_log(uint_t logmask, uint_t lowmask)
220{
221 LOG_SYSLOG_MSK_LOG_ENTER(logmask, lowmask);
222 syslog_logmask = logmask;
223 syslog_lowmask_not = ~lowmask;
224 LOG_SYSLOG_MSK_LOG_LEAVE(E_OK);
225 return(E_OK);
226}
227
228/*
229 * ƒƒOƒoƒbƒtƒ@‚̏ó‘ÔŽQÆ
230 */
231ER
232syslog_ref_log(T_SYSLOG_RLOG *pk_rlog)
233{
234 SIL_PRE_LOC;
235
236 LOG_SYSLOG_REF_LOG_ENTER(pk_rlog);
237 SIL_LOC_INT();
238
239 pk_rlog->count = syslog_count;
240 pk_rlog->lost = syslog_lost;
241 pk_rlog->logmask = syslog_logmask;
242 pk_rlog->lowmask = ~syslog_lowmask_not;
243
244 SIL_UNL_INT();
245 LOG_SYSLOG_REF_LOG_LEAVE(pk_rlog);
246 return(E_OK);
247}
Note: See TracBrowser for help on using the repository browser.