Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 1 | /* |
Jamie Fox | 440cd89 | 2018-02-26 15:43:23 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __OS_WRAPPER_H__ |
| 9 | #define __OS_WRAPPER_H__ |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | #include <stdint.h> |
| 16 | |
| 17 | #define OS_WRAPPER_ERROR 0xFFFFFFFF |
| 18 | |
| 19 | /* prototype for the thread entry function */ |
| 20 | typedef void (*os_wrapper_thread_func) (void *argument); |
| 21 | |
| 22 | /** |
| 23 | * \brief Creates a new semaphore |
| 24 | * |
| 25 | * \param[in] max_count Highest count of the semaphore |
| 26 | * \param[in] initial_count Starting count of the semaphore |
| 27 | * \param[in] name Name of the semaphore |
| 28 | * |
| 29 | * \return Returns ID of the semaphore created, or OS_WRAPPER_ERROR in case of |
| 30 | * error |
| 31 | */ |
| 32 | uint32_t os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count, |
| 33 | const char *name); |
| 34 | |
| 35 | /** |
| 36 | * \brief Acquires the semaphore |
| 37 | * |
| 38 | * \param[in] semaphore_id Semaphore ID |
| 39 | * \param[in] timeout Timeout value |
| 40 | * |
| 41 | * \return 0 in case of successful acquision, or OS_WRAPPER_ERROR in case of |
| 42 | * error |
| 43 | */ |
| 44 | uint32_t os_wrapper_semaphore_acquire(uint32_t semaphore_id, uint32_t timeout); |
| 45 | |
| 46 | /** |
| 47 | * \brief Releases the semaphore |
| 48 | * |
| 49 | * \param[in] semaphore_id Semaphore ID |
| 50 | * |
| 51 | * \return 0 in case of successful release, or OS_WRAPPER_ERROR in case of error |
| 52 | */ |
| 53 | uint32_t os_wrapper_semaphore_release(uint32_t semaphore_id); |
| 54 | |
| 55 | /** |
| 56 | * \brief Deletes the semaphore |
| 57 | * |
| 58 | * \param[in] semaphore_id Semaphore ID |
| 59 | * |
| 60 | * \return 0 in case of successful release, or OS_WRAPPER_ERROR in case of error |
| 61 | */ |
| 62 | uint32_t os_wrapper_semaphore_delete(uint32_t sema); |
| 63 | |
| 64 | /** |
| 65 | * \brief Creates a new thread |
| 66 | * |
| 67 | * \param[in] name Name of the thread |
| 68 | * \param[in] stack_size Size of stack to be allocated for this thread |
| 69 | * \param[in] func Pointer to the function invoked by thread |
Jamie Fox | 96dfe7b | 2018-02-05 14:27:51 +0000 | [diff] [blame^] | 70 | * \param[in] arg Argument to pass to the function invoked by thread |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 71 | * \param[in] priority Initial thread priority |
| 72 | * |
| 73 | * \return Returns thread ID, or OS_WRAPPER_ERROR in case of error |
| 74 | */ |
| 75 | uint32_t os_wrapper_new_thread(const char *name, uint32_t stack_size, |
Jamie Fox | 96dfe7b | 2018-02-05 14:27:51 +0000 | [diff] [blame^] | 76 | os_wrapper_thread_func func, void *arg, |
| 77 | uint32_t priority); |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 78 | /** |
| 79 | * \brief Gets current thread ID |
| 80 | * |
| 81 | * \return Returns thread ID, or OS_WRAPPER_ERROR in case of error |
| 82 | */ |
| 83 | uint32_t os_wrapper_get_thread_id(void); |
| 84 | |
| 85 | /** |
| 86 | * \brief Gets thread priority |
| 87 | * |
| 88 | * \param[in] id Thread ID |
| 89 | * |
| 90 | * \return Returns thread priority value, or OS_WRAPPER_ERROR in case of error |
| 91 | */ |
| 92 | uint32_t os_wrapper_get_thread_priority(uint32_t id); |
| 93 | |
| 94 | /** |
Jamie Fox | 440cd89 | 2018-02-26 15:43:23 +0000 | [diff] [blame] | 95 | * \brief Waits for the thread to terminate |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 96 | * |
| 97 | * \param[in] id Thread ID |
| 98 | * |
Jamie Fox | 440cd89 | 2018-02-26 15:43:23 +0000 | [diff] [blame] | 99 | * \return 0 in case of successful join or OS_WRAPPER_ERROR in case of error. |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 100 | */ |
Jamie Fox | 440cd89 | 2018-02-26 15:43:23 +0000 | [diff] [blame] | 101 | uint32_t os_wrapper_join_thread(uint32_t id); |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 102 | |
| 103 | #ifdef __cplusplus |
| 104 | } |
| 105 | #endif |
| 106 | |
| 107 | #endif /* __OS_WRAPPER_H__ */ |