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