1 // xtensa_overlay_os_hook.c -- Overlay manager OS hooks for FreeRTOS.
2 
3 // Copyright (c) 2015-2015 Cadence Design Systems Inc.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included
14 // in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 
25 #include "FreeRTOS.h"
26 #include "semphr.h"
27 
28 #if configUSE_MUTEX
29 
30 /* Mutex object that controls access to the overlay. Currently only one
31  * overlay region is supported so one mutex suffices.
32  */
33 static SemaphoreHandle_t xt_overlay_mutex;
34 
35 
36 /* This function should be overridden to provide OS specific init such
37  * as the creation of a mutex lock that can be used for overlay locking.
38  * Typically this mutex would be set up with priority inheritance. See
39  * overlay manager documentation for more details.
40  */
xt_overlay_init_os(void)41 void xt_overlay_init_os(void)
42 {
43     /* Create the mutex for overlay access. Priority inheritance is
44      * required.
45      */
46     xt_overlay_mutex = xSemaphoreCreateMutex();
47 }
48 
49 
50 /* This function locks access to shared overlay resources, typically
51  * by acquiring a mutex.
52  */
xt_overlay_lock(void)53 void xt_overlay_lock(void)
54 {
55     xSemaphoreTake(xt_overlay_mutex, 0);
56 }
57 
58 
59 /* This function releases access to shared overlay resources, typically
60  * by unlocking a mutex.
61  */
xt_overlay_unlock(void)62 void xt_overlay_unlock(void)
63 {
64     xSemaphoreGive(xt_overlay_mutex);
65 }
66 
67 #endif
68