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 /**   Semaphore                                                           */
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_trace.h"
30 #include "tx_semaphore.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _tx_semaphore_put_notify                            PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function registers an application callback function that is    */
46 /*    called whenever the this semaphore is put.                          */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    semaphore_ptr                         Pointer to semaphore          */
51 /*    semaphore_put_notify                  Application callback function */
52 /*                                            (TX_NULL disables notify)   */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Service return status         */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    None                                                                */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
71 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_tx_semaphore_put_notify(TX_SEMAPHORE * semaphore_ptr,VOID (* semaphore_put_notify)(TX_SEMAPHORE * notify_semaphore_ptr))75 UINT  _tx_semaphore_put_notify(TX_SEMAPHORE *semaphore_ptr, VOID (*semaphore_put_notify)(TX_SEMAPHORE *notify_semaphore_ptr))
76 {
77 
78 #ifdef TX_DISABLE_NOTIFY_CALLBACKS
79 
80     TX_SEMAPHORE_NOT_USED(semaphore_ptr);
81     TX_SEMAPHORE_PUT_NOTIFY_NOT_USED(semaphore_put_notify);
82 
83     /* Feature is not enabled, return error.  */
84     return(TX_FEATURE_NOT_ENABLED);
85 #else
86 
87 TX_INTERRUPT_SAVE_AREA
88 
89 
90     /* Disable interrupts.  */
91     TX_DISABLE
92 
93     /* Make entry in event log.  */
94     TX_TRACE_IN_LINE_INSERT(TX_TRACE_SEMAPHORE_PUT_NOTIFY, semaphore_ptr, 0, 0, 0, TX_TRACE_SEMAPHORE_EVENTS)
95 
96     /* Make entry in event log.  */
97     TX_EL_SEMAPHORE_PUT_NOTIFY_INSERT
98 
99     /* Setup semaphore put notification callback function.  */
100     semaphore_ptr -> tx_semaphore_put_notify =  semaphore_put_notify;
101 
102     /* Restore interrupts.  */
103     TX_RESTORE
104 
105     /* Return success to caller.  */
106     return(TX_SUCCESS);
107 #endif
108 }
109 
110