timer_ticks.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * $Id$
  3. *
  4. *
  5. * timer frequency and ticks conversions
  6. *
  7. * Copyright (C) 2005 iptelorg GmbH
  8. *
  9. * This file is part of SIP-router, a free SIP server.
  10. *
  11. * SIP-router is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version
  15. *
  16. * SIP-router is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. /* History:
  26. * --------
  27. * 2005-07-27 complete re-design/re-implemnetation (andrei)
  28. * 2007-07-02 added ticks comparison macros (andrei)
  29. */
  30. /**
  31. * @file
  32. * @brief SIP-router core :: timer frequency and ticks conversions
  33. * @ingroup core
  34. * Module: @ref core
  35. */
  36. #ifndef _timer_ticks_h
  37. #define _timer_ticks_h
  38. /** @brief how many ticks per second (must >1 and < 100 (on linux x86))
  39. * recomended values >=8, <=32 (a 2^k value is better/faster)*/
  40. #define TIMER_TICKS_HZ 16U
  41. /** @brief how many ticks per m milliseconds? (rounded up) */
  42. #define MS_TO_TICKS(m) (((m)*TIMER_TICKS_HZ+999U)/1000U)
  43. /** @brief how many ticks per s seconds? */
  44. #define S_TO_TICKS(s) ((s)*TIMER_TICKS_HZ)
  45. /** @brief how many s pe per t ticks, integer value */
  46. #define TICKS_TO_S(t) ((t)/TIMER_TICKS_HZ)
  47. /** @brief how many ms per t ticks, integer value */
  48. #define TICKS_TO_MS(t) (((t)*1000U)/TIMER_TICKS_HZ)
  49. /** @brief ticks comparison operations: t1 OP t2, where OP can be <, >, <=, >= */
  50. #define TICKS_CMP_OP(t1, t2, OP) \
  51. (((s_ticks_t)((ticks_t)(t1)-(ticks_t)(t2))) OP (s_ticks_t)0)
  52. /** @brief t1 < t2 */
  53. #define TICKS_LT(t1, t2) TICKS_CMP_OP(t1, t2, <)
  54. /** @brief t1 <= t2 */
  55. #define TICKS_LE(t1, t2) TICKS_CMP_OP(t1, t2, <=)
  56. /** @brief t1 > t2 */
  57. #define TICKS_GT(t1, t2) TICKS_CMP_OP(t1, t2, >)
  58. /** @brief t1 >= t2 */
  59. #define TICKS_GE(t1, t2) TICKS_CMP_OP(t1, t2, >=)
  60. typedef unsigned int ticks_t;/* type used to keep the ticks (must be 32 bits)*/
  61. typedef signed int s_ticks_t; /* signed ticks type */
  62. #endif