1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** ThreadX Component */ 17 /** */ 18 /** Timer */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define TX_SOURCE_CODE 24 25 26 /* Include necessary system files. */ 27 28 #include "tx_api.h" 29 #include "tx_timer.h" 30 #include "tx_thread.h" 31 32 33 VOID _tx_timer_interrupt(VOID); 34 /**************************************************************************/ 35 /* */ 36 /* FUNCTION RELEASE */ 37 /* */ 38 /* _tx_timer_interrupt Linux/GNU */ 39 /* 6.1 */ 40 /* AUTHOR */ 41 /* */ 42 /* William E. Lamie, Microsoft Corporation */ 43 /* */ 44 /* DESCRIPTION */ 45 /* */ 46 /* This function processes the hardware timer interrupt. This */ 47 /* processing includes incrementing the system clock and checking for */ 48 /* time slice and/or timer expiration. If either is found, the */ 49 /* interrupt context save/restore functions are called along with the */ 50 /* expiration functions. */ 51 /* */ 52 /* INPUT */ 53 /* */ 54 /* None */ 55 /* */ 56 /* OUTPUT */ 57 /* */ 58 /* None */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* _tx_linux_debug_entry_insert */ 63 /* tx_linux_mutex_lock */ 64 /* tx_linux_mutex_unlock */ 65 /* _tx_timer_expiration_process */ 66 /* _tx_thread_time_slice */ 67 /* */ 68 /* CALLED BY */ 69 /* */ 70 /* interrupt vector */ 71 /* */ 72 /* RELEASE HISTORY */ 73 /* */ 74 /* DATE NAME DESCRIPTION */ 75 /* */ 76 /* 09-30-2020 William E. Lamie Initial Version 6.1 */ 77 /* */ 78 /**************************************************************************/ _tx_timer_interrupt(VOID)79VOID _tx_timer_interrupt(VOID) 80 { 81 82 /* Debug entry. */ 83 _tx_linux_debug_entry_insert("TIMER INTERRUPT", __FILE__, __LINE__); 84 85 /* Lock mutex to ensure other threads are not playing with 86 the core ThreadX data structures. */ 87 tx_linux_mutex_lock(_tx_linux_mutex); 88 89 /* Increment the system clock. */ 90 _tx_timer_system_clock++; 91 92 /* Test for time-slice expiration. */ 93 if (_tx_timer_time_slice) 94 { 95 96 /* Decrement the time_slice. */ 97 _tx_timer_time_slice--; 98 99 /* Check for expiration. */ 100 if (_tx_timer_time_slice == 0) 101 { 102 103 /* Set the time-slice expired flag. */ 104 _tx_timer_expired_time_slice = TX_TRUE; 105 } 106 } 107 108 /* Test for timer expiration. */ 109 if (*_tx_timer_current_ptr) 110 { 111 112 /* Set expiration flag. */ 113 _tx_timer_expired = TX_TRUE; 114 } 115 else 116 { 117 118 /* No timer expired, increment the timer pointer. */ 119 _tx_timer_current_ptr++; 120 121 /* Check for wrap-around. */ 122 if (_tx_timer_current_ptr == _tx_timer_list_end) 123 { 124 125 /* Wrap to beginning of list. */ 126 _tx_timer_current_ptr = _tx_timer_list_start; 127 } 128 } 129 130 /* See if anything has expired. */ 131 if ((_tx_timer_expired_time_slice) || (_tx_timer_expired)) 132 { 133 134 /* Did a timer expire? */ 135 if (_tx_timer_expired) 136 { 137 138 /* Process timer expiration. */ 139 _tx_timer_expiration_process(); 140 } 141 142 /* Did time slice expire? */ 143 if (_tx_timer_expired_time_slice) 144 { 145 146 /* Time slice interrupted thread. */ 147 _tx_thread_time_slice(); 148 } 149 } 150 151 /* Unlock linux mutex. */ 152 tx_linux_mutex_unlock(_tx_linux_mutex); 153 } 154 155