blob: dc5e6450cf60e65237bb96bb75edb7974d6aaa15 [file] [log] [blame]
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +01008#include "tfm_nspm_api.h"
9
10#include <string.h>
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020011#include <stdint.h>
12
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +010013#include "cmsis_os2.h"
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020014#include "tfm_ns_svc.h"
15
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +010016/* Translation table pair between OS threads and client IDs */
17struct thread_test_clientid_pair {
18 const char* t_name; /*!< Task/Thread name */
19 int32_t client_id; /*!< Client ID used in assets definition */
20};
21
22static struct thread_test_clientid_pair test_ns_policy_table[] =
23{
24 {"Thread_A", -1},
25 {"Thread_B", -2},
26 {"Thread_C", -3},
27 {"Thread_D", -4},
28 {"seq_task", -5},
29 {"mid_task", -6},
30 {"pri_task", -7},
31};
32
33/**
34 * \brief Gets the client ID based on the thread name
35 *
36 * \return If the thread name is in the test_ns_policy_table, it returns the
37 * client ID. Otherwise, it returns 0 as an error code.
38 */
39static uint32_t get_client_id(void)
40{
41 uint32_t i;
42 static uint32_t test_table_size = (sizeof(test_ns_policy_table) /
43 sizeof(test_ns_policy_table[0]));
44 const char* p_thread_name;
45 osThreadId_t thread_id;
46
47 /* Get thread name */
48 thread_id = osThreadGetId();
49 p_thread_name = osThreadGetName(thread_id);
50
51 for (i = 0; i < test_table_size; i++) {
52 if (strcmp(test_ns_policy_table[i].t_name, p_thread_name) == 0) {
53 return test_ns_policy_table[i].client_id;
54 }
55 }
56
57 return 0;
58}
59
60__attribute__ ((naked))
61static uint32_t tfm_nspm_svc_register_client(uint32_t client_id)
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020062{
63 SVC(SVC_TFM_NSPM_REGISTER_CLIENT_ID);
64 __ASM("BX LR");
65}
66
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +010067uint32_t tfm_nspm_register_client_id(void)
68{
69 uint32_t client_id;
70
71 client_id = get_client_id();
72 if (client_id == 0) {
73 return 0;
74 }
75
76 return tfm_nspm_svc_register_client(client_id);
77}
78
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020079