tos_stopwatch.h 3.8 KB
Newer Older
D
daishengdong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
/*----------------------------------------------------------------------------
 * Tencent is pleased to support the open source community by making TencentOS
 * available.
 *
 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
 * If you have downloaded a copy of the TencentOS binary from Tencent, please
 * note that the TencentOS binary is licensed under the BSD 3-Clause License.
 *
 * If you have downloaded a copy of the TencentOS source code from Tencent,
 * please note that TencentOS source code is licensed under the BSD 3-Clause
 * License, except for the third-party components listed below which are
 * subject to different license terms. Your integration of TencentOS into your
 * own projects may require compliance with the BSD 3-Clause License, as well
 * as the other licenses applicable to the third-party components included
 * within TencentOS.
 *---------------------------------------------------------------------------*/

#ifndef _TOS_STOPWATCH_H_
#define  _TOS_STOPWATCH_H_

__CDECLS_BEGIN

typedef struct k_stopwatch_st {
    knl_obj_t   knl_obj;

    k_tick_t    until;
} k_stopwatch_t;

/**
 * @brief Create a stopwatch.
 *
 * @attention
 *
 * @param[in]   stopwatch               the stopwatch.
 *
 * @return  errcode
 * @retval  #K_ERR_NONE                     return successfully.
 */
__API__ k_err_t tos_stopwatch_create(k_stopwatch_t *stopwatch);

/**
 * @brief Destroy a stopwatch.
 *
 * @attention
 *
 * @param[in]   stopwatch               the stopwatch.
 *
 * @return  errcode
 * @retval  #K_ERR_NONE                     return successfully.
 */
__API__ k_err_t tos_stopwatch_destroy(k_stopwatch_t *stopwatch);

/**
 * @brief Count down for a certain tick.
 *
 * @attention
 *
 * @param[in]   stopwatch               the stopwatch.
 * @param[in]   tick                    tick to count down.
 *
 * @return  errcode
 * @retval  #K_ERR_NONE                     return successfully.
 */
__API__ k_err_t tos_stopwatch_countdown(k_stopwatch_t *stopwatch, k_tick_t tick);

/**
 * @brief Count down for a certain time(in millisecond).
 *
 * @attention
 *
 * @param[in]   stopwatch               the stopwatch.
 * @param[in]   millisec                time(in millisecond) to count down.
 *
 * @return  errcode
 * @retval  #K_ERR_NONE                     return successfully.
 */
__API__ k_err_t tos_stopwatch_countdown_ms(k_stopwatch_t *stopwatch, k_time_t millisec);

/**
 * @brief Delay for a certain tick.
 *
 * @attention the stopwatch delay is a "busy" delay without give up of CPU(compared to tos_task_delay)
 *
 * @param[in]   tick                    tick to delay.
 *
 * @return  None
 */
__API__ void tos_stopwatch_delay(k_tick_t tick);

/**
 * @brief Delay for a certain time(in millisecond).
 *
 * @attention the stopwatch delay is a "busy" delay without give up of CPU(compared to tos_task_delay)
 *
 * @param[in]   millisec                time(in millisecond) to delay.
 *
 * @return  None
 */
__API__ void tos_stopwatch_delay_ms(k_time_t millisec);

/**
 * @brief How much time remain of the stopwatch(in tick).
 *
 * @attention
 *
D
David Lin 已提交
106
 * @param[in]   stopwatch               the stopwatch.
D
daishengdong 已提交
107 108 109 110 111 112 113 114 115 116
 *
 * @return  ticks remain
 */
__API__ k_tick_t tos_stopwatch_remain(k_stopwatch_t *stopwatch);

/**
 * @brief How much time remain of the stopwatch(in millisecond).
 *
 * @attention
 *
D
David Lin 已提交
117
 * @param[in]   stopwatch               the stopwatch.
D
daishengdong 已提交
118 119 120 121 122 123 124 125 126 127
 *
 * @return  milliseconds remain
 */
__API__ k_time_t tos_stopwatch_remain_ms(k_stopwatch_t *stopwatch);

/**
 * @brief Whether the stopwatch is expired.
 *
 * @attention
 *
D
David Lin 已提交
128
 * @param[in]   stopwatch               the stopwatch.
D
daishengdong 已提交
129 130 131 132 133 134 135 136 137 138 139
 *
 * @return  whether the stopwatch is expired
 * @retval  #K_TRUE     the stopwatch is expired.
 * @retval  #K_FALSE    the stopwatch is no expired.
 */
__API__ int tos_stopwatch_is_expired(k_stopwatch_t *stopwatch);

__CDECLS_END

#endif /* _TOS_STOPWATCH_H_ */