]> begriffs open source - cmsis-freertos/blob - CMSIS/RTOS2/FreeRTOS/Examples/App/TrustZone/NonSecure/main_ns.c
Correct memory allocation and access in osMemoryPoolNew (#142)
[cmsis-freertos] / CMSIS / RTOS2 / FreeRTOS / Examples / App / TrustZone / NonSecure / main_ns.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:    main_ns.c
19  *      Purpose: TrustZone Non-Secure Domain example program
20  *
21  *---------------------------------------------------------------------------*/
22 #include <stdio.h>
23 #include "cmsis_os2.h"                  // ::CMSIS:RTOS2
24 #include "FreeRTOS.h"                   // ARM.FreeRTOS::RTOS:Core
25 #include "task.h"                       // ARM.FreeRTOS::RTOS:Core
26
27 /* Secure functions callable from the non-secure application */
28 #include "library_nsc.h"
29
30
31 /* Non-secure counters */
32 uint32_t Count_NS;
33 uint32_t Count_S;
34
35 /* Callback function called from the secure domain */
36 static void Callback_NS (void) {
37   Count_NS += 1U;
38 }
39
40 /* Application main thread (non-secure) */
41 static void app_main (void *arg) {
42   uint32_t count_s;
43
44   /* Allocate secure contex for this task (because it calls secure side) */
45   portALLOCATE_SECURE_CONTEXT (configMINIMAL_SECURE_STACK_SIZE);
46
47   /* Initialize counters */
48   Count_NS = 0U;
49   Count_S  = 0U;
50
51   for (;;) {
52
53     /* Call secure function */
54     count_s = Func_NSC(Callback_NS);
55
56     /* Store returned (secure) counter value */
57     Count_S = count_s;
58
59     printf("Count(NS, S): (%d, %d)\n", Count_NS, Count_S);
60
61     if (Count_S == 10) {
62       printf("\nExample completed.\n");
63
64       osDelay(osWaitForever);
65     }
66   }
67 }
68
69
70 int main (void) {
71
72   // System Initialization
73   SystemCoreClockUpdate();
74
75   osKernelInitialize();                 // Initialize CMSIS-RTOS
76   osThreadNew(app_main, NULL, NULL);    // Create application main thread
77   if (osKernelGetState() == osKernelReady) {
78     osKernelStart();                    // Start thread execution
79   }
80
81   for(;;) {}
82 }