aboutsummaryrefslogtreecommitdiff
path: root/interface/src/multi_core/tfm_ns_mailbox_rtos_api.c
blob: f7d23d2bc44f5663efcce832cb63e6bd8f071bff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

/*
 * This file is a reference implementation of Non-secure mailbox RTOS API.
 * This reference implementation is based on TF-M ROTS wrapper API.
 * It can be replaced by RTOS specific implementation.
 */

#include "os_wrapper/semaphore.h"
#include "os_wrapper/thread.h"

#include "tfm_ns_mailbox.h"

#define MAX_SEMAPHORE_COUNT            NUM_MAILBOX_QUEUE_SLOT

/*
 * Thread flag to manage wait/wake mechanism in mailbox.、
 * Thread flag can be RTOS specific.
 * The following example definition also covers the rule of CMSIS-RTOS2, which
 * requires the MSB of thread flags must be 0b0.
 */
#define MAILBOX_THREAD_FLAG            0x5FCA0000

static void *ns_lock_handle = NULL;

#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
const void *tfm_ns_mailbox_os_get_task_handle(void)
{
    return os_wrapper_thread_get_handle();
}

void tfm_ns_mailbox_os_wait_reply(void)
{
    os_wrapper_thread_wait_flag(MAILBOX_THREAD_FLAG, OS_WRAPPER_WAIT_FOREVER);
}

void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle)
{
    os_wrapper_thread_set_flag_isr((void *)task_handle, MAILBOX_THREAD_FLAG);
}
#endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */

int32_t tfm_ns_mailbox_os_lock_init(void)
{
    ns_lock_handle = os_wrapper_semaphore_create(MAX_SEMAPHORE_COUNT,
                                                 MAX_SEMAPHORE_COUNT,
                                                 NULL);
    if (!ns_lock_handle) {
        return MAILBOX_GENERIC_ERROR;
    }

    return MAILBOX_SUCCESS;
}

int32_t tfm_ns_mailbox_os_lock_acquire(void)
{
    return os_wrapper_semaphore_acquire(ns_lock_handle,
                                        OS_WRAPPER_WAIT_FOREVER);
}

int32_t tfm_ns_mailbox_os_lock_release(void)
{
    return os_wrapper_semaphore_release(ns_lock_handle);
}