[61] | 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-2008 by Embedded and Real-Time Systems Laboratory
|
---|
| 9 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 10 | *
|
---|
| 11 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
| 12 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
| 13 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 14 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 15 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
| 16 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
| 17 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
| 18 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 19 | gip
|
---|
| 20 | * Ò}j
|
---|
| 21 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
| 22 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
| 23 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
| 24 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
| 25 | * ÆD
|
---|
| 26 | * (a) Äzzɺ¤hL
|
---|
| 27 | gipÒ}j
|
---|
| 28 | AÈÇjÉCãLÌ
|
---|
| 29 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 30 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
| 31 | * ñ·é±ÆD
|
---|
| 32 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
| 33 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 34 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
| 35 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
| 36 | * ÆÓ·é±ÆD
|
---|
| 37 | *
|
---|
| 38 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
| 39 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
| 40 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
| 41 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
| 42 | * ÌÓCðíÈ¢D
|
---|
| 43 | *
|
---|
| 44 | * @(#) $Id: logtask.c 1111 2008-06-12 08:42:26Z ertl-hiro $
|
---|
| 45 | */
|
---|
| 46 |
|
---|
| 47 | /*
|
---|
| 48 | * VXeO^XN
|
---|
| 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 | * VXeO^XNÌoÍæÌ|[gID
|
---|
| 60 | */
|
---|
| 61 | static ID logtask_portid;
|
---|
| 62 |
|
---|
| 63 | /*
|
---|
| 64 | * VAC^tF[XÖÌ1¶oÍ
|
---|
| 65 | */
|
---|
| 66 | static void
|
---|
| 67 | logtask_putc(char_t c)
|
---|
| 68 | {
|
---|
| 69 | serial_wri_dat(logtask_portid, &c, 1);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /*
|
---|
| 73 | * VXeOoÍÌÒ¿í¹
|
---|
| 74 | */
|
---|
| 75 | ER
|
---|
| 76 | logtask_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ÌêÉÍCVAobt@ªó©ð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 | * VXeO^XNÌ{Ì
|
---|
| 129 | */
|
---|
| 130 | void
|
---|
| 131 | logtask_main(intptr_t exinf)
|
---|
| 132 | {
|
---|
| 133 | SYSLOG syslog;
|
---|
| 134 | uint_t lost;
|
---|
| 135 | ER_UINT rercd;
|
---|
| 136 |
|
---|
| 137 | logtask_portid = (ID) exinf;
|
---|
| 138 | serial_opn_por(logtask_portid);
|
---|
| 139 | 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 | lost = 0U;
|
---|
| 144 | while ((rercd = syslog_rea_log(&syslog)) >= 0) {
|
---|
| 145 | lost += (uint_t) rercd;
|
---|
| 146 | if (syslog.logtype >= LOG_TYPE_COMMENT) {
|
---|
| 147 | if (lost > 0U) {
|
---|
| 148 | syslog_lostmsg(lost, logtask_putc);
|
---|
| 149 | lost = 0U;
|
---|
| 150 | }
|
---|
| 151 | syslog_print(&syslog, logtask_putc);
|
---|
| 152 | logtask_putc('\n');
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 | if (lost > 0U) {
|
---|
| 156 | syslog_lostmsg(lost, logtask_putc);
|
---|
| 157 | }
|
---|
| 158 | dly_tsk(LOGTASK_INTERVAL);
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | /*
|
---|
| 163 | * VXeO^XNÌI¹
|
---|
| 164 | */
|
---|
| 165 | void
|
---|
| 166 | logtask_terminate(intptr_t exinf)
|
---|
| 167 | {
|
---|
| 168 | char_t c;
|
---|
| 169 | SYSLOG syslog;
|
---|
| 170 | bool_t msgflg = false;
|
---|
| 171 | ER_UINT rercd;
|
---|
| 172 |
|
---|
| 173 | /*
|
---|
| 174 | * VAC^tF[XhCoÌMobt@É~ϳê½f[^
|
---|
| 175 | * ðCáxoÍ@\ðp¢ÄoÍ·éD
|
---|
| 176 | */
|
---|
| 177 | while (serial_get_chr(logtask_portid, &c)) {
|
---|
| 178 | target_fput_log(c);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | /*
|
---|
| 182 | * Oobt@ÉL^³ê½OîñðCáxoÍ@\ðp¢Äo
|
---|
| 183 | * Í·éD
|
---|
| 184 | */
|
---|
| 185 | while ((rercd = syslog_rea_log(&syslog)) >= 0) {
|
---|
| 186 | if (!msgflg) {
|
---|
| 187 | /*
|
---|
| 188 | * Oobt@É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 (syslog.logtype >= LOG_TYPE_COMMENT) {
|
---|
| 198 | syslog_print(&syslog, target_fput_log);
|
---|
| 199 | target_fput_log('\n');
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 | }
|
---|