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 /**************************************************************************/ 14 /** */ 15 /** ThreadX Component */ 16 /** */ 17 /** Timer */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define TX_SOURCE_CODE 23 #define TX_THREAD_SMP_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 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _tx_timer_interrupt SMP/Linux/GCC */ 38 /* 6.1 */ 39 /* AUTHOR */ 40 /* */ 41 /* William E. Lamie, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function processes the hardware timer interrupt. This */ 46 /* processing includes incrementing the system clock and checking for */ 47 /* time slice and/or timer expiration. If either is found, the */ 48 /* interrupt context save/restore functions are called along with the */ 49 /* expiration functions. */ 50 /* */ 51 /* INPUT */ 52 /* */ 53 /* None */ 54 /* */ 55 /* OUTPUT */ 56 /* */ 57 /* None */ 58 /* */ 59 /* CALLS */ 60 /* */ 61 /* _tx_linux_debug_entry_insert */ 62 /* _tx_timer_expiration_process */ 63 /* _tx_thread_time_slice */ 64 /* */ 65 /* CALLED BY */ 66 /* */ 67 /* interrupt vector */ 68 /* */ 69 /* RELEASE HISTORY */ 70 /* */ 71 /* DATE NAME DESCRIPTION */ 72 /* */ 73 /* 09-30-2020 William E. Lamie Initial Version 6.1 */ 74 /* */ 75 /**************************************************************************/ _tx_timer_interrupt(VOID)76VOID _tx_timer_interrupt(VOID) 77 { 78 79 UINT saved_posture; 80 81 82 /* Get the protection. */ 83 saved_posture = _tx_thread_smp_protect(); 84 85 /* Increment the system active counter. */ 86 _tx_timer_interrupt_active++; 87 88 /* Debug entry. */ 89 _tx_linux_debug_entry_insert("TIMER INTERRUPT", __FILE__, __LINE__); 90 91 /* Increment the system clock. */ 92 _tx_timer_system_clock++; 93 94 /* Test for timer expiration. */ 95 if (*_tx_timer_current_ptr) 96 { 97 98 /* Set expiration flag. */ 99 _tx_timer_expired = TX_TRUE; 100 } 101 else 102 { 103 104 /* No timer expired, increment the timer pointer. */ 105 _tx_timer_current_ptr++; 106 107 /* Check for wrap-around. */ 108 if (_tx_timer_current_ptr == _tx_timer_list_end) 109 { 110 111 /* Wrap to beginning of list. */ 112 _tx_timer_current_ptr = _tx_timer_list_start; 113 } 114 } 115 116 /* See if anything has expired. */ 117 if (_tx_timer_expired) 118 { 119 120 /* Did a timer expire? */ 121 if (_tx_timer_expired) 122 { 123 124 /* Process timer expiration. */ 125 _tx_timer_expiration_process(); 126 } 127 } 128 129 /* Call time-slice processing to process time-slice for all threads on each core. */ 130 _tx_thread_time_slice(); 131 132 /* Increment the system active counter. */ 133 _tx_timer_interrupt_active++; 134 135 /* Release the protection. */ 136 _tx_thread_smp_unprotect(saved_posture); 137 } 138