xref: /rockchip-linux_mpp/osal/inc/mpp_time.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */
2 /*
3  * Copyright (c) 2015 Rockchip Electronics Co., Ltd.
4  */
5 
6 #ifndef __MPP_TIME_H__
7 #define __MPP_TIME_H__
8 
9 #include <unistd.h>
10 
11 #include "mpp_thread.h"
12 
13 #define msleep(x)               usleep((x)*1000)
14 
15 typedef void* MppClock;
16 typedef void* MppTimer;
17 typedef void* MppStopwatch;
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 rk_s64 mpp_time();
24 void mpp_time_diff(rk_s64 start, rk_s64 end, rk_s64 limit, const char *fmt);
25 
26 /*
27  * Clock create / destroy / enable / disable function
28  * Note when clock is create it is default disabled user need to call enable
29  * fucntion with enable = 1 to enable the clock.
30  * User can use enable function with enable = 0 to disable the clock.
31  */
32 MppClock mpp_clock_get(const char *name);
33 void mpp_clock_put(MppClock clock);
34 void mpp_clock_enable(MppClock clock, rk_u32 enable);
35 
36 /*
37  * Clock basic operation function:
38  * start : let clock start timing counter
39  * pause : let clock pause and return the diff to start time
40  * reset : let clock counter to all zero
41  */
42 rk_s64 mpp_clock_start(MppClock clock);
43 rk_s64 mpp_clock_pause(MppClock clock);
44 rk_s64 mpp_clock_reset(MppClock clock);
45 
46 /*
47  * These clock helper function can only be call when clock is paused:
48  * mpp_clock_get_sum    - Return clock sum up total value
49  * mpp_clock_get_count  - Return clock sum up counter value
50  * mpp_clock_get_name   - Return clock name
51  */
52 rk_s64 mpp_clock_get_sum(MppClock clock);
53 rk_s64 mpp_clock_get_count(MppClock clock);
54 const char *mpp_clock_get_name(MppClock clock);
55 
56 /*
57  * MppTimer is for timer with callback function
58  * It will provide the ability to repeat doing something until it is
59  * disalble or put.
60  *
61  * Timer work flow:
62  *
63  * 1. mpp_timer_get
64  * 2. mpp_timer_set_callback
65  * 3. mpp_timer_set_timing(initial, interval)
66  * 4. mpp_timer_set_enable(initial, 1)
67  *    ... running ...
68  * 5. mpp_timer_set_enable(initial, 0)
69  * 6. mpp_timer_put
70  */
71 MppTimer mpp_timer_get(const char *name);
72 void mpp_timer_set_callback(MppTimer timer, MppThreadFunc func, void *ctx);
73 void mpp_timer_set_timing(MppTimer timer, rk_s32 initial, rk_s32 interval);
74 void mpp_timer_set_enable(MppTimer timer, rk_s32 enable);
75 void mpp_timer_put(MppTimer timer);
76 
77 /*
78  * MppStopwatch is for timer to record event and time
79  *
80  * Stopwatch work flow:
81  *
82  * 1. mpp_stopwatch_get
83  * 2. mpp_stopwatch_setup(max_count, show_on_exit)
84  * 3. mpp_stopwatch_record(event)
85  *    ... running ...
86  * 4. mpp_stopwatch_record(event)
87  * 5. mpp_stopwatch_put (show events and time)
88  */
89 MppStopwatch mpp_stopwatch_get(const char *name);
90 void mpp_stopwatch_set_show_on_exit(MppStopwatch stopwatch, rk_s32 show_on_exit);
91 void mpp_stopwatch_record(MppStopwatch stopwatch, const char *event);
92 void mpp_stopwatch_put(MppStopwatch timer);
93 rk_s64 mpp_stopwatch_elapsed_time(MppStopwatch stopwatch);
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif /*__MPP_TIME_H__*/
100