1 /**************************************************************************/
2 /*   Copyright (c) Cadence Design Systems, Inc.                           */
3 /*                                                                        */
4 /* Permission is hereby granted, free of charge, to any person obtaining  */
5 /* a copy of this software and associated documentation files (the        */
6 /* "Software"), to deal in the Software without restriction, including    */
7 /* without limitation the rights to use, copy, modify, merge, publish,    */
8 /* distribute, sublicense, and/or sell copies of the Software, and to     */
9 /* permit persons to whom the Software is furnished to do so, subject to  */
10 /* the following conditions:                                              */
11 /*                                                                        */
12 /* The above copyright notice and this permission notice shall be         */
13 /* included in all copies or substantial portions of the Software.        */
14 /*                                                                        */
15 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
16 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
17 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
18 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
19 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
20 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
21 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
22 /**************************************************************************/
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  DESCRIPTION                                                           */
27 /*                                                                        */
28 /*  Xtensa overlay manager OS hooks for ThreadX. XEA2 only.               */
29 /*                                                                        */
30 /*  RELEASE HISTORY                                                       */
31 /*                                                                        */
32 /*    DATE              NAME                      DESCRIPTION             */
33 /*                                                                        */
34 /*  12-31-2020     Cadence Design Systems   Initial Version 6.1.3         */
35 /*                                                                        */
36 /**************************************************************************/
37 
38 
39 #ifdef XT_USE_OVLY
40 
41 #include <xtensa/overlay.h>
42 #include "tx_api.h"
43 
44 
45 /* Required to work around a bug in the overlay header. */
46 #ifdef XT_DISABLE_OVERLAYS
47 #undef  xt_overlay_fatal_error
48 #define xt_overlay_fatal_error(id)
49 #endif
50 
51 
52 /* Mutex object that controls access to the overlay. Currently only one
53  * overlay region is supported so one mutex suffices.
54  */
55 static TX_MUTEX xt_overlay_mutex;
56 
57 
58 /**************************************************************************/
59 /*  This function should be overridden to provide OS specific init such   */
60 /*  as the creation of a mutex lock that can be used for overlay locking. */
61 /*  Typically this mutex would be set up with priority inheritance. See   */
62 /* overlay manager documentation for more details.                        */
63 /**************************************************************************/
64 void
xt_overlay_init_os(void)65 xt_overlay_init_os(void)
66 {
67     /* Create the mutex for overlay access. Priority inheritance is
68      * required.
69      */
70     UINT status =
71         tx_mutex_create (&xt_overlay_mutex, "xt_overlay_lock", TX_INHERIT);
72 
73     if (status != TX_SUCCESS) {
74         xt_overlay_fatal_error (-1);
75     }
76 }
77 
78 
79 /**************************************************************************/
80 /* This function locks access to shared overlay resources, typically      */
81 /* by acquiring a mutex.                                                  */
82 /**************************************************************************/
83 void
xt_overlay_lock(void)84 xt_overlay_lock(void)
85 {
86     UINT status = tx_mutex_get (&xt_overlay_mutex, TX_WAIT_FOREVER);
87 
88     if (status != TX_SUCCESS) {
89         xt_overlay_fatal_error (-1);
90     }
91 }
92 
93 
94 /**************************************************************************/
95 /* This function releases access to shared overlay resources, typically   */
96 /* by unlocking a mutex.                                                  */
97 /**************************************************************************/
98 void
xt_overlay_unlock(void)99 xt_overlay_unlock(void)
100 {
101     UINT status = tx_mutex_put (&xt_overlay_mutex);
102 
103     if (status != TX_SUCCESS) {
104         xt_overlay_fatal_error (-1);
105     }
106 }
107 
108 #endif /* XT_USE_OVLY */
109 
110