ucloud-iot-rtthread-package/ports/rtthread/HAL_Timer_rtthread.c

55 lines
1.3 KiB
C
Raw Normal View History

2020-01-08 14:07:35 +08:00
/*
* Copyright (C) 2012-2019 UCloud. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "uiot_import.h"
#include <rtthread.h>
bool HAL_Timer_Expired(Timer *timer) {
rt_tick_t now;
now = rt_tick_get();
return timer->end_time < now;
}
2020-01-09 18:21:11 +08:00
void HAL_Timer_Countdown_ms(Timer *timer, uint32_t timeout_ms) {
2020-01-08 14:07:35 +08:00
rt_tick_t now;
now = rt_tick_get();
timer->end_time = now + rt_tick_from_millisecond(timeout_ms);
}
2020-01-09 18:21:11 +08:00
void HAL_Timer_Countdown(Timer *timer, uint32_t timeout) {
2020-01-08 14:07:35 +08:00
rt_tick_t now;
now = rt_tick_get();
timer->end_time = now + rt_tick_from_millisecond(timeout * 1000);
}
uint32_t HAL_Timer_Remain_ms(Timer *timer) {
rt_tick_t now;
now = rt_tick_get();
rt_tick_t result = timer->end_time - now;
return result;
}
void HAL_Timer_Init(Timer *timer) {
timer->end_time = (rt_tick_t)0;
}
#ifdef __cplusplus
}
#endif