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 /* Include necessary system files. */ 26 27 #include "tx_api.h" 28 #include "tx_timer.h" 29 #include "tx_thread.h" 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _tx_timer_interrupt RISC-V64/GNU */ 36 /* 6.2.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Scott Larson, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function processes the hardware timer interrupt. This */ 44 /* processing includes incrementing the system clock and checking for */ 45 /* time slice and/or timer expiration. If either is found, the */ 46 /* interrupt context save/restore functions are called along with the */ 47 /* expiration functions. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* None */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* None */ 56 /* */ 57 /* CALLS */ 58 /* */ 59 /* _tx_timer_expiration_process Timer expiration processing */ 60 /* _tx_thread_time_slice Time slice interrupted thread */ 61 /* */ 62 /* CALLED BY */ 63 /* */ 64 /* interrupt vector */ 65 /* */ 66 /* RELEASE HISTORY */ 67 /* */ 68 /* DATE NAME DESCRIPTION */ 69 /* */ 70 /* 03-08-2023 Scott Larson Initial Version 6.2.1 */ 71 /* */ 72 /**************************************************************************/ _tx_timer_interrupt(VOID)73VOID _tx_timer_interrupt(VOID) 74 { 75 /* Increment system clock. */ 76 _tx_timer_system_clock++; 77 78 /* Test for time-slice expiration. */ 79 if (_tx_timer_time_slice) 80 { 81 /* Decrement the time_slice. */ 82 _tx_timer_time_slice--; 83 84 /* Check for expiration. */ 85 if (_tx_timer_time_slice == 0) 86 { 87 88 /* Set the time-slice expired flag. */ 89 _tx_timer_expired_time_slice = TX_TRUE; 90 } 91 } 92 93 /* Test for timer expiration. */ 94 if (*_tx_timer_current_ptr) 95 { 96 97 /* Set expiration flag. */ 98 _tx_timer_expired = TX_TRUE; 99 } 100 else 101 { 102 103 /* No timer expired, increment the timer pointer. */ 104 _tx_timer_current_ptr++; 105 106 /* Check for wrap-around. */ 107 if (_tx_timer_current_ptr == _tx_timer_list_end) 108 { 109 110 /* Wrap to beginning of list. */ 111 _tx_timer_current_ptr = _tx_timer_list_start; 112 } 113 } 114 115 /* See if anything has expired. */ 116 if ((_tx_timer_expired_time_slice) || (_tx_timer_expired)) 117 { 118 119 /* Did a timer expire? */ 120 if (_tx_timer_expired) 121 { 122 123 /* Process timer expiration. */ 124 _tx_timer_expiration_process(); 125 } 126 127 /* Did time slice expire? */ 128 if (_tx_timer_expired_time_slice) 129 { 130 131 /* Time slice interrupted thread. */ 132 _tx_thread_time_slice(); 133 } 134 } 135 } 136