blob: eab121e2d8fd4586485b541f74169f7323aaa4fd [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
Antonio de Angelisdf5817d2019-06-20 16:07:26 +010017#define OS_WRAPPER_ERROR (0xFFFFFFFFU)
18#define OS_WRAPPER_WAIT_FOREVER (0xFFFFFFFFU)
19#define OS_WRAPPER_DEFAULT_STACK_SIZE (-1)
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000020
21/* prototype for the thread entry function */
22typedef void (*os_wrapper_thread_func) (void *argument);
23
24/**
25 * \brief Creates a new semaphore
26 *
27 * \param[in] max_count Highest count of the semaphore
28 * \param[in] initial_count Starting count of the semaphore
29 * \param[in] name Name of the semaphore
30 *
31 * \return Returns ID of the semaphore created, or OS_WRAPPER_ERROR in case of
32 * error
33 */
34uint32_t os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count,
35 const char *name);
36
37/**
38 * \brief Acquires the semaphore
39 *
40 * \param[in] semaphore_id Semaphore ID
41 * \param[in] timeout Timeout value
42 *
43 * \return 0 in case of successful acquision, or OS_WRAPPER_ERROR in case of
44 * error
45 */
46uint32_t os_wrapper_semaphore_acquire(uint32_t semaphore_id, uint32_t timeout);
47
48/**
49 * \brief Releases the semaphore
50 *
51 * \param[in] semaphore_id Semaphore ID
52 *
53 * \return 0 in case of successful release, or OS_WRAPPER_ERROR in case of error
54 */
55uint32_t os_wrapper_semaphore_release(uint32_t semaphore_id);
56
57/**
58 * \brief Deletes the semaphore
59 *
60 * \param[in] semaphore_id Semaphore ID
61 *
62 * \return 0 in case of successful release, or OS_WRAPPER_ERROR in case of error
63 */
Gyorgy Szing40a7af02019-02-06 14:19:47 +010064uint32_t os_wrapper_semaphore_delete(uint32_t semaphore_id);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000065
66/**
67 * \brief Creates a new thread
68 *
69 * \param[in] name Name of the thread
Antonio de Angelisdf5817d2019-06-20 16:07:26 +010070 * \param[in] stack_size Size of stack to be allocated for this thread. It can
71 * be OS_WRAPPER_DEFAULT_STACK_SIZE to use the default
72 * value provided by the underlying RTOS
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000073 * \param[in] func Pointer to the function invoked by thread
Jamie Fox96dfe7b2018-02-05 14:27:51 +000074 * \param[in] arg Argument to pass to the function invoked by thread
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000075 * \param[in] priority Initial thread priority
76 *
77 * \return Returns thread ID, or OS_WRAPPER_ERROR in case of error
78 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +010079uint32_t os_wrapper_thread_new(const char *name, int32_t stack_size,
Jamie Fox96dfe7b2018-02-05 14:27:51 +000080 os_wrapper_thread_func func, void *arg,
81 uint32_t priority);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000082/**
83 * \brief Gets current thread ID
84 *
85 * \return Returns thread ID, or OS_WRAPPER_ERROR in case of error
86 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +010087uint32_t os_wrapper_thread_get_id(void);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000088
89/**
90 * \brief Gets thread priority
91 *
92 * \param[in] id Thread ID
93 *
94 * \return Returns thread priority value, or OS_WRAPPER_ERROR in case of error
95 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +010096uint32_t os_wrapper_thread_get_priority(uint32_t id);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +000097
98/**
Antonio de Angelisdf5817d2019-06-20 16:07:26 +010099 * \brief Exits the calling thread
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000100 *
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100101 * \return void
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000102 */
Antonio de Angelisdf5817d2019-06-20 16:07:26 +0100103void os_wrapper_thread_exit(void);
Marc Moreno Berengueffd3c462017-11-29 16:09:52 +0000104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* __OS_WRAPPER_H__ */