diff --git a/apps/mstpcap/main.c b/apps/mstpcap/main.c index 4da985a0..fc9e22e8 100644 --- a/apps/mstpcap/main.c +++ b/apps/mstpcap/main.c @@ -400,7 +400,7 @@ static void packet_statistics_clear(void) static uint32_t Timer_Silence(void *pArg) { - return mstimer_remaining(&Silence_Timer); + return mstimer_elapsed(&Silence_Timer); } static void Timer_Silence_Reset(void *pArg) diff --git a/ports/bdk-atxx4-mstp/rs485.c b/ports/bdk-atxx4-mstp/rs485.c index b0b372b7..9db99060 100644 --- a/ports/bdk-atxx4-mstp/rs485.c +++ b/ports/bdk-atxx4-mstp/rs485.c @@ -61,7 +61,7 @@ static struct mstimer Silence_Timer; bool rs485_silence_time_elapsed( uint16_t milliseconds) { - return (mstimer_remaining(&Silence_Timer) > milliseconds); + return (mstimer_elapsed(&Silence_Timer) > milliseconds); } /**************************************************************************** diff --git a/ports/linux/mstpsnap.c b/ports/linux/mstpsnap.c index 58c300d3..942172ea 100644 --- a/ports/linux/mstpsnap.c +++ b/ports/linux/mstpsnap.c @@ -62,12 +62,14 @@ static volatile struct mstp_port_struct_t MSTP_Port; /* buffers needed by mstp port struct */ static uint8_t RxBuffer[MAX_MPDU]; static uint8_t TxBuffer[MAX_MPDU]; +static struct mstimer Silence_Timer; + static uint32_t Timer_Silence( void *pArg) { uint32_t delta_time = 0; - delta_time = timer_milliseconds(TIMER_SILENCE); + delta_time = mstimer_elapsed(&Silence_Timer); if (delta_time > 0xFFFF) { delta_time = 0xFFFF; } @@ -78,7 +80,7 @@ static uint32_t Timer_Silence( static void Timer_Silence_Reset( void *pArg) { - timer_reset(TIMER_SILENCE); + mstimer_set(&Silence_Timer, 0); } /* functions used by the MS/TP state machine to put or get data */ diff --git a/ports/stm32f10x/main.c b/ports/stm32f10x/main.c index 56602329..fae8d3e0 100644 --- a/ports/stm32f10x/main.c +++ b/ports/stm32f10x/main.c @@ -76,7 +76,7 @@ void lse_init( while (1) { if (LSE_Delay < LSE_FAIL_FLAG) { mstimer_set(&Delay_Timer, 0); - while (mstimer_remaining(&Delay_Timer) < 500) { + while (mstimer_elapsed(&Delay_Timer) < 500) { /* do nothing */ } /* check whether LSE is ready, with 4 seconds timeout */ diff --git a/ports/stm32f10x/rs485.c b/ports/stm32f10x/rs485.c index 1b055123..ce5bcdbc 100644 --- a/ports/stm32f10x/rs485.c +++ b/ports/stm32f10x/rs485.c @@ -72,7 +72,7 @@ void rs485_silence_reset( bool rs485_silence_elapsed( uint32_t interval) { - return (mstimer_remaining(&Silence_Timer) > interval); + return (mstimer_elapsed(&Silence_Timer) > interval); } /************************************************************************* @@ -101,7 +101,7 @@ static uint16_t rs485_turnaround_time( bool rs485_turnaround_elapsed( void) { - return (mstimer_remaining(&Silence_Timer) > rs485_turnaround_time()); + return (mstimer_elapsed(&Silence_Timer) > rs485_turnaround_time()); } diff --git a/ports/win32/dlmstp.c b/ports/win32/dlmstp.c index 3dabef1e..6a8339dc 100644 --- a/ports/win32/dlmstp.c +++ b/ports/win32/dlmstp.c @@ -72,7 +72,7 @@ static struct mstimer Silence_Timer; static uint32_t Timer_Silence( void *pArg) { - return mstimer_remaining(&Silence_Timer); + return mstimer_elapsed(&Silence_Timer); } static void Timer_Silence_Reset( diff --git a/ports/xplained/rs485.c b/ports/xplained/rs485.c index b01d6630..d9120643 100644 --- a/ports/xplained/rs485.c +++ b/ports/xplained/rs485.c @@ -90,7 +90,7 @@ void rs485_silence_reset(void) */ bool rs485_silence_elapsed(uint32_t interval) { - return (mstimer_remaining(&Silence_Timer) > interval); + return (mstimer_elapsed(&Silence_Timer) > interval); } /** @@ -154,7 +154,7 @@ static uint16_t rs485_turnaround_time(void) */ bool rs485_turnaround_elapsed(void) { - return (mstimer_remaining(&Silence_Timer) > rs485_turnaround_time()); + return (mstimer_elapsed(&Silence_Timer) > rs485_turnaround_time()); } /** diff --git a/src/bacnet/basic/sys/mstimer.c b/src/bacnet/basic/sys/mstimer.c index caee0af1..759ef248 100644 --- a/src/bacnet/basic/sys/mstimer.c +++ b/src/bacnet/basic/sys/mstimer.c @@ -106,6 +106,21 @@ unsigned long mstimer_remaining(struct mstimer *t) return t->start + t->interval - mstimer_now(); } +/** + * The time elapsed since the timer started + * + * This function returns the time elapsed. + * + * @param t A pointer to the timer + * + * @return The time elapsed since the last start of the timer + * + */ +unsigned long mstimer_elapsed(struct mstimer *t) +{ + return mstimer_now() - t->start; +} + /** * The value of the interval * diff --git a/src/bacnet/basic/sys/mstimer.h b/src/bacnet/basic/sys/mstimer.h index 180d8866..997e0134 100644 --- a/src/bacnet/basic/sys/mstimer.h +++ b/src/bacnet/basic/sys/mstimer.h @@ -59,6 +59,8 @@ int mstimer_expired(struct mstimer *t); BACNET_STACK_EXPORT unsigned long mstimer_remaining(struct mstimer *t); BACNET_STACK_EXPORT +unsigned long mstimer_elapsed(struct mstimer *t); +BACNET_STACK_EXPORT unsigned long mstimer_interval(struct mstimer *t); /* HAL implementation */ BACNET_STACK_EXPORT