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 /**   Thread                                                              */
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_thread.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _txe_thread_priority_change                         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 change priority function     */
45 /*    call.                                                               */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    thread_ptr                            Pointer to thread to suspend  */
50 /*    new_priority                          New thread priority           */
51 /*    old_priority                          Old thread priority           */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    TX_THREAD_ERROR                       Invalid thread pointer        */
56 /*    TX_PTR_ERROR                          Invalid old priority pointer  */
57 /*    TX_CALLER_ERROR                       Invalid caller of function    */
58 /*    status                                Actual completion status      */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _tx_thread_priority_change            Actual priority change        */
63 /*                                            function                    */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_txe_thread_priority_change(TX_THREAD * thread_ptr,UINT new_priority,UINT * old_priority)78 UINT  _txe_thread_priority_change(TX_THREAD *thread_ptr, UINT new_priority, UINT *old_priority)
79 {
80 
81 UINT        status;
82 
83 
84     /* Check for an invalid thread pointer.  */
85     if (thread_ptr == TX_NULL)
86     {
87 
88         /* Thread pointer is invalid, return appropriate error code.  */
89         status =  TX_THREAD_ERROR;
90     }
91 
92     /* Now check for invalid thread ID.  */
93     else if (thread_ptr -> tx_thread_id != TX_THREAD_ID)
94     {
95 
96         /* Thread pointer is invalid, return appropriate error code.  */
97         status =  TX_THREAD_ERROR;
98     }
99 
100     /* Check for a valid old priority pointer.  */
101     else if (old_priority == TX_NULL)
102     {
103 
104         /* Invalid destination pointer, return appropriate error code.  */
105         status =  TX_PTR_ERROR;
106     }
107 
108     /* Determine if the priority is legal.  */
109     else if (new_priority >= ((UINT) TX_MAX_PRIORITIES))
110     {
111 
112         /* Return an error status.  */
113         status =  TX_PRIORITY_ERROR;
114     }
115 
116     /* Check for invalid caller of this function.  */
117     else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
118     {
119 
120         /* Invalid caller of this function, return appropriate error code.  */
121         status =  TX_CALLER_ERROR;
122     }
123     else
124     {
125 
126         /* Call actual change thread priority function.  */
127         status =  _tx_thread_priority_change(thread_ptr, new_priority, old_priority);
128     }
129 
130     /* Return completion status.  */
131     return(status);
132 }
133 
134