tx_timer.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /***************************************************************************
  2. * Copyright (c) 2024 Microsoft Corporation
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the MIT License which is available at
  6. * https://opensource.org/licenses/MIT.
  7. *
  8. * SPDX-License-Identifier: MIT
  9. **************************************************************************/
  10. /**************************************************************************/
  11. /**************************************************************************/
  12. /** */
  13. /** ThreadX Component */
  14. /** */
  15. /** Timer */
  16. /** */
  17. /**************************************************************************/
  18. /**************************************************************************/
  19. /**************************************************************************/
  20. /* */
  21. /* COMPONENT DEFINITION RELEASE */
  22. /* */
  23. /* tx_timer.h PORTABLE C */
  24. /* 6.1 */
  25. /* AUTHOR */
  26. /* */
  27. /* William E. Lamie, Microsoft Corporation */
  28. /* */
  29. /* DESCRIPTION */
  30. /* */
  31. /* This file defines the ThreadX timer management component, including */
  32. /* data types and external references. It is assumed that tx_api.h */
  33. /* and tx_port.h have already been included. */
  34. /* */
  35. /* RELEASE HISTORY */
  36. /* */
  37. /* DATE NAME DESCRIPTION */
  38. /* */
  39. /* 05-19-2020 William E. Lamie Initial Version 6.0 */
  40. /* 09-30-2020 Yuxin Zhou Modified comment(s), */
  41. /* resulting in version 6.1 */
  42. /* */
  43. /**************************************************************************/
  44. #ifndef TX_TIMER_H
  45. #define TX_TIMER_H
  46. /* Define timer management specific data definitions. */
  47. #define TX_TIMER_ID ((ULONG) 0x4154494D)
  48. #define TX_TIMER_ENTRIES ((ULONG) 32)
  49. /* Define internal timer management function prototypes. */
  50. VOID _tx_timer_expiration_process(VOID);
  51. VOID _tx_timer_initialize(VOID);
  52. VOID _tx_timer_system_activate(TX_TIMER_INTERNAL *timer_ptr);
  53. VOID _tx_timer_system_deactivate(TX_TIMER_INTERNAL *timer_ptr);
  54. VOID _tx_timer_thread_entry(ULONG timer_thread_input);
  55. /* Timer management component data declarations follow. */
  56. /* Determine if the initialization function of this component is including
  57. this file. If so, make the data definitions really happen. Otherwise,
  58. make them extern so other functions in the component can access them. */
  59. #ifdef TX_TIMER_INIT
  60. #define TIMER_DECLARE
  61. #else
  62. #define TIMER_DECLARE extern
  63. #endif
  64. /* Define the system clock value that is continually incremented by the
  65. periodic timer interrupt processing. */
  66. TIMER_DECLARE volatile ULONG _tx_timer_system_clock;
  67. /* Define the current time slice value. If non-zero, a time-slice is active.
  68. Otherwise, the time_slice is not active. */
  69. TIMER_DECLARE ULONG _tx_timer_time_slice;
  70. /* Define the time-slice expiration flag. This is used to indicate that a time-slice
  71. has happened. */
  72. TIMER_DECLARE UINT _tx_timer_expired_time_slice;
  73. /* Define the thread and application timer entry list. This list provides a direct access
  74. method for insertion of times less than TX_TIMER_ENTRIES. */
  75. TIMER_DECLARE TX_TIMER_INTERNAL *_tx_timer_list[TX_TIMER_ENTRIES];
  76. /* Define the boundary pointers to the list. These are setup to easily manage
  77. wrapping the list. */
  78. TIMER_DECLARE TX_TIMER_INTERNAL **_tx_timer_list_start;
  79. TIMER_DECLARE TX_TIMER_INTERNAL **_tx_timer_list_end;
  80. /* Define the current timer pointer in the list. This pointer is moved sequentially
  81. through the timer list by the timer interrupt handler. */
  82. TIMER_DECLARE TX_TIMER_INTERNAL **_tx_timer_current_ptr;
  83. /* Define the timer expiration flag. This is used to indicate that a timer
  84. has expired. */
  85. TIMER_DECLARE UINT _tx_timer_expired;
  86. /* Define the created timer list head pointer. */
  87. TIMER_DECLARE TX_TIMER *_tx_timer_created_ptr;
  88. /* Define the created timer count. */
  89. TIMER_DECLARE ULONG _tx_timer_created_count;
  90. /* Define the pointer to the timer that has expired and is being processed. */
  91. TIMER_DECLARE TX_TIMER_INTERNAL *_tx_timer_expired_timer_ptr;
  92. #ifndef TX_TIMER_PROCESS_IN_ISR
  93. /* Define the timer thread's control block. */
  94. TIMER_DECLARE TX_THREAD _tx_timer_thread;
  95. /* Define the variable that holds the timer thread's starting stack address. */
  96. TIMER_DECLARE VOID *_tx_timer_stack_start;
  97. /* Define the variable that holds the timer thread's stack size. */
  98. TIMER_DECLARE ULONG _tx_timer_stack_size;
  99. /* Define the variable that holds the timer thread's priority. */
  100. TIMER_DECLARE UINT _tx_timer_priority;
  101. /* Define the system timer thread's stack. The default size is defined
  102. in tx_port.h. */
  103. TIMER_DECLARE ULONG _tx_timer_thread_stack_area[(((UINT) TX_TIMER_THREAD_STACK_SIZE)+((sizeof(ULONG)) - ((UINT) 1)))/sizeof(ULONG)];
  104. #else
  105. /* Define the busy flag that will prevent nested timer ISR processing. */
  106. TIMER_DECLARE UINT _tx_timer_processing_active;
  107. #endif
  108. #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
  109. /* Define the total number of timer activations. */
  110. TIMER_DECLARE ULONG _tx_timer_performance_activate_count;
  111. /* Define the total number of timer reactivations. */
  112. TIMER_DECLARE ULONG _tx_timer_performance_reactivate_count;
  113. /* Define the total number of timer deactivations. */
  114. TIMER_DECLARE ULONG _tx_timer_performance_deactivate_count;
  115. /* Define the total number of timer expirations. */
  116. TIMER_DECLARE ULONG _tx_timer_performance_expiration_count;
  117. /* Define the total number of timer expiration adjustments. These are required
  118. if the expiration time is greater than the size of the timer list. In such
  119. cases, the timer is placed at the end of the list and then reactivated
  120. as many times as necessary to finally achieve the resulting timeout. */
  121. TIMER_DECLARE ULONG _tx_timer_performance__expiration_adjust_count;
  122. #endif
  123. /* Define default post timer delete macro to whitespace, if it hasn't been defined previously (typically in tx_port.h). */
  124. #ifndef TX_TIMER_DELETE_PORT_COMPLETION
  125. #define TX_TIMER_DELETE_PORT_COMPLETION(t)
  126. #endif
  127. #endif