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_thread.h" 29 #include "tx_timer.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _txe_timer_delete PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* William E. Lamie, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function checks for errors in the delete application timer */ 45 /* function call. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* timer_ptr Pointer to timer control block */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* TX_TIMER_ERROR Invalid application timer pointer */ 54 /* TX_CALLER_ERROR Invalid caller of this function */ 55 /* status Actual completion status */ 56 /* */ 57 /* CALLS */ 58 /* */ 59 /* _tx_timer_delete Actual timer delete function */ 60 /* */ 61 /* CALLED BY */ 62 /* */ 63 /* Application Code */ 64 /* */ 65 /* RELEASE HISTORY */ 66 /* */ 67 /* DATE NAME DESCRIPTION */ 68 /* */ 69 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 70 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 71 /* resulting in version 6.1 */ 72 /* */ 73 /**************************************************************************/ _txe_timer_delete(TX_TIMER * timer_ptr)74UINT _txe_timer_delete(TX_TIMER *timer_ptr) 75 { 76 77 UINT status; 78 #ifndef TX_TIMER_PROCESS_IN_ISR 79 TX_THREAD *thread_ptr; 80 #endif 81 82 83 #ifndef TX_TIMER_PROCESS_IN_ISR 84 85 /* Default status to success. */ 86 status = TX_SUCCESS; 87 #endif 88 89 /* Check for an invalid timer pointer. */ 90 if (timer_ptr == TX_NULL) 91 { 92 /* Timer pointer is invalid, return appropriate error code. */ 93 status = TX_TIMER_ERROR; 94 } 95 96 /* Now check for invalid timer ID. */ 97 else if (timer_ptr -> tx_timer_id != TX_TIMER_ID) 98 { 99 /* Timer pointer is invalid, return appropriate error code. */ 100 status = TX_TIMER_ERROR; 101 } 102 103 /* Check for invalid caller of this function. */ 104 105 /* Is the caller an ISR or Initialization? */ 106 else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0)) 107 { 108 109 /* Invalid caller of this function, return appropriate error code. */ 110 status = TX_CALLER_ERROR; 111 } 112 else 113 { 114 115 #ifndef TX_TIMER_PROCESS_IN_ISR 116 117 /* Pickup thread pointer. */ 118 TX_THREAD_GET_CURRENT(thread_ptr) 119 120 /* Is the caller the system timer thread? */ 121 if (thread_ptr == &_tx_timer_thread) 122 { 123 124 /* Invalid caller of this function, return appropriate error code. */ 125 status = TX_CALLER_ERROR; 126 } 127 128 /* Determine if everything is okay. */ 129 if (status == TX_SUCCESS) 130 { 131 #endif 132 133 /* Call actual application timer delete function. */ 134 status = _tx_timer_delete(timer_ptr); 135 136 #ifndef TX_TIMER_PROCESS_IN_ISR 137 } 138 #endif 139 } 140 141 /* Return completion status. */ 142 return(status); 143 } 144 145