alt_alarm.h 4.8 KB

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