Skip to content

Commit 96e19af

Browse files
authored
Merge pull request #14396 from LDong-Arm/tfm_os_wrapper
TF-M: Switch to vanilla TF-M's OS wrapper
2 parents 7ef27d9 + a6081e5 commit 96e19af

File tree

13 files changed

+518
-27
lines changed

13 files changed

+518
-27
lines changed

drivers/usb/include/usb/USBCDC_ECM.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#include "USBDescriptor.h"
2323
#include "USBDevice.h"
2424
#include "ByteBuffer.h"
25-
#include "Mutex.h"
25+
#include "rtos/Mutex.h"
2626
#include "EventFlags.h"
2727
#include "events/EventQueue.h"
28-
#include "Thread.h"
28+
#include "rtos/Thread.h"
2929
#include "Callback.h"
3030

3131
#define MAX_PACKET_SIZE_INT (64)

drivers/usb/include/usb/USBMIDI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "USBDevice.h"
2626
#include "MIDIMessage.h"
2727
#include "EventFlags.h"
28-
#include "Mutex.h"
28+
#include "rtos/Mutex.h"
2929
#include "Callback.h"
3030

3131
#define DEFAULT_CONFIGURATION (1)

drivers/usb/include/usb/USBMSD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "usb/internal/PolledQueue.h"
2626
#include "usb/internal/Task.h"
2727
#include "BlockDevice.h"
28-
#include "Mutex.h"
28+
#include "rtos/Mutex.h"
2929

3030
#include "USBDevice.h"
3131

drivers/usb/include/usb/internal/AsyncOp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#ifndef MBED_ASYNC_OP_H
1919
#define MBED_ASYNC_OP_H
2020

21-
#include "Mutex.h"
22-
#include "Semaphore.h"
21+
#include "rtos/Mutex.h"
22+
#include "rtos/Semaphore.h"
2323
#include "Callback.h"
2424

2525
#include "LinkEntry.h"

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ target_include_directories(mbed-psa
3232

3333
target_sources(mbed-psa
3434
INTERFACE
35+
src/os_wrapper_cmsis_rtos_v2.c
3536
src/tfm_crypto_ipc_api.c
3637
src/tfm_initial_attestation_ipc_api.c
3738
src/tfm_its_ipc_api.c

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/TARGET_TFM_V8M/src/tfm_ns_interface.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,32 @@
77
#include <stdint.h>
88
#include <stdbool.h>
99

10+
#include "os_wrapper/mutex.h"
11+
1012
#include "tfm_api.h"
1113
#include "tfm_ns_interface.h"
12-
#include "cmsis_os2.h"
1314

1415
/**
1516
* \brief the ns_lock ID
1617
*/
17-
static osMutexId_t ns_lock_handle = NULL;
18+
static void *ns_lock_handle = NULL;
1819

1920
__attribute__((weak))
2021
int32_t tfm_ns_interface_dispatch(veneer_fn fn,
2122
uint32_t arg0, uint32_t arg1,
2223
uint32_t arg2, uint32_t arg3)
2324
{
2425
int32_t result;
25-
osStatus_t status;
2626

2727
/* TFM request protected by NS lock */
28-
status = osMutexAcquire(ns_lock_handle, osWaitForever);
29-
if (status != osOK) {
28+
if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
29+
!= OS_WRAPPER_SUCCESS) {
3030
return (int32_t)TFM_ERROR_GENERIC;
3131
}
3232

3333
result = fn(arg0, arg1, arg2, arg3);
3434

35-
status = osMutexRelease(ns_lock_handle);
36-
if (status != osOK) {
35+
if (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) {
3736
return (int32_t)TFM_ERROR_GENERIC;
3837
}
3938

@@ -43,22 +42,13 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn,
4342
__attribute__((weak))
4443
enum tfm_status_e tfm_ns_interface_init(void)
4544
{
46-
const osMutexAttr_t attr = {
47-
.name = NULL,
48-
.attr_bits = osMutexPrioInherit, /* Priority inheritance is recommended
49-
* to enable if it is supported.
50-
* For recursive mutex and the ability
51-
* of auto release when owner being
52-
* terminated is not required.
53-
*/
54-
.cb_mem = NULL,
55-
.cb_size = 0U
56-
};
45+
void *handle;
5746

58-
ns_lock_handle = osMutexNew(&attr);
59-
if (!ns_lock_handle) {
47+
handle = os_wrapper_mutex_create();
48+
if (!handle) {
6049
return TFM_ERROR_GENERIC;
6150
}
6251

52+
ns_lock_handle = handle;
6353
return TFM_SUCCESS;
6454
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
706a1e6db255
1+
8635d8a23341
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2017-2019, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#ifndef __OS_WRAPPER_COMMON_H__
9+
#define __OS_WRAPPER_COMMON_H__
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#include <stdint.h>
16+
17+
#define OS_WRAPPER_SUCCESS (0x0)
18+
#define OS_WRAPPER_ERROR (0xFFFFFFFFU)
19+
#define OS_WRAPPER_WAIT_FOREVER (0xFFFFFFFFU)
20+
#define OS_WRAPPER_DEFAULT_STACK_SIZE (-1)
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#endif /* __OS_WRAPPER_COMMON_H__ */
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2017-2019, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#ifndef __OS_WRAPPER_MUTEX_H__
9+
#define __OS_WRAPPER_MUTEX_H__
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#include "common.h"
16+
17+
/**
18+
* \brief Creates a mutex for mutual exclusion of resources
19+
*
20+
* \return The handle of the created mutex on success or NULL on error
21+
*/
22+
void *os_wrapper_mutex_create(void);
23+
24+
/**
25+
* \brief Acquires a mutex that is created by \ref os_wrapper_mutex_create()
26+
*
27+
* \param[in] handle The handle of the mutex to acquire. Should be one of the
28+
* handles returned by \ref os_wrapper_mutex_create()
29+
* \param[in] timeout The maximum amount of time(in tick periods) for the
30+
* thread to wait for the mutex to be available.
31+
* If timeout is zero, the function will return immediately.
32+
* Setting timeout to \ref OS_WRAPPER_WAIT_FOREVER will
33+
* cause the thread to wait indefinitely
34+
*
35+
* \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
36+
*/
37+
uint32_t os_wrapper_mutex_acquire(void *handle, uint32_t timeout);
38+
39+
/**
40+
* \brief Releases the mutex acquired previously
41+
*
42+
43+
* \param[in] handle The handle of the mutex that has been acquired
44+
*
45+
* \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
46+
*/
47+
uint32_t os_wrapper_mutex_release(void *handle);
48+
49+
/**
50+
* \brief Deletes a mutex that is created by \ref os_wrapper_mutex_create()
51+
*
52+
* \param[in] handle The handle of the mutex to be deleted
53+
*
54+
* \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
55+
*/
56+
uint32_t os_wrapper_mutex_delete(void *handle);
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif
61+
62+
#endif /* __OS_WRAPPER_MUTEX_H__ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2017-2020, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#ifndef __OS_WRAPPER_SEMAPHORE_H__
9+
#define __OS_WRAPPER_SEMAPHORE_H__
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#include "common.h"
16+
17+
/**
18+
* \brief Creates a new semaphore
19+
*
20+
* \param[in] max_count Highest count of the semaphore
21+
* \param[in] initial_count Starting count of the available semaphore
22+
* \param[in] name Name of the semaphore
23+
*
24+
* \return Returns handle of the semaphore created, or NULL in case of error
25+
*/
26+
void *os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count,
27+
const char *name);
28+
29+
/**
30+
* \brief Acquires the semaphore
31+
*
32+
* \param[in] hanlde Semaphore handle
33+
* \param[in] timeout Timeout value
34+
*
35+
* \return \ref OS_WRAPPER_SUCCESS in case of successful acquision, or
36+
* \ref OS_WRAPPER_ERROR in case of error
37+
*/
38+
uint32_t os_wrapper_semaphore_acquire(void *handle, uint32_t timeout);
39+
40+
/**
41+
* \brief Releases the semaphore
42+
*
43+
* \param[in] hanlde Semaphore handle
44+
*
45+
* \return \ref OS_WRAPPER_SUCCESS in case of successful release, or
46+
* \ref OS_WRAPPER_ERROR in case of error
47+
*/
48+
uint32_t os_wrapper_semaphore_release(void *handle);
49+
50+
/**
51+
* \brief Deletes the semaphore
52+
*
53+
* \param[in] handle Semaphore handle
54+
*
55+
* \return \ref OS_WRAPPER_SUCCESS in case of successful release, or
56+
* \ref OS_WRAPPER_ERROR in case of error
57+
*/
58+
uint32_t os_wrapper_semaphore_delete(void *handle);
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif
63+
64+
#endif /* __OS_WRAPPER_SEMAPHORE_H__ */
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2017-2020, Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#ifndef __OS_WRAPPER_THREAD_H__
9+
#define __OS_WRAPPER_THREAD_H__
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#include "common.h"
16+
17+
/* prototype for the thread entry function */
18+
typedef void (*os_wrapper_thread_func) (void *argument);
19+
20+
/**
21+
* \brief Creates a new thread
22+
*
23+
* \param[in] name Name of the thread
24+
* \param[in] stack_size Size of stack to be allocated for this thread. It can
25+
* be \ref OS_WRAPPER_DEFAULT_STACK_SIZE to use the
26+
* default value provided by the underlying RTOS
27+
* \param[in] func Pointer to the function invoked by thread
28+
* \param[in] arg Argument to pass to the function invoked by thread
29+
* \param[in] priority Initial thread priority
30+
*
31+
* \return Returns the thread handle created, or NULL in case of error
32+
*/
33+
void *os_wrapper_thread_new(const char *name, int32_t stack_size,
34+
os_wrapper_thread_func func, void *arg,
35+
uint32_t priority);
36+
/**
37+
* \brief Gets current thread handle
38+
*
39+
* \return Returns the thread handle, or NULL in case of error
40+
*/
41+
void *os_wrapper_thread_get_handle(void);
42+
43+
/**
44+
* \brief Gets thread priority
45+
*
46+
* \param[in] handle Thread handle
47+
* \param[out] priority The priority of the thread
48+
*
49+
* \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
50+
* in case of error
51+
*/
52+
uint32_t os_wrapper_thread_get_priority(void *handle, uint32_t *priority);
53+
54+
/**
55+
* \brief Exits the calling thread
56+
*/
57+
void os_wrapper_thread_exit(void);
58+
59+
/**
60+
* \brief Set the event flags for synchronizing a thread specified by handle.
61+
*
62+
* \note This function may not be allowed to be called from Interrupt Service
63+
* Routines.
64+
*
65+
* \param[in] handle Thread handle to be notified
66+
* \param[in] flags Event flags value
67+
*
68+
* \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
69+
* in case of error
70+
*/
71+
uint32_t os_wrapper_thread_set_flag(void *handle, uint32_t flags);
72+
73+
/**
74+
* \brief Set the event flags in an interrupt handler for synchronizing a thread
75+
* specified by handle.
76+
*
77+
* \param[in] handle Thread handle to be notified
78+
* \param[in] flags Event flags value
79+
*
80+
* \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
81+
* in case of error
82+
*/
83+
uint32_t os_wrapper_thread_set_flag_isr(void *handle, uint32_t flags);
84+
85+
/**
86+
* \brief Wait for the event flags for synchronizing threads.
87+
*
88+
* \note This function may not be allowed to be called from Interrupt Service
89+
* Routines.
90+
*
91+
* \param[in] flags Specify the flags to wait for
92+
* \param[in] timeout Timeout value
93+
*
94+
* \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
95+
* in case of error
96+
*/
97+
uint32_t os_wrapper_thread_wait_flag(uint32_t flags, uint32_t timeout);
98+
99+
#ifdef __cplusplus
100+
}
101+
#endif
102+
103+
#endif /* __OS_WRAPPER_THREAD_H__ */

0 commit comments

Comments
 (0)