• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TIME_H_
18 
19 #define TIME_H_
20 
21 #include <stdio.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define NUM_TIME_SYNC_DATAPOINTS    16
30 
31 typedef struct {
32     uint64_t time1[NUM_TIME_SYNC_DATAPOINTS];
33     uint64_t time2[NUM_TIME_SYNC_DATAPOINTS];
34     size_t n;
35     size_t i;
36 
37     uint64_t time1_base;
38     uint64_t time2_base;
39 
40     bool estimate_valid;
41     float alpha, beta;
42 
43     uint8_t hold_count;
44 
45 } time_sync_t;
46 
47 void time_sync_reset(time_sync_t *sync);
48 bool time_sync_init(time_sync_t *sync);
49 void time_sync_truncate(time_sync_t *sync, size_t window_size);
50 bool time_sync_add(time_sync_t *sync, uint64_t time1, uint64_t time2);
51 bool time_sync_estimate_time1(time_sync_t *sync, uint64_t time2, uint64_t *time1);
52 void time_sync_hold(time_sync_t *sync, uint8_t count);
53 
54 #ifdef __cplusplus
55 }
56 #endif
57 
58 #endif  // TIME_H_
59