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