summaryrefslogtreecommitdiffstats
path: root/main/common/timer.h
blob: b73c63250d9ab0d86e992338619ab4c31a73dc23 (plain) (blame)
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
/**************************************************************************
 *
 * Copyright (c) 2013 Alcatel-Lucent
 *
 * Alcatel Lucent licenses this file to You 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 contained the
 * file LICENSE at the top level of this repository.
 * You may also obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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.
 *
 **************************************************************************
 *
 * timer.h
 *
 * Original author:     Ed Sutter (ed.sutter@alcatel-lucent.com)
 *
 */
#ifndef _TIMER_H_
#define _TIMER_H_

struct elapsed_tmr {
    unsigned long start;            // Start value of elapsed timeout.
    unsigned long tmrval;           // Running timer value
    // (used by elapsed timeout)
    unsigned long currenttmrval;    // Current timer value
    // (not used by elapsed timeout)
    unsigned long tpm;              // Ticks per millisecond

    unsigned long elapsed_low;
    unsigned long elapsed_high;

    unsigned long timeout_low;
    unsigned long timeout_high;

    unsigned long tmrflags;
};

/* Timer flags:
 */
#define HWTMR_ENABLED       (1 << 0)
#define TIMEOUT_OCCURRED    (1 << 1)

/* Timer macros:
 */
#define HWRTMR_IS_ENABLED(tmr)          \
    ((tmr)->tmrflags & HWTMR_ENABLED)

#define ELAPSED_TIMEOUT(tmr)            \
    ((tmr)->tmrflags & TIMEOUT_OCCURRED)

/* uMon API timer commands:
 */
#define TIMER_START     1
#define TIMER_ELAPSED   2
#define TIMER_QUERY     3

extern unsigned long target_timer(void);
extern void startElapsedTimer(struct elapsed_tmr *tmr,long timeout);
extern int msecElapsed(struct elapsed_tmr *tmr);
extern unsigned long msecRemaining(struct elapsed_tmr *tmr);
extern int monTimer(int cmd, void *arg);

#endif