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 24 25 /* Include necessary system files. */ 26 27 #include "tx_api.h" 28 #include "tx_timer.h" 29 #ifdef TX_ENABLE_EVENT_TRACE 30 #include "tx_trace.h" 31 #endif 32 33 34 /**************************************************************************/ 35 /* */ 36 /* FUNCTION RELEASE */ 37 /* */ 38 /* _tx_timer_activate PORTABLE C */ 39 /* 6.1 */ 40 /* AUTHOR */ 41 /* */ 42 /* William E. Lamie, Microsoft Corporation */ 43 /* */ 44 /* DESCRIPTION */ 45 /* */ 46 /* This function activates the specified application timer. */ 47 /* */ 48 /* INPUT */ 49 /* */ 50 /* timer_ptr Pointer to timer control block */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* TX_SUCCESS Always returns success */ 55 /* */ 56 /* CALLS */ 57 /* */ 58 /* _tx_timer_system_activate Actual timer activation function */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* Application Code */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 69 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* */ 72 /**************************************************************************/ _tx_timer_activate(TX_TIMER * timer_ptr)73UINT _tx_timer_activate(TX_TIMER *timer_ptr) 74 { 75 76 TX_INTERRUPT_SAVE_AREA 77 78 UINT status; 79 80 81 /* Disable interrupts to put the timer on the created list. */ 82 TX_DISABLE 83 84 #ifdef TX_ENABLE_EVENT_TRACE 85 86 /* If trace is enabled, insert this event into the trace buffer. */ 87 TX_TRACE_IN_LINE_INSERT(TX_TRACE_TIMER_ACTIVATE, timer_ptr, 0, 0, 0, TX_TRACE_TIMER_EVENTS) 88 #endif 89 90 #ifdef TX_ENABLE_EVENT_LOGGING 91 92 /* Log this kernel call. */ 93 TX_EL_TIMER_ACTIVATE_INSERT 94 #endif 95 96 /* Check for an already active timer. */ 97 if (timer_ptr -> tx_timer_internal.tx_timer_internal_list_head != TX_NULL) 98 { 99 100 /* Timer is already active, return an error. */ 101 status = TX_ACTIVATE_ERROR; 102 } 103 104 /* Check for a timer with a zero expiration. */ 105 else if (timer_ptr -> tx_timer_internal.tx_timer_internal_remaining_ticks == ((ULONG) 0)) 106 { 107 108 /* Timer is being activated with a zero expiration. */ 109 status = TX_ACTIVATE_ERROR; 110 } 111 else 112 { 113 114 #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO 115 116 /* Increment the total activations counter. */ 117 _tx_timer_performance_activate_count++; 118 119 /* Increment the number of activations on this timer. */ 120 timer_ptr -> tx_timer_performance_activate_count++; 121 #endif 122 123 /* Call actual activation function. */ 124 _tx_timer_system_activate(&(timer_ptr -> tx_timer_internal)); 125 126 /* Return a successful status. */ 127 status = TX_SUCCESS; 128 } 129 130 /* Restore interrupts. */ 131 TX_RESTORE 132 133 /* Return completion status. */ 134 return(status); 135 } 136 137