1 |
2 |
alfik |
#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 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
30 |
|
|
* of California and by the laws of the United States of America. *
|
31 |
|
|
* *
|
32 |
|
|
* Altera does not recommend, suggest or require that this reference design *
|
33 |
|
|
* file be used in conjunction or combination with any other product. *
|
34 |
|
|
******************************************************************************/
|
35 |
|
|
|
36 |
|
|
/******************************************************************************
|
37 |
|
|
* *
|
38 |
|
|
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
39 |
|
|
* *
|
40 |
|
|
******************************************************************************/
|
41 |
|
|
|
42 |
|
|
#include "alt_llist.h"
|
43 |
|
|
#include "alt_types.h"
|
44 |
|
|
|
45 |
|
|
#include "priv/alt_alarm.h"
|
46 |
|
|
|
47 |
|
|
#ifdef __cplusplus
|
48 |
|
|
extern "C"
|
49 |
|
|
{
|
50 |
|
|
#endif /* __cplusplus */
|
51 |
|
|
|
52 |
|
|
/*
|
53 |
|
|
* "alt_alarm" is a structure type used by applications to register an alarm
|
54 |
|
|
* callback function. An instance of this type must be passed as an input
|
55 |
|
|
* argument to alt_alarm_start(). The user is not responsible for initialising
|
56 |
|
|
* the contents of the instance. This is done by alt_alarm_start().
|
57 |
|
|
*/
|
58 |
|
|
|
59 |
|
|
typedef struct alt_alarm_s alt_alarm;
|
60 |
|
|
|
61 |
|
|
/*
|
62 |
|
|
* alt_alarm_start() can be called by an application/driver in order to register
|
63 |
|
|
* a function for periodic callback at the system clock frequency. Be aware that
|
64 |
|
|
* this callback is likely to occur in interrupt context.
|
65 |
|
|
*/
|
66 |
|
|
|
67 |
|
|
extern int alt_alarm_start (alt_alarm* the_alarm,
|
68 |
|
|
alt_u32 nticks,
|
69 |
|
|
alt_u32 (*callback) (void* context),
|
70 |
|
|
void* context);
|
71 |
|
|
|
72 |
|
|
/*
|
73 |
|
|
* alt_alarm_stop() is used to unregister a callback. Alternatively the callback
|
74 |
|
|
* can return zero to unregister.
|
75 |
|
|
*/
|
76 |
|
|
|
77 |
|
|
extern void alt_alarm_stop (alt_alarm* the_alarm);
|
78 |
|
|
|
79 |
|
|
/*
|
80 |
|
|
* Obtain the system clock rate in ticks/s.
|
81 |
|
|
*/
|
82 |
|
|
|
83 |
|
|
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_ticks_per_second (void)
|
84 |
|
|
{
|
85 |
|
|
return _alt_tick_rate;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/*
|
89 |
|
|
* alt_sysclk_init() is intended to be only used by the system clock driver
|
90 |
|
|
* in order to initialise the value of the clock frequency.
|
91 |
|
|
*/
|
92 |
|
|
|
93 |
|
|
static ALT_INLINE int ALT_ALWAYS_INLINE alt_sysclk_init (alt_u32 nticks)
|
94 |
|
|
{
|
95 |
|
|
if (! _alt_tick_rate)
|
96 |
|
|
{
|
97 |
|
|
_alt_tick_rate = nticks;
|
98 |
|
|
return 0;
|
99 |
|
|
}
|
100 |
|
|
else
|
101 |
|
|
{
|
102 |
|
|
return -1;
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
/*
|
107 |
|
|
* alt_nticks() returns the elapsed number of system clock ticks since reset.
|
108 |
|
|
*/
|
109 |
|
|
|
110 |
|
|
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_nticks (void)
|
111 |
|
|
{
|
112 |
|
|
return _alt_nticks;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
/*
|
116 |
|
|
* alt_tick() should only be called by the system clock driver. This is used
|
117 |
|
|
* to notify the system that the system timer period has expired.
|
118 |
|
|
*/
|
119 |
|
|
|
120 |
|
|
extern void alt_tick (void);
|
121 |
|
|
|
122 |
|
|
#ifdef __cplusplus
|
123 |
|
|
}
|
124 |
|
|
#endif
|
125 |
|
|
|
126 |
|
|
#endif /* __ALT_ALARM_H__ */
|