blob: a493593a612fa1d0c19c707babd64795393d5f8f [file] [log] [blame]
Kevin Peng477fa942019-07-29 10:55:17 +08001/*
David Hu56297f32019-09-30 13:41:15 +08002 * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
Kevin Peng477fa942019-07-29 10:55:17 +08003 *
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 *
Kevin Peng383e8402019-08-05 16:35:44 +080031 * \return Returns the thread handle created, or NULL in case of error
Kevin Peng477fa942019-07-29 10:55:17 +080032 */
Kevin Peng383e8402019-08-05 16:35:44 +080033void *os_wrapper_thread_new(const char *name, int32_t stack_size,
34 os_wrapper_thread_func func, void *arg,
35 uint32_t priority);
Kevin Peng477fa942019-07-29 10:55:17 +080036/**
Kevin Peng383e8402019-08-05 16:35:44 +080037 * \brief Gets current thread handle
Kevin Peng477fa942019-07-29 10:55:17 +080038 *
Kevin Peng383e8402019-08-05 16:35:44 +080039 * \return Returns the thread handle, or NULL in case of error
Kevin Peng477fa942019-07-29 10:55:17 +080040 */
Kevin Peng383e8402019-08-05 16:35:44 +080041void *os_wrapper_thread_get_handle(void);
Kevin Peng477fa942019-07-29 10:55:17 +080042
43/**
44 * \brief Gets thread priority
45 *
Kevin Peng383e8402019-08-05 16:35:44 +080046 * \param[in] handle Thread handle
47 * \param[out] priority The priority of the thread
Kevin Peng477fa942019-07-29 10:55:17 +080048 *
Kevin Peng383e8402019-08-05 16:35:44 +080049 * \return Returns \ref OS_WRAPPER_SUCCESS on success, or \ref OS_WRAPPER_ERROR
50 * in case of error
Kevin Peng477fa942019-07-29 10:55:17 +080051 */
Kevin Peng383e8402019-08-05 16:35:44 +080052uint32_t os_wrapper_thread_get_priority(void *handle, uint32_t *priority);
Kevin Peng477fa942019-07-29 10:55:17 +080053
54/**
55 * \brief Exits the calling thread
56 */
57void os_wrapper_thread_exit(void);
58
David Hu56297f32019-09-30 13:41:15 +080059/**
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
Kevin Peng477fa942019-07-29 10:55:17 +080099#ifdef __cplusplus
100}
101#endif
102
103#endif /* __OS_WRAPPER_THREAD_H__ */