EXT_cbtimer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * \file EM_timer.h
  3. *
  4. * This Header File contains the APIs and the ADTs exported by the
  5. * EtherMind Timer Library for Windows (User-mode).
  6. */
  7. /*
  8. * Copyright (C) 2013. Mindtree Ltd.
  9. * All rights reserved.
  10. */
  11. #ifndef _H_EXT_CBTIMER_
  12. #define _H_EXT_CBTIMER_
  13. /* --------------------------------------------------- Header File Inclusion */
  14. #include "EM_os.h"
  15. #include "cbtimer.h"
  16. /* Enable support to get remaining time to expire of a timer entity */
  17. #define EXT_CBTIMER_SUPPORT_REMAINING_TIME
  18. /* --------------------------------------------------- Global Definitions */
  19. /* Maximum number of timer entities */
  20. #define EXT_CBTIMER_MAX_ENTITIES 32
  21. /* Mask to indicate millisecond timeout */
  22. #define EXT_CBTIMEOUT_MILLISEC 0x80000000
  23. /* Timer Handles must be initialized to this value */
  24. #define EXT_CBTIMER_HANDLE_INIT_VAL 0xFF
  25. #define EXT_CBTIMER_STATIC_DATA_SIZE 32
  26. /* Flag: Timer Entity State */
  27. #define EXT_CBTIMER_ENTITY_FREE 0x00
  28. #define EXT_CBTIMER_ENTITY_IN_USE 0x01
  29. #define EXT_CBTIMER_ENTITY_IN_FREE 0x02
  30. /* Flag: Timer Entity Data to be freed or not */
  31. #define EXT_CBTIMER_ENTITY_HOLD_ALLOC_DATA 0x00
  32. #define EXT_CBTIMER_ENTITY_FREE_ALLOC_DATA 0x01
  33. /* Timer module ID and Error codes */
  34. #define EXT_CBTIMER_ERR_ID 0xC000
  35. #define EXT_CBTIMER_MUTEX_INIT_FAILED (0x0001 | EXT_CBTIMER_ERR_ID)
  36. #define EXT_CBTIMER_COND_INIT_FAILED (0x0002 | EXT_CBTIMER_ERR_ID)
  37. #define EXT_CBTIMER_MUTEX_LOCK_FAILED (0x0003 | EXT_CBTIMER_ERR_ID)
  38. #define EXT_CBTIMER_MUTEX_UNLOCK_FAILED (0x0004 | EXT_CBTIMER_ERR_ID)
  39. #define EXT_CBTIMER_MEMORY_ALLOCATION_FAILED (0x0005 | EXT_CBTIMER_ERR_ID)
  40. #define EXT_CBTIMER_HANDLE_IS_NULL (0x0011 | EXT_CBTIMER_ERR_ID)
  41. #define EXT_CBTIMER_CALLBACK_IS_NULL (0x0012 | EXT_CBTIMER_ERR_ID)
  42. #define EXT_CBTIMER_QUEUE_EMPTY (0x0013 | EXT_CBTIMER_ERR_ID)
  43. #define EXT_CBTIMER_QUEUE_FULL (0x0014 | EXT_CBTIMER_ERR_ID)
  44. #define EXT_CBTIMER_ENTITY_SEARCH_FAILED (0x0015 | EXT_CBTIMER_ERR_ID)
  45. #define EXT_CBTIMER_NULL_PARAMETER_NOT_ALLOWED (0x0016 | EXT_CBTIMER_ERR_ID)
  46. #define EXT_CBTIMER_TIMEOUT_ZERO_NOT_ALLOWED (0x0017 | EXT_CBTIMER_ERR_ID)
  47. #define EXT_CBTIMER_FAILED_SET_TIME_EVENT (0x0018 | EXT_CBTIMER_ERR_ID)
  48. /**
  49. * Invalid Timer ID for PhyOS.
  50. * NUM_CBTIMERS is not exposed from osal_cbtimer.c
  51. */
  52. #define EXT_PHYOS_INVALID_TIMER_ID 0xFF
  53. /* ----------------------------------------------- Structures/Data Types */
  54. /* Timer Entity */
  55. typedef struct ext_cbtimer_entity_struct
  56. {
  57. /* The Timer Handle - Index of the timer entity */
  58. UINT8 handle;
  59. /* Callback to call when Timer expires */
  60. void (* callback) (void *, UINT16);
  61. /**
  62. * Timer Callback Parameter if
  63. * data_length > EM_TIMER_STATIC_DATA_SIZE
  64. */
  65. UCHAR *allocated_data;
  66. /* Next Element in the Timer Q */
  67. struct ext_cbtimer_entity_struct *next;
  68. /**
  69. * Timer Callback Parameter if
  70. * data_length <= EM_TIMER_STATIC_DATA_SIZE
  71. */
  72. UCHAR static_data[EXT_CBTIMER_STATIC_DATA_SIZE];
  73. /* Timeout Value asked by the User */
  74. UINT32 timeout;
  75. #ifdef EXT_CBTIMER_SUPPORT_REMAINING_TIME
  76. /* Start Time Stamp - used to calculate remaining time */
  77. UINT64 start_timestamp;
  78. #endif /* EM_TIMER_SUPPORT_REMAINING_TIME */
  79. /* Length of the data */
  80. UINT16 data_length;
  81. /* Is this Entity Allocated ? */
  82. UCHAR in_use;
  83. /* PhyOS Timer ID */
  84. UINT8 timer_id;
  85. } EXT_CBTIMER_ENTITY;
  86. typedef UINT8 EXT_cbtimer_handle;
  87. /* --------------------------------------------------- Function Declarations */
  88. #ifdef __cplusplus
  89. extern "C" {
  90. #endif
  91. void EXT_cbtimer_init ( void );
  92. void ext_cbtimer_em_init ( void );
  93. void ext_cbtimer_em_shutdown ( void );
  94. EM_RESULT EXT_cbtimer_start_timer
  95. (
  96. EXT_cbtimer_handle *handle,
  97. UINT32 timeout,
  98. void (* callback) (void *, UINT16),
  99. void *args, UINT16 size_args
  100. );
  101. EM_RESULT EXT_cbtimer_restart_timer
  102. (
  103. EXT_cbtimer_handle handle,
  104. UINT32 new_timeout
  105. );
  106. EM_RESULT EXT_cbtimer_stop_timer ( EXT_cbtimer_handle handle );
  107. UINT32 EXT_cbtimer_get_remain_timer
  108. (
  109. EXT_cbtimer_handle handle
  110. );
  111. EM_RESULT EXT_cbtimer_get_remaining_time
  112. (
  113. EXT_cbtimer_handle handle,
  114. UINT32 * remaining_time_ms
  115. );
  116. EM_RESULT EXT_cbtimer_is_active_timer ( EXT_cbtimer_handle handle );
  117. /* Debug Routine - Internal Use Only */
  118. EM_RESULT EXT_cbtimer_list_timer ( void );
  119. #ifdef __cplusplus
  120. };
  121. #endif
  122. #endif /* _H_EM_TIMER_ */