1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28/*=============================================================================
29VideoCore OS Abstraction Layer - timer support
30=============================================================================*/
31
32#ifndef VCOS_TIMER_H
33#define VCOS_TIMER_H
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#include "interface/vcos/vcos_types.h"
40#ifndef VCOS_PLATFORM_H
41#include "vcos.h"
42#endif
43
44/** \file vcos_timer.h
45 *
46 * Timers are single shot.
47 *
48 * Timer times are in milliseconds.
49 *
50 * \note that timer callback functions are called from an arbitrary thread
51 * context. The expiration function should do its work as quickly as possible;
52 * blocking should be avoided.
53 *
54 * \note On Windows, the separate function vcos_timer_init() must be called
55 * as timer initialization from DllMain is not possible.
56 */
57
58/** Perform timer subsystem initialization. This function is not needed
59 * on non-Windows platforms but is still present so that it can be
60 * called. On Windows it is needed because vcos_init() gets called
61 * from DLL initialization where it is not possible to create a
62 * time queue (deadlock occurs if you try).
63 *
64 * @return VCOS_SUCCESS on success. VCOS_EEXIST if this has already been called
65 * once. VCOS_ENOMEM if resource allocation failed.
66 */
67VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_timer_init(void);
68
69/** Create a timer in a disabled state.
70 *
71 * The timer is initially disabled.
72 *
73 * @param timer timer handle
74 * @param name name for timer
75 * @param expiration_routine function to call when timer expires
76 * @param context context passed to expiration routine
77 *
78 */
79VCOS_INLINE_DECL
80VCOS_STATUS_T vcos_timer_create(VCOS_TIMER_T *timer,
81 const char *name,
82 void (*expiration_routine)(void *context),
83 void *context);
84
85
86
87/** Start a timer running.
88 *
89 * Timer must be stopped.
90 *
91 * @param timer timer handle
92 * @param delay Delay to wait for, in ms
93 */
94VCOS_INLINE_DECL
95void vcos_timer_set(VCOS_TIMER_T *timer, VCOS_UNSIGNED delay);
96
97/** Stop an already running timer.
98 *
99 * @param timer timer handle
100 */
101VCOS_INLINE_DECL
102void vcos_timer_cancel(VCOS_TIMER_T *timer);
103
104/** Stop a timer and restart it.
105 * @param timer timer handle
106 * @param delay delay in ms
107 */
108VCOS_INLINE_DECL
109void vcos_timer_reset(VCOS_TIMER_T *timer, VCOS_UNSIGNED delay);
110
111VCOS_INLINE_DECL
112void vcos_timer_delete(VCOS_TIMER_T *timer);
113
114#ifdef __cplusplus
115}
116#endif
117#endif
118