Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 1 | /* |
Gyorgy Szing | 40a7af0 | 2019-02-06 14:19:47 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, 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 | |
Kevin Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 17 | #define OS_WRAPPER_SUCCESS (0x0) |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 18 | #define OS_WRAPPER_ERROR (0xFFFFFFFFU) |
| 19 | #define OS_WRAPPER_WAIT_FOREVER (0xFFFFFFFFU) |
| 20 | #define OS_WRAPPER_DEFAULT_STACK_SIZE (-1) |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 21 | |
| 22 | /* prototype for the thread entry function */ |
| 23 | typedef 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 Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 32 | * \return Returns ID of the semaphore created, or \ref OS_WRAPPER_ERROR in case |
| 33 | * of error |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 34 | */ |
| 35 | uint32_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 Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 44 | * \return \ref OS_WRAPPER_SUCCESS in case of successful acquision, or |
| 45 | * \ref OS_WRAPPER_ERROR in case of error |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 46 | */ |
| 47 | uint32_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 Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 54 | * \return \ref OS_WRAPPER_SUCCESS in case of successful release, or |
| 55 | * \ref OS_WRAPPER_ERROR in case of error |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 56 | */ |
| 57 | uint32_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 Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 64 | * \return \ref OS_WRAPPER_SUCCESS in case of successful release, or |
| 65 | * \ref OS_WRAPPER_ERROR in case of error |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 66 | */ |
Gyorgy Szing | 40a7af0 | 2019-02-06 14:19:47 +0100 | [diff] [blame] | 67 | uint32_t os_wrapper_semaphore_delete(uint32_t semaphore_id); |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 68 | |
| 69 | /** |
Kevin Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 70 | * \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 | */ |
| 75 | uint32_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 | */ |
| 90 | uint32_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 | */ |
| 99 | uint32_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 | */ |
| 108 | uint32_t os_wrapper_mutex_delete(uint32_t mutex_id); |
| 109 | |
| 110 | /** |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 111 | * \brief Creates a new thread |
| 112 | * |
| 113 | * \param[in] name Name of the thread |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 114 | * \param[in] stack_size Size of stack to be allocated for this thread. It can |
Kevin Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 115 | * be \ref OS_WRAPPER_DEFAULT_STACK_SIZE to use the |
| 116 | * default value provided by the underlying RTOS |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 117 | * \param[in] func Pointer to the function invoked by thread |
Jamie Fox | 96dfe7b | 2018-02-05 14:27:51 +0000 | [diff] [blame] | 118 | * \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] | 119 | * \param[in] priority Initial thread priority |
| 120 | * |
Kevin Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 121 | * \return Returns thread ID, or \ref OS_WRAPPER_ERROR in case of error |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 122 | */ |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 123 | uint32_t os_wrapper_thread_new(const char *name, int32_t stack_size, |
Jamie Fox | 96dfe7b | 2018-02-05 14:27:51 +0000 | [diff] [blame] | 124 | os_wrapper_thread_func func, void *arg, |
| 125 | uint32_t priority); |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 126 | /** |
| 127 | * \brief Gets current thread ID |
| 128 | * |
Kevin Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 129 | * \return Returns thread ID, or \ref OS_WRAPPER_ERROR in case of error |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 130 | */ |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 131 | uint32_t os_wrapper_thread_get_id(void); |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * \brief Gets thread priority |
| 135 | * |
Kevin Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 136 | * \param[in] id Thread ID |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 137 | * |
Kevin Peng | 95350f4 | 2019-07-22 15:27:02 +0800 | [diff] [blame] | 138 | * \return Returns thread priority value, or \ref OS_WRAPPER_ERROR in case of |
| 139 | * error |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 140 | */ |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 141 | uint32_t os_wrapper_thread_get_priority(uint32_t id); |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 142 | |
| 143 | /** |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 144 | * \brief Exits the calling thread |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 145 | */ |
Antonio de Angelis | df5817d | 2019-06-20 16:07:26 +0100 | [diff] [blame] | 146 | void os_wrapper_thread_exit(void); |
Marc Moreno Berengue | ffd3c46 | 2017-11-29 16:09:52 +0000 | [diff] [blame] | 147 | |
| 148 | #ifdef __cplusplus |
| 149 | } |
| 150 | #endif |
| 151 | |
| 152 | #endif /* __OS_WRAPPER_H__ */ |