Contiki-NG
Loading...
Searching...
No Matches
tz-normal.c
1/*
2 * Copyright (c) 2023, RISE Research Institutes of Sweden
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * \file
36 * TrustZone API setup for normal world.
37 * \author
38 * Niclas Finne <niclas.finne@ri.se>
39 * Nicolas Tsiftes <nicolas.tsiftes@ri.se>
40 */
41
42#include "contiki.h"
43#include "sys/platform.h"
44#include "trustzone/tz-api.h"
45
46/*---------------------------------------------------------------------------*/
47#include "sys/log.h"
48#define LOG_MODULE "TZNormalWorld"
49#define LOG_LEVEL LOG_LEVEL_INFO
50/*---------------------------------------------------------------------------*/
51static volatile bool is_poll_requested;
52
53PROCESS(tz_normal_process, "TZ normal process");
54/*---------------------------------------------------------------------------*/
55static bool
56request_poll(void)
57{
58 is_poll_requested = true;
59 process_poll(&tz_normal_process);
60 return true;
61}
62/*---------------------------------------------------------------------------*/
63static void
64init_tz_api(void)
65{
66 struct tz_api tz_api = {0};
67
68 tz_api.request_poll = request_poll;
69 bool result = tz_api_init(&tz_api);
70 LOG_INFO("Initialize TrustZone API: %s\n",
71 result ? "SUCCESS" : "FAILURE");
72}
73/*---------------------------------------------------------------------------*/
74PROCESS_THREAD(tz_normal_process, ev, data)
75{
77
78 while(true) {
79 PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_POLL);
80 if(is_poll_requested) {
81 is_poll_requested = false;
82 LOG_DBG("> Poll secure world\n");
83 if(tz_api_poll()) {
84 request_poll();
85 }
86 LOG_DBG("< Poll secure world %s!\n",
87 is_poll_requested ? "waiting" : "done");
88 }
89 }
90
92}
93/*---------------------------------------------------------------------------*/
94void
96{
97 init_tz_api();
98 process_start(&tz_normal_process, NULL);
99
100 while(1) {
101 process_num_events_t r;
102 do {
103 r = process_run();
105 } while(r > 0);
106
108 }
109}
110/*---------------------------------------------------------------------------*/
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition watchdog.c:85
void platform_idle()
The platform's idle/sleep function.
Definition platform.c:185
void platform_main_loop(void)
The platform's main loop, if provided.
Definition tz-normal.c:95
process_num_events_t process_run(void)
Run the system once - call poll handlers and process one event.
Definition process.c:305
#define PROCESS(name, strname)
Declare a process.
Definition process.h:308
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition process.h:121
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
Definition process.h:158
#define PROCESS_END()
Define the end of a process.
Definition process.h:132
void process_start(struct process *p, process_data_t data)
Start a process.
Definition process.c:121
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition process.h:274
void process_poll(struct process *p)
Request a process to be polled.
Definition process.c:366
CC_TRUSTZONE_SECURE_CALL bool tz_api_init(struct tz_api *apip)
Initialize the TrustZone API.
Definition tz-api.c:59
CC_TRUSTZONE_SECURE_CALL bool tz_api_poll(void)
Poll the secure world and process all events in the queue.
Definition tz-api.c:90
Header file for the logging system.
Header file for the Contiki-NG main routine.