timer_ticks.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 ser, a free SIP server.
  10. *
  11. * ser 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. * For a license to use the ser software under conditions
  17. * other than those described here, or to purchase support for this
  18. * software, please contact iptel.org by e-mail at the following addresses:
  19. * [email protected]
  20. *
  21. * ser is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. /* History:
  31. * --------
  32. * 2005-07-27 complete re-design/re-implemnetation (andrei)
  33. * 2007-07-02 added ticks comparison macros (andrei)
  34. */
  35. #ifndef _timer_ticks_h
  36. #define _timer_ticks_h
  37. /* how many ticks per second (must >1 and < 100 (on linux x86))
  38. * recomended values >=8, <=32 (a 2^k value is better/faster)*/
  39. #define TIMER_TICKS_HZ 16U
  40. /* how many ticks per m milliseconds? (rounded up) */
  41. #define MS_TO_TICKS(m) (((m)*TIMER_TICKS_HZ+999U)/1000U)
  42. /* how many ticks per s seconds? */
  43. #define S_TO_TICKS(s) ((s)*TIMER_TICKS_HZ)
  44. /* how many s pe per t ticks, integer value */
  45. #define TICKS_TO_S(t) ((t)/TIMER_TICKS_HZ)
  46. /* how many ms per t ticks, integer value */
  47. #define TICKS_TO_MS(t) (((t)*1000U)/TIMER_TICKS_HZ)
  48. /* ticks comparison operations: t1 OP t2, where OP can be <, >, <=, >= */
  49. #define TICKS_CMP_OP(t1, t2, OP) \
  50. (((s_ticks_t)((ticks_t)(t1)-(ticks_t)(t2))) OP (s_ticks_t)0)
  51. /* t1 < t2 */
  52. #define TICKS_LT(t1, t2) TICKS_CMP_OP(t1, t2, <)
  53. /* t1 <= t2 */
  54. #define TICKS_LE(t1, t2) TICKS_CMP_OP(t1, t2, <=)
  55. /* t1 > t2 */
  56. #define TICKS_GT(t1, t2) TICKS_CMP_OP(t1, t2, >)
  57. /* t1 >= t2 */
  58. #define TICKS_GE(t1, t2) TICKS_CMP_OP(t1, t2, >=)
  59. typedef unsigned int ticks_t;/* type used to keep the ticks (must be 32 bits)*/
  60. typedef signed int s_ticks_t; /* signed ticks type */
  61. #endif