blob: a493593a612fa1d0c19c707babd64795393d5f8f [file] [log] [blame]
David Hucdc51fb2021-04-06 18:10:46 +08001/*
2 * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __OS_WRAPPER_THREAD_H__
9#define __OS_WRAPPER_THREAD_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include "common.h"
16
17/* prototype for the thread entry function */
18typedef void (*os_wrapper_thread_func) (void *argument);
19
20/**
21 * \brief Creates a new thread
22 *
23 * \param[in] name Name of the thread
24 * \param[in] stack_size Size of stack to be allocated for this thread. It can
25 * be \ref OS_WRAPPER_DEFAULT_STACK_SIZE to use the
26 * default value provided by the underlying RTOS
27 * \param[in] func Pointer to the function invoked by thread
28 * \param[in] arg Argument to pass to the function invoked by thread
29 * \param[in] priority Initial thread priority
30 *
31 * \return Returns the thread handle created, or NULL in case of error
32 */
33void *os_wrapper_thread_new(const char *name, int32_t stack_size,
34 os_wrapper_thread_func func, void *arg,
35 uint32_t priority);
36/**
37 * \brief Gets current thread handle
38 *
39 * \return Returns the thread handle, or NULL in case of error
40 */
41void *os_wrapper_thread_get_handle(void);
42
43/**
44 * \brief Gets thread priority
45 *
46 * \param[in] handle Thread handle
47 * \param[out] priority The priority of the thread
48 *
49 * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
50 * in case of error
51 */
52uint32_t os_wrapper_thread_get_priority(void *handle, uint32_t *priority);
53
54/**
55 * \brief Exits the calling thread
56 */
57void os_wrapper_thread_exit(void);
58
59/**
60 * \brief Set the event flags for synchronizing a thread specified by handle.
61 *
62 * \note This function may not be allowed to be called from Interrupt Service
63 * Routines.
64 *
65 * \param[in] handle Thread handle to be notified
66 * \param[in] flags Event flags value
67 *
68 * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
69 * in case of error
70 */
71uint32_t os_wrapper_thread_set_flag(void *handle, uint32_t flags);
72
73/**
74 * \brief Set the event flags in an interrupt handler for synchronizing a thread
75 * specified by handle.
76 *
77 * \param[in] handle Thread handle to be notified
78 * \param[in] flags Event flags value
79 *
80 * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
81 * in case of error
82 */
83uint32_t os_wrapper_thread_set_flag_isr(void *handle, uint32_t flags);
84
85/**
86 * \brief Wait for the event flags for synchronizing threads.
87 *
88 * \note This function may not be allowed to be called from Interrupt Service
89 * Routines.
90 *
91 * \param[in] flags Specify the flags to wait for
92 * \param[in] timeout Timeout value
93 *
94 * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
95 * in case of error
96 */
97uint32_t os_wrapper_thread_wait_flag(uint32_t flags, uint32_t timeout);
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif /* __OS_WRAPPER_THREAD_H__ */