AM243x MCU+ SDK  09.00.00
cb_lld_thread.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Texas Instruments Incorporated
3  * Copyright (c) 2023 Excelfore Corporation (https://excelfore.com)
4  *
5  * All rights reserved not granted herein.
6  * Limited License.
7  *
8  * Texas Instruments Incorporated grants a world-wide, royalty-free,
9  * non-exclusive license under copyrights and patents it now or hereafter
10  * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
11  * this software subject to the terms herein. With respect to the foregoing patent
12  * license, such license is granted solely to the extent that any such patent is necessary
13  * to Utilize the software alone. The patent license shall not apply to any combinations which
14  * include this software, other than combinations with devices manufactured by or for TI ("TI Devices").
15  * No hardware patent is licensed hereunder.
16  *
17  * Redistributions must preserve existing copyright notices and reproduce this license (including the
18  * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
19  * in the documentation and/or other materials provided with the distribution
20  *
21  * Redistribution and use in binary form, without modification, are permitted provided that the following
22  * conditions are met:
23  *
24  * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
25  * software provided in binary form.
26  * * any redistribution and use are licensed by TI for use only with TI Devices.
27  * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
28  *
29  * If software source code is provided to you, modification and redistribution of the source code are permitted
30  * provided that the following conditions are met:
31  *
32  * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
33  * TI for use only with TI Devices.
34  * * any redistribution and use of any object code compiled from the source code and any resulting derivative
35  * works, are licensed by TI for use only with TI Devices.
36  *
37  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
38  * promote products derived from this software without specific prior written permission.
39  *
40  * DISCLAIMER.
41  *
42  * THIS SOFTWARE IS PROVIDED BY TI AND TI"S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
43  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44  * IN NO EVENT SHALL TI AND TI"S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
46  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49 */
57 #ifndef CB_LLD_THREAD_H
58 #define CB_LLD_THREAD_H
59 
60 #include <stdint.h>
61 #include <string.h>
62 #include <time.h>
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 typedef struct cb_lld_sem cb_lld_sem_t;
69 typedef struct cb_lld_mutex cb_lld_mutex_t;
70 typedef struct cb_lld_task cb_lld_task_t;
71 
72 #define CB_THREAD_T cb_lld_task_t*
73 #define CB_THREAD_CREATE cb_lld_task_create
74 #define CB_THREAD_JOIN cb_lld_task_join
75 #define CB_THREAD_EXIT cb_lld_task_exit
76 
77 #define CB_THREAD_MUTEX_T cb_lld_mutex_t*
78 #define CB_THREAD_MUTEX_LOCK cb_lld_mutex_lock
79 #define CB_THREAD_MUTEX_TRYLOCK cb_lld_mutex_trylock
80 #define CB_THREAD_MUTEX_TIMEDLOCK cb_lld_mutex_timedlock
81 #define CB_THREAD_MUTEX_UNLOCK cb_lld_mutex_unlock
82 #define CB_THREAD_MUTEX_INIT cb_lld_mutex_init
83 #define CB_THREAD_MUTEX_DESTROY cb_lld_mutex_destroy
84 #define CB_STATIC_MUTEX_INITIALIZER(x) x=NULL
85 #define CB_STATIC_MUTEX_CONSTRUCTOR(x) ub_protected_func(cb_lld_global_mutex_init,&(x))
86 
87 /* does not need to support these macros */
88 #define CB_THREAD_MUTEXATTR_T void*
89 #define CB_THREAD_MUTEXATTR_INIT(a)
90 #define CB_THREAD_MUTEXATTR_SETPSHARED(a,b)
91 #define CB_THREAD_PROCESS_SHARED 0 //PTHREAD_PROCESS_SHARED
92 
93 #define CB_SEM_T cb_lld_sem_t*
94 #define CB_SEM_INIT cb_lld_sem_init
95 #define CB_SEM_WAIT cb_lld_sem_wait
96 #define CB_SEM_TRYWAIT cb_lld_sem_trywait
97 #define CB_SEM_TIMEDWAIT cb_lld_sem_timedwait
98 #define CB_SEM_POST cb_lld_sem_post
99 #define CB_SEM_DESTROY cb_lld_sem_destroy
100 
101 /* does not support condition variable */
102 #define CB_THREAD_COND_T void*
103 #define CB_THREAD_COND_INIT(a, b)
104 #define CB_THREAD_COND_DESTROY(a)
105 #define CB_THREAD_COND_WAIT(a, b)
106 #define CB_THREAD_COND_SIGNAL(a)
107 #define CB_THREAD_COND_BROADCAST(a)
108 
109 /* Implement the same prototype as POSIX APIs */
118 int cb_lld_sem_init(CB_SEM_T *sem, int pshared, unsigned int value);
119 
127 
139 
148 int cb_lld_sem_timedwait(CB_SEM_T *sem, struct timespec *abstime);
149 
157 
165 
175 
184 
192 
200 
208 
223 int cb_lld_mutex_timedlock(CB_THREAD_MUTEX_T *mutex, struct timespec *abstime);
224 
231 int cb_lld_global_mutex_init(void *mutex);
232 
243 int cb_lld_task_create(CB_THREAD_T *th, void *attr, void *(*func)(void*), void *arg);
244 
253 int cb_lld_task_join(CB_THREAD_T th, void **retval);
254 
259 void cb_lld_task_exit(void *retval);
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 #endif //CB_LLD_THREAD_H
266 
cb_lld_mutex_t
struct cb_lld_mutex cb_lld_mutex_t
Definition: cb_lld_thread.h:69
cb_lld_sem_init
int cb_lld_sem_init(CB_SEM_T *sem, int pshared, unsigned int value)
Initializes a semaphore.
cb_lld_mutex_trylock
int cb_lld_mutex_trylock(CB_THREAD_MUTEX_T *mutex)
Attempts to lock a mutex without blocking.
cb_lld_sem_post
int cb_lld_sem_post(CB_SEM_T *sem)
Posts (signals) a semaphore, releasing a waiting thread.
CB_THREAD_T
#define CB_THREAD_T
Definition: cb_lld_thread.h:72
cb_lld_mutex_destroy
int cb_lld_mutex_destroy(CB_THREAD_MUTEX_T *mutex)
Destroys a mutex.
cb_lld_sem_t
struct cb_lld_sem cb_lld_sem_t
Definition: cb_lld_thread.h:68
CB_THREAD_MUTEXATTR_T
#define CB_THREAD_MUTEXATTR_T
Definition: cb_lld_thread.h:88
cb_lld_task_exit
void cb_lld_task_exit(void *retval)
Terminates the calling thread.
CB_SEM_T
#define CB_SEM_T
Definition: cb_lld_thread.h:93
cb_lld_mutex_unlock
int cb_lld_mutex_unlock(CB_THREAD_MUTEX_T *mutex)
Unlocks a mutex.
cb_lld_mutex_timedlock
int cb_lld_mutex_timedlock(CB_THREAD_MUTEX_T *mutex, struct timespec *abstime)
Locks a mutex and waits until a timeout occurs.
value
uint32_t value
Definition: tisci_otp_revision.h:2
cb_lld_sem_wait_status
int cb_lld_sem_wait_status(CB_SEM_T *sem)
Get the semaphore wait status. The return value of this function determines the wait status of cb_lld...
cb_lld_global_mutex_init
int cb_lld_global_mutex_init(void *mutex)
Initializes a global mutex, similar to the ref cb_lld_mutex_init() except there is no log when error ...
cb_lld_task_create
int cb_lld_task_create(CB_THREAD_T *th, void *attr, void *(*func)(void *), void *arg)
Creates a new thread. This function creates a new thread with the specified attributes and starts exe...
cb_lld_task_join
int cb_lld_task_join(CB_THREAD_T th, void **retval)
Waits for a thread to terminate. This function waits for the specified thread to terminate.
cb_lld_sem_trywait
int cb_lld_sem_trywait(CB_SEM_T *sem)
Attempts to wait on a semaphore without blocking. To know if the semaphore was acquired,...
CB_THREAD_MUTEX_T
#define CB_THREAD_MUTEX_T
Definition: cb_lld_thread.h:77
cb_lld_sem_timedwait
int cb_lld_sem_timedwait(CB_SEM_T *sem, struct timespec *abstime)
Waits on a semaphore until it becomes available or until a timeout occurs. To know if the semaphore w...
cb_lld_mutex_lock
int cb_lld_mutex_lock(CB_THREAD_MUTEX_T *mutex)
Locks a mutex.
cb_lld_mutex_init
int cb_lld_mutex_init(CB_THREAD_MUTEX_T *mutex, CB_THREAD_MUTEXATTR_T attr)
Initializes a mutex.
cb_lld_sem_destroy
int cb_lld_sem_destroy(CB_SEM_T *sem)
Destroys a semaphore.
cb_lld_task_t
struct cb_lld_task cb_lld_task_t
Definition: cb_lld_thread.h:70
cb_lld_sem_wait
int cb_lld_sem_wait(CB_SEM_T *sem)
Waits on a semaphore until it becomes available.