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