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