File: ts.h

package info (click to toggle)
rat 4.2.22-2.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,896 kB
  • ctags: 3,717
  • sloc: ansic: 36,542; tcl: 2,740; sh: 2,675; makefile: 295
file content (66 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download | duplicates (4)
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
/*
 * FILE:    ts.h
 * AUTHORS: Orion Hodson
 *
 * Copyright (c) 1999-2001 University College London
 * All rights reserved.
 *
 * $Id: ts.h,v 1.17 2002/03/16 01:00:48 ucacoxh Exp $
 */

#ifndef __TS_H__
#define __TS_H__

typedef struct {
        uint32_t ticks:26;
        uint32_t check:2;
        uint32_t idx:4;
} timestamp_t;

/* Maps a 32 bit unsigned integer into a valid timestamp.
 * This be used for mapping offsets, not timestamps (see
 * below) */

timestamp_t     ts_map32(uint32_t freq, uint32_t ts32);

/* Common Operations */
timestamp_t     ts_add      (timestamp_t ts1, timestamp_t ts2);
timestamp_t     ts_sub      (timestamp_t ts1, timestamp_t ts2);
timestamp_t     ts_abs_diff (timestamp_t ts1, timestamp_t ts2);

/* Operations for use on offets, i.e. small ts values */
timestamp_t     ts_mul      (timestamp_t ts,  uint32_t x);
timestamp_t     ts_div      (timestamp_t ts,  uint32_t x);

/* ts_gt = timestamp greater than */
int      ts_gt(timestamp_t t1, timestamp_t t2);
int      ts_eq(timestamp_t t1, timestamp_t t2);

/* ts_convert changes timebase of a timestamp */
timestamp_t     ts_convert(uint32_t new_freq, timestamp_t ts);

/* Conversion to milliseconds */
uint32_t timestamp_to_ms(timestamp_t t1);

/* Conversion to microseconds */
uint32_t timestamp_to_us(timestamp_t t1);

/* Debugging functions */
int      ts_valid(timestamp_t t1);
uint32_t ts_get_freq(timestamp_t t1);

typedef struct {
        timestamp_t     last_ts;
        uint32_t last_32;
        uint32_t freq;
} ts_sequencer;

/* These functions should be used for mapping sequences of
 * 32 bit timestamps to timestamp_t and vice-versa.
 */

timestamp_t     ts_seq32_in  (ts_sequencer *s, uint32_t f, uint32_t curr_32);
uint32_t ts_seq32_out (ts_sequencer *s, uint32_t f, timestamp_t     curr_ts);

#endif