1 /* --------------------------------------------------------------------------
2 * Copyright (c) 2013-2019 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
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
10 * www.apache.org/licenses/LICENSE-2.0
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.
19 * Purpose: TrustZone Non-Secure Domain example program
21 *---------------------------------------------------------------------------*/
23 #include "cmsis_os2.h" // ::CMSIS:RTOS2
24 #include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core
25 #include "task.h" // ARM.FreeRTOS::RTOS:Core
27 /* Secure functions callable from the non-secure application */
28 #include "library_nsc.h"
31 /* Non-secure counters */
35 /* Callback function called from the secure domain */
36 static void Callback_NS (void) {
40 /* Application main thread (non-secure) */
41 static void app_main (void *arg) {
44 /* Allocate secure contex for this task (because it calls secure side) */
45 portALLOCATE_SECURE_CONTEXT (configMINIMAL_SECURE_STACK_SIZE);
47 /* Initialize counters */
53 /* Call secure function */
54 count_s = Func_NSC(Callback_NS);
56 /* Store returned (secure) counter value */
59 printf("Count(NS, S): (%d, %d)\n", Count_NS, Count_S);
62 printf("\nExample completed.\n");
64 osDelay(osWaitForever);
72 // System Initialization
73 SystemCoreClockUpdate();
75 osKernelInitialize(); // Initialize CMSIS-RTOS
76 osThreadNew(app_main, NULL, NULL); // Create application main thread
77 if (osKernelGetState() == osKernelReady) {
78 osKernelStart(); // Start thread execution