1 /*********************************************************************************
3 * --------------------------------------------------------------------------------
5 * This file is part of MiMic
6 * Copyright (C)2011 Ryo Iizuka
8 * MiMic is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * For further information please contact.
23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
25 *********************************************************************************/
26 #include "../NyLPC_cStopwatch.h"
27 #if NyLPC_ARCH==NyLPC_ARCH_MBEDRTOS
32 static NyLPC_TBool _is_start=NyLPC_TBool_FALSE;
36 NyLPC_TUInt32 NyLPC_cStopwatch_now(void)
38 return (NyLPC_TUInt32)(_timer. read_ms());
44 void NyLPC_cStopwatch_initialize(NyLPC_TcStopwatch_t* i_inst)
48 _is_start=NyLPC_TBool_TRUE;
56 void NyLPC_cStopwatch_set(NyLPC_TcStopwatch_t* i_inst,NyLPC_TUInt32 i_initial)
58 i_inst->_tick=i_initial;
65 void NyLPC_cStopwatch_setNow(NyLPC_TcStopwatch_t* i_inst)
67 i_inst->_tick=NyLPC_cStopwatch_now();
71 * この関数は、基準時刻に現在の時刻をセットします。
73 void NyLPC_cStopwatch_startExpire(NyLPC_TcStopwatch_t* i_inst,NyLPC_TUInt32 i_timeout)
75 NyLPC_cStopwatch_setNow(i_inst);
76 i_inst->_ex_timeout=i_timeout;
80 * NyLPC_cStopwatch_startExpireで設定した時間を経過したかを返します。
82 NyLPC_TBool NyLPC_cStopwatch_isExpired(NyLPC_TcStopwatch_t* i_inst)
85 if(NyLPC_cStopwatch_elapseInMsec(i_inst)>i_inst->_ex_timeout){
86 i_inst->_ex_timeout=0;
88 return (i_inst->_ex_timeout==0);
92 * 基準時刻と現在時刻の差を計算して、経過時間をミリ秒で返します。
94 NyLPC_TUInt32 NyLPC_cStopwatch_elapseInMsec(const NyLPC_TcStopwatch_t* i_inst)
96 return (NyLPC_cStopwatch_now()-i_inst->_tick);