1 #ifndef __ALT_ALARM_H__
2 #define __ALT_ALARM_H__
3
4 /******************************************************************************
5 * *
6 * License Agreement *
7 * *
8 * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
9 * All rights reserved. *
10 * *
11 * Permission is hereby granted, free of charge, to any person obtaining a *
12 * copy of this software and associated documentation files (the "Software"), *
13 * to deal in the Software without restriction, including without limitation *
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
15 * and/or sell copies of the Software, and to permit persons to whom the *
16 * Software is furnished to do so, subject to the following conditions: *
17 * *
18 * The above copyright notice and this permission notice shall be included in *
19 * all copies or substantial portions of the Software. *
20 * *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
27 * DEALINGS IN THE SOFTWARE. *
28 * *
29 * *
30 * Altera does not recommend, suggest or require that this reference design *
31 * file be used in conjunction or combination with any other product. *
32 ******************************************************************************/
33
34 /******************************************************************************
35 * *
36 * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
37 * *
38 ******************************************************************************/
39
40 #include "alt_llist.h"
41 #include "alt_types.h"
42
43 #include "priv/alt_alarm.h"
44
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #endif /* __cplusplus */
49
50 /*
51 * "alt_alarm" is a structure type used by applications to register an alarm
52 * callback function. An instance of this type must be passed as an input
53 * argument to alt_alarm_start(). The user is not responsible for initialising
54 * the contents of the instance. This is done by alt_alarm_start().
55 */
56
57 typedef struct alt_alarm_s alt_alarm;
58
59 /*
60 * alt_alarm_start() can be called by an application/driver in order to register
61 * a function for periodic callback at the system clock frequency. Be aware that
62 * this callback is likely to occur in interrupt context.
63 */
64
65 extern int alt_alarm_start (alt_alarm* the_alarm,
66 alt_u32 nticks,
67 alt_u32 (*callback) (void* context),
68 void* context);
69
70 /*
71 * alt_alarm_stop() is used to unregister a callback. Alternatively the callback
72 * can return zero to unregister.
73 */
74
75 extern void alt_alarm_stop (alt_alarm* the_alarm);
76
77 #ifndef ZEPHYR_RTOS
78 /*
79 * Obtain the system clock rate in ticks/s.
80 */
81
alt_ticks_per_second(void)82 static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_ticks_per_second (void)
83 {
84 return _alt_tick_rate;
85 }
86
87 /*
88 * alt_sysclk_init() is intended to be only used by the system clock driver
89 * in order to initialise the value of the clock frequency.
90 */
91
alt_sysclk_init(alt_u32 nticks)92 static ALT_INLINE int ALT_ALWAYS_INLINE alt_sysclk_init (alt_u32 nticks)
93 {
94 if (! _alt_tick_rate)
95 {
96 _alt_tick_rate = nticks;
97 return 0;
98 }
99 else
100 {
101 return -1;
102 }
103 }
104
105 /*
106 * alt_nticks() returns the elapsed number of system clock ticks since reset.
107 */
108
alt_nticks(void)109 static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_nticks (void)
110 {
111 return _alt_nticks;
112 }
113
114 /*
115 * alt_tick() should only be called by the system clock driver. This is used
116 * to notify the system that the system timer period has expired.
117 */
118
119 extern void alt_tick (void);
120 #else
121 /*
122 * Obtain the system clock rate in ticks/s.
123 */
124
alt_ticks_per_second(void)125 static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_ticks_per_second (void)
126 {
127 return 0;
128 }
129
130 /*
131 * alt_sysclk_init() is intended to be only used by the system clock driver
132 * in order to initialise the value of the clock frequency.
133 */
134
alt_sysclk_init(alt_u32 nticks)135 static ALT_INLINE int ALT_ALWAYS_INLINE alt_sysclk_init (alt_u32 nticks)
136 {
137 return 0;
138 }
139
140 /*
141 * alt_nticks() returns the elapsed number of system clock ticks since reset.
142 */
143
alt_nticks(void)144 static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_nticks (void)
145 {
146 return 0;
147 }
148
149 /*
150 * alt_tick() should only be called by the system clock driver. This is used
151 * to notify the system that the system timer period has expired.
152 */
153
154 extern void alt_tick (void);
155 #endif
156
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif /* __ALT_ALARM_H__ */
162