blob: 90d2cd51d6c1665a939933543a600ccd58a93e76 [file] [log] [blame]
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +00001/*
Gyorgy Szing40a7af02019-02-06 14:19:47 +01002 * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __OS_WRAPPER_H__
9#define __OS_WRAPPER_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stdint.h>
16
Kevin Peng95350f42019-07-22 15:27:02 +080017#define OS_WRAPPER_SUCCESS (0x0)
Antonio de Angelisdf5817d2019-06-20 16:07:26 +010018#define OS_WRAPPER_ERROR (0xFFFFFFFFU)
19#define OS_WRAPPER_WAIT_FOREVER (0xFFFFFFFFU)
20#define OS_WRAPPER_DEFAULT_STACK_SIZE (-1)
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000021
22/* prototype for the thread entry function */
23typedef void (*os_wrapper_thread_func) (void *argument);
24
25/**
26 * \brief Creates a new semaphore
27 *
28 * \param[in] max_count Highest count of the semaphore
29 * \param[in] initial_count Starting count of the semaphore
30 * \param[in] name Name of the semaphore
31 *
Kevin Peng95350f42019-07-22 15:27:02 +080032 * \return Returns ID of the semaphore created, or \ref OS_WRAPPER_ERROR in case
33 * of error
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000034 */
35uint32_t os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count,
36 const char *name);
37
38/**
39 * \brief Acquires the semaphore
40 *
41 * \param[in] semaphore_id Semaphore ID
42 * \param[in] timeout Timeout value
43 *
Kevin Peng95350f42019-07-22 15:27:02 +080044 * \return \ref OS_WRAPPER_SUCCESS in case of successful acquision, or
45 * \ref OS_WRAPPER_ERROR in case of error
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000046 */
47uint32_t os_wrapper_semaphore_acquire(uint32_t semaphore_id, uint32_t timeout);
48
49/**
50 * \brief Releases the semaphore
51 *
52 * \param[in] semaphore_id Semaphore ID
53 *
Kevin Peng95350f42019-07-22 15:27:02 +080054 * \return \ref OS_WRAPPER_SUCCESS in case of successful release, or
55 * \ref OS_WRAPPER_ERROR in case of error
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000056 */
57uint32_t os_wrapper_semaphore_release(uint32_t semaphore_id);
58
59/**
60 * \brief Deletes the semaphore
61 *
62 * \param[in] semaphore_id Semaphore ID
63 *
Kevin Peng95350f42019-07-22 15:27:02 +080064 * \return \ref OS_WRAPPER_SUCCESS in case of successful release, or
65 * \ref OS_WRAPPER_ERROR in case of error
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000066 */
Gyorgy Szing40a7af02019-02-06 14:19:47 +010067uint32_t os_wrapper_semaphore_delete(uint32_t semaphore_id);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000068
69/**
Kevin Peng95350f42019-07-22 15:27:02 +080070 * \brief Creates a mutex for mutual exclusion of resources
71 *
72 * \return The ID of the created mutex on success or \ref OS_WRAPPER_ERROR on
73 * error
74 */
75uint32_t os_wrapper_mutex_create(void);
76
77/**
78 * \brief Acquires a mutex that is created by \ref os_wrapper_mutex_create()
79 *
80 * \param[in] mutex_id The ID of the mutex to acquire. Should be one of the IDs
81 * returned by \ref os_wrapper_mutex_create()
82 * \param[in] timeout The maximum amount of time(in tick periods) for the
83 * thread to wait for the mutex to be available.
84 * If timeout is zero, the function will return immediately.
85 * Setting timeout to \ref OS_WRAPPER_WAIT_FOREVER will
86 * cause the thread to wait indefinitely
87 *
88 * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
89 */
90uint32_t os_wrapper_mutex_acquire(uint32_t mutex_id, uint32_t timeout);
91
92/**
93 * \brief Releases the mutex acquired previously
94 *
95 * \param[in] mutex_id The ID of the mutex that has been acquired
96 *
97 * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
98 */
99uint32_t os_wrapper_mutex_release(uint32_t mutex_id);
100
101/**
102 * \brief Deletes a mutex that is created by \ref os_wrapper_mutex_create()
103 *
104 * \param[in] mutex_id The ID of the mutex to be deleted
105 *
106 * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
107 */
108uint32_t os_wrapper_mutex_delete(uint32_t mutex_id);
109
110/**
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000111 * \brief Creates a new thread
112 *
113 * \param[in] name Name of the thread
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100114 * \param[in] stack_size Size of stack to be allocated for this thread. It can
Kevin Peng95350f42019-07-22 15:27:02 +0800115 * be \ref OS_WRAPPER_DEFAULT_STACK_SIZE to use the
116 * default value provided by the underlying RTOS
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000117 * \param[in] func Pointer to the function invoked by thread
Jamie Fox96dfe7b2018-02-05 14:27:51 +0000118 * \param[in] arg Argument to pass to the function invoked by thread
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000119 * \param[in] priority Initial thread priority
120 *
Kevin Peng95350f42019-07-22 15:27:02 +0800121 * \return Returns thread ID, or \ref OS_WRAPPER_ERROR in case of error
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000122 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100123uint32_t os_wrapper_thread_new(const char *name, int32_t stack_size,
Jamie Fox96dfe7b2018-02-05 14:27:51 +0000124 os_wrapper_thread_func func, void *arg,
125 uint32_t priority);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000126/**
127 * \brief Gets current thread ID
128 *
Kevin Peng95350f42019-07-22 15:27:02 +0800129 * \return Returns thread ID, or \ref OS_WRAPPER_ERROR in case of error
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000130 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100131uint32_t os_wrapper_thread_get_id(void);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000132
133/**
134 * \brief Gets thread priority
135 *
Kevin Peng95350f42019-07-22 15:27:02 +0800136 * \param[in] id Thread ID
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000137 *
Kevin Peng95350f42019-07-22 15:27:02 +0800138 * \return Returns thread priority value, or \ref OS_WRAPPER_ERROR in case of
139 * error
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000140 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100141uint32_t os_wrapper_thread_get_priority(uint32_t id);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000142
143/**
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100144 * \brief Exits the calling thread
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000145 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100146void os_wrapper_thread_exit(void);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000147
148#ifdef __cplusplus
149}
150#endif
151
152#endif /* __OS_WRAPPER_H__ */