support posix
1. posix pthread.h: pthread, pthread_barrier, pthread_cond, pthread_mutex, , pthread_rwlock, pthread_spin, etc 2. posix semaphore.h: sem_* 3. posix mqueue.h: mq_* 4. posix time.h: timer_* 5. to support posix, add tos_barrier, tos_bitmap, tos_rwlock, tos_stopwatch, change name of k_task_t from a char * pointer to a char array. 6. sample, see examples\posix 7. project, see board\TencentOS_tiny_EVB_MX_Plus\KEIL\posix
This commit is contained in:
47
osal/posix/include/private/mqueue.h
Normal file
47
osal/posix/include/private/mqueue.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _POSIX_PRIVATE_MQUEUE_H_
|
||||
#define _POSIX_PRIVATE_MQUEUE_H_
|
||||
|
||||
#include "tos_k.h"
|
||||
|
||||
#include "private/posix_config.h"
|
||||
|
||||
__CDECLS_BEGIN
|
||||
|
||||
#define MQUEUE_MAX (POSIX_CFG_MQUEUE_MAX)
|
||||
|
||||
#define MQUEUE_MSG_MAX 20
|
||||
#define MQUEUE_MSG_SIZE_MAX 50
|
||||
|
||||
typedef struct mqueue_control_st {
|
||||
mqd_t id;
|
||||
k_prio_mail_q_t kprio_mail_q;
|
||||
} mqueue_ctl_t;
|
||||
|
||||
__KNL__ int mqueue_id_add(mqd_t id, mqueue_ctl_t *mqueue_ctl);
|
||||
|
||||
__KNL__ mqd_t mqueue_id_alloc(void);
|
||||
|
||||
__KNL__ int mqueue_id_free(mqd_t id);
|
||||
|
||||
__KNL__ mqueue_ctl_t *mqueue_by_id(mqd_t id);
|
||||
|
||||
__CDECLS_END
|
||||
|
||||
#endif /* _POSIX_PRIVATE_TIMER_H_*/
|
48
osal/posix/include/private/posix_config.h
Normal file
48
osal/posix/include/private/posix_config.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _POSIX_CONFIG_H_
|
||||
#define _POSIX_CONFIG_H_
|
||||
|
||||
|
||||
#define POSIX_CFG_PTHREAD_THREADS_MAX 32
|
||||
#define POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS 4
|
||||
#define POSIX_CFG_PTHREAD_KEYS_MAX 8
|
||||
|
||||
#define POSIX_CFG_TIMERS_MAX 8
|
||||
|
||||
#define POSIX_CFG_MQUEUE_MAX 8
|
||||
|
||||
#define POSIX_CFG_PTHREAD_BARRIER_EN 1u
|
||||
|
||||
#define POSIX_CFG_PTHREAD_COND_EN 1u
|
||||
|
||||
#define POSIX_CFG_PTHREAD_MUTEX_EN 1u
|
||||
|
||||
#define POSIX_CFG_PTHREAD_RWLOCK_EN 1u
|
||||
|
||||
#define POSIX_CFG_PTHREAD_SPIN_EN 1u
|
||||
|
||||
#define POSIX_CFG_SEM_EN 1u
|
||||
|
||||
#define POSIX_CFG_MQUEUE_EN 1u
|
||||
|
||||
#define POSIX_CFG_TIMER_EN 1u
|
||||
|
||||
#include "private/posix_config_check.h"
|
||||
|
||||
#endif /* _POSIX_CONFIG_H_ */
|
61
osal/posix/include/private/posix_config_check.h
Normal file
61
osal/posix/include/private/posix_config_check.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _POSIX_CONFIG_CHECK_H_
|
||||
#define _POSIX_CONFIG_CHECK_H_
|
||||
|
||||
|
||||
#include "tos_config.h"
|
||||
#include "private/posix_config_default.h"
|
||||
|
||||
#if (TOS_CFG_MMHEAP_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_MMHEAP_EN to use posix stuff"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_PTHREAD_COND_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use pthread_cond"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_PTHREAD_COND_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_cond"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_PTHREAD_MUTEX_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_mutex"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_PTHREAD_RWLOCK_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use pthread_rwlock"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_PTHREAD_RWLOCK_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_rwlock"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_SEM_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use posix sem"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_MQUEUE_EN > 0u) && (TOS_CFG_PRIORITY_MAIL_QUEUE_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_PRIORITY_MAIL_QUEUE_EN to use posix mqueue"
|
||||
#endif
|
||||
|
||||
#if (POSIX_CFG_TIMER_EN > 0u) && (TOS_CFG_TIMER_EN == 0u)
|
||||
#error "INVALID config, Must enable TOS_CFG_TIMER_EN to use posix timer"
|
||||
#endif
|
||||
|
||||
#endif /* _POSIX_CONFIG_CHECK_H_ */
|
74
osal/posix/include/private/posix_config_default.h
Normal file
74
osal/posix/include/private/posix_config_default.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _POSIX_CONFIG_DEFAULT_H_
|
||||
#define _POSIX_CONFIG_DEFAULT_H_
|
||||
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_THREADS_MAX
|
||||
#define POSIX_CFG_PTHREAD_THREADS_MAX 32
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS
|
||||
#define POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS 4
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_KEYS_MAX
|
||||
#define POSIX_CFG_PTHREAD_KEYS_MAX 8
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_TIMERS_MAX
|
||||
#define POSIX_CFG_TIMERS_MAX 8
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_MQUEUE_MAX
|
||||
#define POSIX_CFG_MQUEUE_MAX 8
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_BARRIER_EN
|
||||
#define POSIX_CFG_PTHREAD_BARRIER_EN 1u
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_COND_EN
|
||||
#define POSIX_CFG_PTHREAD_COND_EN 1u
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_MUTEX_EN
|
||||
#define POSIX_CFG_PTHREAD_MUTEX_EN 1u
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_RWLOCK_EN
|
||||
#define POSIX_CFG_PTHREAD_RWLOCK_EN 1u
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_PTHREAD_SPIN_EN
|
||||
#define POSIX_CFG_PTHREAD_SPIN_EN 1u
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_SEM_EN
|
||||
#define POSIX_CFG_SEM_EN 1u
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_MQUEUE_EN
|
||||
#define POSIX_CFG_MQUEUE_EN 1u
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_CFG_TIMER_EN
|
||||
#define POSIX_CFG_TIMER_EN 1u
|
||||
#endif
|
||||
|
||||
#endif /* _POSIX_CONFIG_DEFAULT_H_ */
|
119
osal/posix/include/private/pthread.h
Normal file
119
osal/posix/include/private/pthread.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _POSIX_PRIVATE_PTHREAD_H_
|
||||
#define _POSIX_PRIVATE_PTHREAD_H_
|
||||
|
||||
#include "tos_k.h"
|
||||
|
||||
#include "private/posix_config.h"
|
||||
|
||||
#include "sys/types.h"
|
||||
|
||||
__CDECLS_BEGIN
|
||||
|
||||
typedef struct pthread_control_st {
|
||||
uint16_t threadstate : 4;
|
||||
uint16_t cancelstate : 2;
|
||||
uint16_t canceltype : 2;
|
||||
uint16_t cancelpending : 1;
|
||||
|
||||
pthread_t id;
|
||||
pthread_attr_t attr;
|
||||
k_task_t ktask;
|
||||
k_task_t *the_ktask;
|
||||
|
||||
k_sem_t joinner_sem;
|
||||
|
||||
void *(*start_routine)(void *); /* start routine of the pthread */
|
||||
void *arg; /* argument to start routine */
|
||||
void *retval; /* return value of start routine */
|
||||
void *stackaddr; /* memory of address */
|
||||
|
||||
k_slist_t cleanup_ctl_list;
|
||||
|
||||
void **thread_data;
|
||||
} pthread_ctl_t;
|
||||
|
||||
typedef struct pthread_cleanup_control_st {
|
||||
void (*routine)(void *); /* function to be called */
|
||||
void *arg; /* argument for the routine */
|
||||
k_slist_t list;
|
||||
} pthread_cleanup_ctl_t;
|
||||
|
||||
#define PTHREAD_KEYS_MAX (POSIX_CFG_PTHREAD_KEYS_MAX)
|
||||
|
||||
typedef void (*key_destructor_t)(void*);
|
||||
|
||||
typedef struct pthread_key_control_st {
|
||||
k_bmtbl_t key_bitmap_tbl[TOS_BITMAP_SIZE(PTHREAD_KEYS_MAX)];
|
||||
k_bitmap_t key_bitmap;
|
||||
key_destructor_t destructors[PTHREAD_KEYS_MAX];
|
||||
} pthread_key_ctl_t;
|
||||
|
||||
#define PTHREAD_INFO_SIZE (sizeof(pthread_ctl_t))
|
||||
#define PTHREAD_STK_SIZE_MIN (K_TASK_STK_SIZE_MIN + PTHREAD_INFO_SIZE)
|
||||
|
||||
#define PTHREAD_DEFAULT_TIMESLICE 20
|
||||
#define PTHREAD_DEFAULT_STACKSIZE (2048 + PTHREAD_INFO_SIZE)
|
||||
#define PTHREAD_DEFAULT_INHERIT_SCHED PTHREAD_INHERIT_SCHED
|
||||
#define PTHREAD_DEFAULT_SCHEDPOLICY SCHED_OTHER
|
||||
#define PTHREAD_DEFAULT_PRIORITY (TOS_CFG_TASK_PRIO_MAX / 2)
|
||||
#define PTHREAD_DEFAULT_DETACH_STATE PTHREAD_CREATE_JOINABLE
|
||||
|
||||
#define PTHREAD_DESTRUCTOR_ITERATIONS (POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS)
|
||||
|
||||
#define PTHREAD_THREADS_MAX (POSIX_CFG_PTHREAD_THREADS_MAX)
|
||||
|
||||
__KNL__
|
||||
pthread_ctl_t *pthread_ctl_self(void);
|
||||
|
||||
__KNL__ pthread_ctl_t *pthread_ctl_by_id(pthread_t id);
|
||||
|
||||
__KNL__ int pthread_id_add(pthread_t id, pthread_ctl_t *info);
|
||||
|
||||
__KNL__ pthread_t pthread_id_alloc(void);
|
||||
|
||||
__KNL__ int pthread_id_free(pthread_t id);
|
||||
|
||||
__KNL__ void pthread_data_clear(pthread_key_t key);
|
||||
|
||||
__KNL__ int pthread_key_ctl_init(void);
|
||||
|
||||
__KNL__ pthread_key_t pthread_key_alloc(void);
|
||||
|
||||
__KNL__ int pthread_key_is_alloc(pthread_key_t key);
|
||||
|
||||
__KNL__ int pthread_key_free(pthread_key_t key);
|
||||
|
||||
__KNL__ int pthread_key_destructor_register(pthread_key_t key, key_destructor_t destructor);
|
||||
|
||||
__KNL__ key_destructor_t pthread_key_destructor_get(pthread_key_t key);
|
||||
|
||||
__KNL__ int pthread_ctl_reap(int pthreads_ready2reap);
|
||||
|
||||
__KNL__ void pthread_lock(void);
|
||||
|
||||
__KNL__ void pthread_unlock(void);
|
||||
|
||||
__KNL__ int pthread_lock_init(void);
|
||||
|
||||
__KNL__ int pthread_init(void);
|
||||
|
||||
__CDECLS_END
|
||||
|
||||
#endif /* _POSIX_PRIVATE_PTHREAD_PRV_H_ */
|
36
osal/posix/include/private/time.h
Normal file
36
osal/posix/include/private/time.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _POSIX_PRIVATE_TIME_H_
|
||||
#define _POSIX_PRIVATE_TIME_H_
|
||||
|
||||
#include "tos_k.h"
|
||||
|
||||
__CDECLS_BEGIN
|
||||
|
||||
#define MILLISECOND_PER_SECOND 1000UL
|
||||
#define MICROSECOND_PER_SECOND 1000000UL
|
||||
#define NANOSECOND_PER_SECOND 1000000000UL
|
||||
|
||||
__KNL__ k_tick_t timespec_to_ktick(const struct timespec *tp);
|
||||
|
||||
__KNL__ void ktick_to_timespec(k_tick_t ktick, struct timespec *tp);
|
||||
|
||||
__CDECLS_END
|
||||
|
||||
#endif /* _POSIX_PRIVATE_TIME_H_ */
|
||||
|
50
osal/posix/include/private/timer.h
Normal file
50
osal/posix/include/private/timer.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* Tencent is pleased to support the open source community by making TencentOS
|
||||
* available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||
*
|
||||
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||
* License, except for the third-party components listed below which are
|
||||
* subject to different license terms. Your integration of TencentOS into your
|
||||
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||
* as the other licenses applicable to the third-party components included
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _POSIX_PRIVATE_TIMER_H_
|
||||
#define _POSIX_PRIVATE_TIMER_H_
|
||||
|
||||
#include "tos_k.h"
|
||||
|
||||
#include "private/posix_config.h"
|
||||
|
||||
#include "signal.h"
|
||||
|
||||
__CDECLS_BEGIN
|
||||
|
||||
#define TIMERS_MAX (POSIX_CFG_TIMERS_MAX)
|
||||
|
||||
typedef struct ptimer_control_st {
|
||||
timer_t id;
|
||||
k_timer_t ktimer;
|
||||
|
||||
void (*sigev_notify_function)(union sigval);
|
||||
union sigval sigev_value;
|
||||
} ptimer_ctl_t;
|
||||
|
||||
__KNL__ int timer_id_add(timer_t id, ptimer_ctl_t *ptimer_ctl);
|
||||
|
||||
__KNL__ timer_t timer_id_alloc(void);
|
||||
|
||||
__KNL__ int timer_id_free(timer_t id);
|
||||
|
||||
__KNL__ ptimer_ctl_t *timer_by_id(timer_t id);
|
||||
|
||||
__CDECLS_END
|
||||
|
||||
#endif /* _POSIX_PRIVATE_TIMER_H_*/
|
||||
|
Reference in New Issue
Block a user