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 Pool                                                           */
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 #include "tx_timer.h"
31 #include "tx_byte_pool.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _txe_byte_pool_delete                               PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    William E. Lamie, Microsoft Corporation                             */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function checks for errors in the delete byte pool function    */
47 /*    call.                                                               */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    pool_ptr                          Pointer to pool control block     */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    TX_POOL_ERROR                     Invalid pool pointer              */
56 /*    TX_CALLER_ERROR                   Invalid caller of this function   */
57 /*    status                            Actual completion status          */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _tx_byte_pool_delete              Actual byte pool delete 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_pool_delete(TX_BYTE_POOL * pool_ptr)76 UINT  _txe_byte_pool_delete(TX_BYTE_POOL *pool_ptr)
77 {
78 
79 UINT            status;
80 #ifndef TX_TIMER_PROCESS_IN_ISR
81 TX_THREAD       *thread_ptr;
82 #endif
83 
84 
85 #ifndef TX_TIMER_PROCESS_IN_ISR
86 
87     /* Default status to success.  */
88     status =  TX_SUCCESS;
89 #endif
90 
91     /* Check for an invalid byte pool pointer.  */
92     if (pool_ptr == TX_NULL)
93     {
94 
95         /* Byte pool pointer is invalid, return appropriate error code.  */
96         status =  TX_POOL_ERROR;
97     }
98 
99     /* Now check the pool ID.  */
100     else if (pool_ptr -> tx_byte_pool_id != TX_BYTE_POOL_ID)
101     {
102 
103         /* Byte pool pointer is invalid, return appropriate error code.  */
104         status =  TX_POOL_ERROR;
105     }
106 
107     /* Check for interrupt or initialization.  */
108     else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
109     {
110 
111         /* Invalid caller of this function, return appropriate error code.  */
112         status =  TX_CALLER_ERROR;
113     }
114     else
115     {
116 
117 #ifndef TX_TIMER_PROCESS_IN_ISR
118 
119         /* Pickup thread pointer.  */
120         TX_THREAD_GET_CURRENT(thread_ptr)
121 
122         /* Check for invalid caller of this function.  First check for a calling thread.  */
123         if (thread_ptr == &_tx_timer_thread)
124         {
125 
126             /* Invalid caller of this function, return appropriate error code.  */
127             status =  TX_CALLER_ERROR;
128         }
129 
130         /* Determine if everything is okay.  */
131         if (status == TX_SUCCESS)
132         {
133 #endif
134 
135             /* Call actual byte pool delete function.  */
136             status =  _tx_byte_pool_delete(pool_ptr);
137 
138 #ifndef TX_TIMER_PROCESS_IN_ISR
139         }
140 #endif
141     }
142 
143     /* Return completion status.  */
144     return(status);
145 }
146 
147