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 /** Module Manager */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define TX_SOURCE_CODE 23 24 #include "tx_api.h" 25 #include "tx_mutex.h" 26 #include "txm_module.h" 27 28 29 /**************************************************************************/ 30 /* */ 31 /* FUNCTION RELEASE */ 32 /* */ 33 /* _txm_module_manager_maximum_module_priority_set PORTABLE C */ 34 /* 6.1 */ 35 /* AUTHOR */ 36 /* */ 37 /* Scott Larson, Microsoft Corporation */ 38 /* */ 39 /* DESCRIPTION */ 40 /* */ 41 /* This function sets the maximum thread priority allowed in a module. */ 42 /* */ 43 /* INPUT */ 44 /* */ 45 /* module_instance Module instance pointer */ 46 /* priority Maximum thread priority */ 47 /* */ 48 /* OUTPUT */ 49 /* */ 50 /* status Completion status */ 51 /* */ 52 /* CALLS */ 53 /* */ 54 /* _tx_mutex_get Get protection mutex */ 55 /* _tx_mutex_put Release protection mutex */ 56 /* */ 57 /* CALLED BY */ 58 /* */ 59 /* Application code */ 60 /* */ 61 /* RELEASE HISTORY */ 62 /* */ 63 /* DATE NAME DESCRIPTION */ 64 /* */ 65 /* 09-30-2020 Scott Larson Initial Version 6.1 */ 66 /* */ 67 /**************************************************************************/ _txm_module_manager_maximum_module_priority_set(TXM_MODULE_INSTANCE * module_instance,UINT priority)68UINT _txm_module_manager_maximum_module_priority_set(TXM_MODULE_INSTANCE *module_instance, UINT priority) 69 { 70 /* Determine if the module manager has not been initialized yet. */ 71 if (_txm_module_manager_ready != TX_TRUE) 72 { 73 /* Module manager has not been initialized. */ 74 return(TX_NOT_AVAILABLE); 75 } 76 77 /* Determine if the module is valid. */ 78 if (module_instance == TX_NULL) 79 { 80 /* Invalid module pointer. */ 81 return(TX_PTR_ERROR); 82 } 83 84 /* Get module manager protection mutex. */ 85 _tx_mutex_get(&_txm_module_manager_mutex, TX_WAIT_FOREVER); 86 87 /* Determine if the module instance is valid. */ 88 if (module_instance -> txm_module_instance_id != TXM_MODULE_ID) 89 { 90 /* Release the protection mutex. */ 91 _tx_mutex_put(&_txm_module_manager_mutex); 92 93 /* Invalid module pointer. */ 94 return(TX_PTR_ERROR); 95 } 96 97 /* Determine if the module instance is in the loaded state. */ 98 if ((module_instance -> txm_module_instance_state != TXM_MODULE_LOADED) && (module_instance -> txm_module_instance_state != TXM_MODULE_STOPPED)) 99 { 100 /* Release the protection mutex. */ 101 _tx_mutex_put(&_txm_module_manager_mutex); 102 103 /* Return error if the module is not ready. */ 104 return(TX_START_ERROR); 105 } 106 107 108 /* Set module's maximum priority. */ 109 module_instance->txm_module_instance_maximum_priority = priority; 110 111 /* Release the protection mutex. */ 112 _tx_mutex_put(&_txm_module_manager_mutex); 113 114 return(TX_SUCCESS); 115 } 116