]> begriffs open source - cmsis-freertos/blob - CMSIS/RTOS2/FreeRTOS/Examples/App/TrustZone/Secure/library_nsc.c
Correct memory allocation and access in osMemoryPoolNew (#142)
[cmsis-freertos] / CMSIS / RTOS2 / FreeRTOS / Examples / App / TrustZone / Secure / library_nsc.c
1 /* -------------------------------------------------------------------------- 
2  * Copyright (c) 2013-2019 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  *      Name:    library_nsc.c
19  *      Purpose: Example function callable from the non-secure domain
20  *
21  *---------------------------------------------------------------------------*/
22  
23 #include <arm_cmse.h>
24 #include "secure_port_macros.h"         // ARM.FreeRTOS::RTOS:TrustZone
25
26 #include "library_nsc.h"                // Non-secure callable function definition
27
28 /* Non-secure function pointer type */
29 typedef void (*NS_Func_t) (void) __attribute__((cmse_nonsecure_call));
30
31
32 /* Secure counter */
33 static uint32_t Count_S = 0U;
34
35 /* Function that can be called from the non-secure application */
36 secureportNON_SECURE_CALLABLE uint32_t Func_NSC (Callback_t callback) {
37   NS_Func_t ns_callback;
38
39   /* Create function pointer to call back non-secure domain */
40   ns_callback = (NS_Func_t)cmse_nsfptr_create(callback);
41
42   /* Execute callback function */
43   ns_callback();
44
45   Count_S += 1U;
46
47   /* Return secure counter value */
48   return Count_S;
49 }