blob: 7d8d6d1106b7d44439a7d39ba509db74d336d164 [file] [log] [blame]
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +00001/*
2 * Copyright (c) 2017, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "test/suites/sst/non_secure/os_wrapper.h"
9
10#include <string.h>
11#include "cmsis.h"
12#include "cmsis_os2.h"
13
14/* This is an example OS abstraction layer rtx RTOS for non-secure test
15 * environment */
16
17uint32_t os_wrapper_new_thread(const char* name, uint32_t stack_size,
18 os_wrapper_thread_func func, uint32_t priority)
19{
20 osThreadAttr_t task_attribs = {.tz_module = 1};
21 osThreadId_t thread_id;
22
23 task_attribs.stack_size = stack_size;
24 task_attribs.name = name;
25 task_attribs.priority = priority;
26
27 thread_id = osThreadNew(func, NULL, &task_attribs);
28 if (thread_id == NULL) {
29 return OS_WRAPPER_ERROR;
30 }
31
32 return (uint32_t)thread_id;
33}
34
35
36uint32_t os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count,
37 const char* name)
38{
39 osSemaphoreAttr_t sema_attrib = {0};
40 osSemaphoreId_t semaphore;
41
42 sema_attrib.name = name;
43
44 semaphore = osSemaphoreNew(max_count, initial_count, &sema_attrib);
45 if (semaphore == NULL) {
46 return OS_WRAPPER_ERROR;
47 }
48
49 return (uint32_t)semaphore;
50}
51
52uint32_t os_wrapper_semaphore_acquire(uint32_t semaphore_id, uint32_t timeout)
53{
54 osStatus_t status;
55
56 status = osSemaphoreAcquire((osSemaphoreId_t)semaphore_id, timeout);
57 if (status != osOK) {
58 return OS_WRAPPER_ERROR;
59 }
60
61 return 0;
62}
63
64uint32_t os_wrapper_semaphore_release(uint32_t sema)
65{
66 osStatus_t status;
67
68 status = osSemaphoreRelease((osSemaphoreId_t)sema);
69 if (status != osOK) {
70 return OS_WRAPPER_ERROR;
71 }
72
73 return 0;
74}
75
76uint32_t os_wrapper_semaphore_delete(uint32_t sema)
77{
78 osStatus_t status;
79
80 status = osSemaphoreDelete((osSemaphoreId_t)sema);
81 if (status != osOK) {
82 return OS_WRAPPER_ERROR;
83 }
84
85 return 0;
86}
87
88uint32_t os_wrapper_get_thread_id(void)
89{
90 osThreadId_t thread_id;
91
92 thread_id = osThreadGetId();
93 if(thread_id == NULL) {
94 return OS_WRAPPER_ERROR;
95 }
96
97 return (uint32_t)thread_id;
98}
99
100uint32_t os_wrapper_get_thread_priority(uint32_t id)
101{
102 osPriority_t prio;
103
104 prio = osThreadGetPriority((osThreadId_t)id);
105 if (prio == osPriorityError) {
106 return OS_WRAPPER_ERROR;
107 }
108
109 return prio;
110}
111
112uint32_t os_wrapper_delete_thread(uint32_t id)
113{
114 /* Make sure the thread has ended at this point*/
115 (void)osThreadJoin((osThreadId_t) id);
116
117 /* RTX handles thread deletion automatically. So, any
118 * action is required in this function to delete the thread. */
119
120 return 0;
121}