add ring queue/message queue/mail queue, binary heap/priority queue/priority message queue/priority mail queue

1. remove the old msg queue and queue:
i. msg queue is not a common and reusable/flexible component(need user to config the msg pool size and this componet can only be used by tos_queue)
ii. tos_queue can only deliver the pointer message(cannot do a memory buffer deliver)

2. add ring queue(tos_ring_q) componet
rinq queue can be reused by tos_chr_fifi/tos_msg_q/tos_mail_q as the foundational data container

3. add message queue(tos_msg_q)
a little like the old queue mechanism, supply the capability to deliver a pointer message

4. add mail queue(tos_mail_q)
supply the capability to deliver a memory buffer

5. add binary heap(tos_bin_heap)
the basement componet to implement priority queue

6. add priority queue(tos_prio_q)
can be reused by the priority message/mail queue  as the foundational data container.

7. add priority message queue(tos_prio_msg_q)
a message(pointer) deliver mechanism, supply the capability of delivering the message with priority(message with higher priority comes faster to the pender than with lower)

8. add priority mail queue(tos_prio_mail_q)
a mail(memory buffer) deliver mechanism, supply the capability of delivering the mail with priority(mail with higher priority comes faster to the pender than with lower)
This commit is contained in:
daishengdong
2019-10-28 15:50:46 +08:00
parent f35b725a59
commit d0b8d0675e
127 changed files with 26661 additions and 14013 deletions

View File

@@ -35,11 +35,16 @@
#include <tos_pm.h>
#include <tos_pend.h>
#include <tos_sys.h>
#include <tos_fifo.h>
#include <tos_ring_queue.h>
#include <tos_char_fifo.h>
#include <tos_mail_queue.h>
#include <tos_message_queue.h>
#include <tos_binary_heap.h>
#include <tos_priority_queue.h>
#include <tos_priority_mail_queue.h>
#include <tos_priority_message_queue.h>
#include <tos_task.h>
#include <tos_robin.h>
#include <tos_msg.h>
#include <tos_queue.h>
#include <tos_mutex.h>
#include <tos_sem.h>
#include <tos_event.h>

View File

@@ -0,0 +1,149 @@
/*----------------------------------------------------------------------------
* 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 _TOS_BINARY_HEAP_H_
#define _TOS_BINARY_HEAP_H_
typedef int (*k_bin_heap_cmp)(void *first, void *second);
typedef struct k_binary_heap_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
size_t total;
k_bin_heap_cmp cmp;
size_t item_size;
size_t item_cnt;
uint8_t *pool;
} k_bin_heap_t;
#define BIN_HEAP_FIRST_ITEM(bin_heap) (void *)(&bin_heap->pool[0])
#define BIN_HEAP_LAST_ITEM(bin_heap) (void *)(&bin_heap->pool[bin_heap->total * bin_heap->item_size])
#define BIN_HEAP_THE_ITEM(bin_heap, index) (void *)(&bin_heap->pool[index * bin_heap->item_size])
#define BIN_HEAP_PARENT(index) ((index - 1) / 2)
#define BIN_HEAP_RCHILD(index) (2 * (index + 1))
#define BIN_HEAP_LSIBLING(index) (index - 1)
/**
* @brief Create a binary heap.
* create a binary heap.
*
* @attention None
*
* @param[in] bin_heap pointer to the handler of the binary heap.
* @param[in] pool pool buffer of the binary heap.
* @param[in] item_cnt item count of the binary heap.
* @param[in] item_size size of each item of the binary heap.
* @param[in] cmp compare function to determine two items which is bigger or smaller.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_bin_heap_create(k_bin_heap_t *bin_heap, void *pool, size_t item_cnt, size_t item_size, k_bin_heap_cmp cmp);
/**
* @brief Destroy a binary heap.
* destroy a binary heap.
*
* @attention None
*
* @param[in] bin_heap pointer to the handler of the binary heap.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_bin_heap_destroy(k_bin_heap_t *bin_heap);
/**
* @brief Push an item.
* push an item into the binary heap.
*
* @attention None
*
* @param[in] bin_heap pointer to the handler of the binary heap.
* @param[in] item the item to be pushed.
* @param[in] item_size size of the item(should be consistent with the item_size passed to tos_bin_heap_create).
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_BIN_HEAP_ITEM_SIZE_NOT_MATCH the item_size is not consistent with the item_size passed to tos_bin_heap_create.
* @retval #K_ERR_BIN_HEAP_FULL the binary heap is full.
*/
__API__ k_err_t tos_bin_heap_push(k_bin_heap_t *bin_heap, void *item, size_t item_size);
/**
* @brief Pop an item.
* pop an item from the binary heap.
*
* @attention None
*
* @param[in] bin_heap pointer to the handler of the binary heap.
* @param[out] item buffer to hold the item poped.
* @param[out] item_size size of the item poped(should be consistent with the item_size passed to tos_bin_heap_create).
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_BIN_HEAP_EMPTY the ring queue is empty.
*/
__API__ k_err_t tos_bin_heap_pop(k_bin_heap_t *bin_heap, void *item, size_t *item_size);
/**
* @brief Flush the binary heap.
* flush the binary heap.
*
* @attention None
*
* @param[in] bin_heap pointer to the handler of the binary heap.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_bin_heap_flush(k_bin_heap_t *bin_heap);
/**
* @brief Whether the binary heap is empty.
* Whether the binary heap is empty.
*
* @attention None
*
* @param[in] bin_heap pointer to the handler of the binary heap.
*
* @return whether the binary heap is emtpy.
* @retval #0 the binary heap is not empty.
* @retval #Not 0 the binary heap is empty.
*/
__API__ int tos_bin_heap_is_empty(k_bin_heap_t *bin_heap);
/**
* @brief Whether the binary heap is full.
* Whether the binary heap is full.
*
* @attention None
*
* @param[in] bin_heap pointer to the handler of the binary heap.
*
* @return whether the binary hea is full.
* @retval #0 the binary hea is not full.
* @retval #Not 0 the binary hea is full.
*/
__API__ int tos_bin_heap_is_full(k_bin_heap_t *bin_heap);
#endif /* _TOS_BINARY_HEAP_H_ */

View File

@@ -0,0 +1,159 @@
/*----------------------------------------------------------------------------
* 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 _TOS_CHAR_FIFO_H_
#define _TOS_CHAR_FIFO_H_
typedef struct k_char_fifo_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
k_ring_q_t ring_q;
} k_chr_fifo_t;
/**
* @brief Create a character fifo.
* Create a character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
* @param[in] buffer memory buffer provided to be as the inner buffer.
* @param[in] size size of the memory buffer.
*
* @return errno
* @retval #K_ERR_OBJ_PTR_NULL fifo is a NULL pointer.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_create(k_chr_fifo_t *chr_fifo, void *buffer, size_t size);
/**
* @brief Destroy a character fifo.
* Destroy a character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
*
* @return errno
* @retval #K_ERR_OBJ_PTR_NULL fifo is a NULL pointer.
* @retval #K_ERR_OBJ_INVALID not a valid pointer to a fifo.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_destroy(k_chr_fifo_t *chr_fifo);
/**
* @brief Push data into character fifo.
* Push one single data into the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[in] data data to push into the fifo.
*
* @return errno
* @retval #K_ERR_RING_Q_FULL the character fifo is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_push(k_chr_fifo_t *chr_fifo, uint8_t data);
/**
* @brief Push stream into character fifo.
* Push a stream data into the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[IN] stream stream to be pushed into the character fifo.
* @param[OUT] size size of the stream.
*
* @return the actual number of the data pushed into the character fifo.
*/
__API__ int tos_chr_fifo_push_stream(k_chr_fifo_t *chr_fifo, uint8_t *stream, size_t size);
/**
* @brief Pop data from character fifo.
* Pop one single data from the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[OUT] out one signle buffer to hold the data poped from the character fifo.
*
* @return errno
* @retval #K_ERR_FIFO_EMPTY the character fifo is empty.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_pop(k_chr_fifo_t *chr_fifo, uint8_t *out);
/**
* @brief Pop stream from character fifo.
* Pop a stream data from the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[OUT] buffer pointer to the buffer to receive the stream poped.
* @param[OUT] size size of the buffer.
*
* @return the actual number of the data poped from the character fifo.
*/
__API__ int tos_chr_fifo_pop_stream(k_chr_fifo_t *chr_fifo, uint8_t *buffer, size_t size);
/**
* @brief Flush character fifo.
* Flush/reset the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
*
* @return None.
*/
__API__ k_err_t tos_chr_fifo_flush(k_chr_fifo_t *chr_fifo);
/**
* @brief Whether the character fifo is empty.
* Whether the character fifo is empty.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
*
* @return whether the character fifo is emtpy.
* @retval #0 the character fifo is not empty.
* @retval #Not 0 the character fifo is empty.
*/
__API__ int tos_chr_fifo_is_empty(k_chr_fifo_t *chr_fifo);
/**
* @brief Whether the character fifo is full.
* Whether the character fifo is full.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
*
* @return whether the character fifo is full.
* @retval #0 the character fifo is not full.
* @retval #Not 0 the character fifo is full.
*/
__API__ int tos_chr_fifo_is_full(k_chr_fifo_t *chr_fifo);
#endif // _TOS_CHAR_FIFO_H_

View File

@@ -44,8 +44,12 @@
#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to support dynamic task create"
#endif
#if (TOS_CFG_QUEUE_EN > 0u) && (TOS_CFG_MSG_EN == 0u)
#error "INVALID config, must enable TOS_CFG_MSG_EN to use tos_queue"
#if (TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u)
#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to support tos_prio_msg_q"
#endif
#if (TOS_CFG_PRIORITY_MAIL_QUEUE_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u)
#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to support tos_prio_mail_q"
#endif
#if ((TOS_CFG_TIMER_EN > 0u) && !defined(TOS_CFG_TIMER_AS_PROC))

View File

@@ -60,15 +60,6 @@
/////////////////////////////////////////
/////////////////////////////////////////
// disable queue
#ifdef TOS_CFG_QUEUE_EN
#undef TOS_CFG_QUEUE_EN
#endif
#define TOS_CFG_QUEUE_EN 0u
/////////////////////////////////////////
/////////////////////////////////////////
// disable semaphore
#ifdef TOS_CFG_SEM_EN
@@ -195,8 +186,20 @@
#define TOS_CFG_MUTEX_EN 0u
#endif
#ifndef TOS_CFG_QUEUE_EN
#define TOS_CFG_QUEUE_EN 0u
#ifndef TOS_CFG_MESSAGE_QUEUE_EN
#define TOS_CFG_MESSAGE_QUEUE_EN 0u
#endif
#ifndef TOS_CFG_MAIL_QUEUE_EN
#define TOS_CFG_MAIL_QUEUE_EN 0u
#endif
#ifndef TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN
#define TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN 0u
#endif
#ifndef TOS_CFG_PRIORITY_MAIL_QUEUE_EN
#define TOS_CFG_PRIORITY_MAIL_QUEUE_EN 0u
#endif
#ifndef TOS_CFG_SEM_EN
@@ -211,12 +214,6 @@
#define TOS_CFG_COMPLETION_EN 0u
#endif
#if (TOS_CFG_QUEUE_EN > 0u) && !defined(TOS_CFG_MSG_EN)
#define TOS_CFG_MSG_EN 1u
#elif (TOS_CFG_QUEUE_EN == 0u) && !defined(TOS_CFG_MSG_EN)
#define TOS_CFG_MSG_EN 0u
#endif
#ifndef TOS_CFG_TIMER_EN
#define TOS_CFG_TIMER_EN 0u
#endif
@@ -225,10 +222,6 @@
#define TOS_CFG_TIMER_AS_PROC 0u
#endif
#ifndef TOS_CFG_MSG_POOL_SIZE
#define TOS_CFG_MSG_POOL_SIZE 100u
#endif
#ifndef TOS_CFG_IDLE_TASK_STK_SIZE
#define TOS_CFG_IDLE_TASK_STK_SIZE 128u
#endif

View File

@@ -21,6 +21,10 @@
typedef enum k_err_en {
K_ERR_NONE = 0u,
K_ERR_BIN_HEAP_FULL = 10u,
K_ERR_BIN_HEAP_EMPTY,
K_ERR_BIN_HEAP_ITEM_SIZE_NOT_MATCH,
K_ERR_COMPLETION_OVERFLOW = 25u,
K_ERR_COUNTDOWNLATCH_OVERFLOW = 50u,
@@ -30,9 +34,6 @@ typedef enum k_err_en {
K_ERR_EVENT_PEND_OPT_INVALID = 200u,
K_ERR_FIFO_FULL = 300u,
K_ERR_FIFO_EMPTY,
K_ERR_IN_IRQ = 400u,
K_ERR_KNL_NOT_RUNNING = 500u,
@@ -51,10 +52,6 @@ typedef enum k_err_en {
K_ERR_MMHEAP_POOL_ALREADY_EXIST,
K_ERR_MMHEAP_POOL_NOT_EXIST,
K_ERR_MSG_QUEUE_FULL = 900u,
K_ERR_MSG_QUEUE_EMPTY,
K_ERR_MSG_QUEUE_MSG_NOT_EXIST,
K_ERR_MUTEX_NOT_OWNER = 1000u,
K_ERR_MUTEX_NESTING,
K_ERR_MUTEX_NESTING_OVERFLOW,
@@ -62,15 +59,9 @@ typedef enum k_err_en {
K_ERR_OBJ_PTR_NULL = 1100u,
K_ERR_OBJ_INVALID,
K_ERR_PM_DEVICE_ALREADY_REG = 1200u,
K_ERR_PM_DEVICE_OVERFLOW = 1300u,
K_ERR_PM_WKUP_SOURCE_NOT_INSTALL = 1400u,
K_ERR_OUT_OF_MEMORY = 1150u,
K_ERR_QUEUE_EMPTY = 1500u,
K_ERR_QUEUE_FULL,
K_ERR_QUEUE_MSG_NOT_EXIST,
K_ERR_PEND_NOWAIT = 1600u,
K_ERR_PEND_NOWAIT = 1200u,
K_ERR_PEND_SCHED_LOCKED,
K_ERR_PEND_IN_IRQ,
K_ERR_PEND_ABNORMAL,
@@ -78,6 +69,19 @@ typedef enum k_err_en {
K_ERR_PEND_DESTROY,
K_ERR_PEND_OWNER_DIE,
K_ERR_PM_DEVICE_ALREADY_REG = 1300u,
K_ERR_PM_DEVICE_OVERFLOW,
K_ERR_PM_WKUP_SOURCE_NOT_INSTALL,
K_ERR_PRIO_Q_EMPTY = 1400u,
K_ERR_PRIO_Q_FULL,
K_ERR_PRIO_Q_SLOT_NOT_TAKEN,
K_ERR_PRIO_Q_ITEM_SIZE_NOT_MATCH,
K_ERR_RING_Q_FULL = 1600u,
K_ERR_RING_Q_EMPTY,
K_ERR_RING_Q_ITEM_SIZE_NOT_MATCH,
K_ERR_SCHED_LOCKED = 1700u,
K_ERR_SCHED_NOT_LOCKED,

View File

@@ -1,163 +0,0 @@
/*----------------------------------------------------------------------------
* 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 _TOS_FIFO_H_
#define _TOS_FIFO_H_
typedef struct k_fifo_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
int beg;
int end;
size_t cnt;
uint8_t *buf;
size_t siz;
} k_fifo_t;
/**
* @brief Create a fifo.
* Create a fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
* @param[in] buffer memory buffer provided to be as the inner buffer.
* @param[in] size size of the memory buffer.
*
* @return errno
* @retval #K_ERR_OBJ_PTR_NULL fifo is a NULL pointer.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_fifo_create(k_fifo_t *fifo, uint8_t *buffer, size_t size);
/**
* @brief Destroy a fifo.
* Destroy a fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
*
* @return errno
* @retval #K_ERR_OBJ_PTR_NULL fifo is a NULL pointer.
* @retval #K_ERR_OBJ_INVALID not a valid pointer to a fifo.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_fifo_destroy(k_fifo_t *fifo);
/**
* @brief Push data into fifo.
* Push one single data into the fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
* @param[in] data data to push into the fifo.
*
* @return errno
* @retval #K_ERR_FIFO_FULL the fifo is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_fifo_push(k_fifo_t *fifo, uint8_t data);
/**
* @brief Push stream into fifo.
* Push a stream data into the fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
* @param[IN] stream stream to be pushed into the fifo.
* @param[OUT] size size of the stream.
*
* @return the actual number of the data pushed into the fifo.
*/
__API__ int tos_fifo_push_stream(k_fifo_t *fifo, uint8_t *stream, size_t size);
/**
* @brief Pop data from fifo.
* Pop one single data from the fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
* @param[OUT] out one signle buffer to hold the data poped from the fifo.
*
* @return errno
* @retval #K_ERR_FIFO_EMPTY the fifo is empty.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_fifo_pop(k_fifo_t *fifo, uint8_t *out);
/**
* @brief Pop stream from fifo.
* Pop a stream data from the fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
* @param[OUT] buffer pointer to the buffer to receive the stream poped.
* @param[OUT] size size of the buffer.
*
* @return the actual number of the data poped from the fifo.
*/
__API__ int tos_fifo_pop_stream(k_fifo_t *fifo, uint8_t *buffer, size_t size);
/**
* @brief Flush fifo.
* Flush/reset the fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
*
* @return None.
*/
__API__ void tos_fifo_flush(k_fifo_t *fifo);
/**
* @brief Whether the fifo is empty.
* Whether the fifo is empty.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
*
* @return whether the fifo is emtpy.
* @retval #0 the fifo is not empty.
* @retval #Not 0 the fifo is empty.
*/
__API__ int tos_fifo_is_empty(k_fifo_t *fifo);
/**
* @brief Whether the fifo is full.
* Whether the fifo is full.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
*
* @return whether the fifo is full.
* @retval #0 the fifo is not full.
* @retval #Not 0 the fifo is full.
*/
__API__ int tos_fifo_is_full(k_fifo_t *fifo);
#endif // _TOS_FIFO_H_

View File

@@ -90,11 +90,6 @@ extern size_t const k_timer_task_stk_size;
#endif
#endif
#if (TOS_CFG_MSG_EN > 0u)
extern k_list_t k_msg_freelist;
extern k_msg_t k_msg_pool[];
#endif
#if TOS_CFG_PWR_MGR_EN > 0u
extern pm_device_ctl_t k_pm_device_ctl;

View File

@@ -51,5 +51,17 @@
printf(__VA_ARGS__); \
printf("\n");
#define TOS_ASSERT_AUX(exp, function, line) \
if (!(exp)) { \
tos_kprintln("assert failed: %s %d\n", function, line); \
tos_knl_sched_lock(); \
tos_cpu_int_disable(); \
while (K_TRUE) { \
; \
} \
}
#define TOS_ASSERT(exp) TOS_ASSERT_AUX(exp, __FUNCTION__, __LINE__)
#endif /* _TOS_KLIB_H_ */

View File

@@ -0,0 +1,125 @@
/*----------------------------------------------------------------------------
* 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 _TOS_MAIL_QUEUE_H_
#define _TOS_MAIL_QUEUE_H_
#if TOS_CFG_MAIL_QUEUE_EN > 0u
typedef struct k_mail_queue_st {
pend_obj_t pend_obj;
k_ring_q_t ring_q;
} k_mail_q_t;
/**
* @brief Create a mail queue.
* create a mail queue.
*
* @attention a MAIL is a buffer with a certain size.
*
* @param[in] mail_q pointer to the handler of the mail queue.
* @param[in] pool pool buffer of the mail queue.
* @param[in] mail_cnt mail count of the mail queue.
* @param[in] mail_size size of each mail in the mail queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_mail_q_create(k_mail_q_t *mail_q, void *pool, size_t mail_cnt, size_t mail_size);
/**
* @brief Destroy a mail queue.
* destroy a mail queue.
*
* @attention None
*
* @param[in] mail_q pointer to the handler of the mail queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_mail_q_destroy(k_mail_q_t *mail_q);
/**
* @brief Flush the mail queue.
* flush the mail queue.
*
* @attention None
*
* @param[in] mail_q pointer to the handler of the mail queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_mail_q_flush(k_mail_q_t *mail_q);
/**
* @brief Pend a mail queue.
* pend a mail queue.
*
* @attention we WILL perform a memcpy when mail_buf is received(a MAIL is a buffer with a certain size).
*
* @param[in] mail_q pointer to the handler of the mail queue.
* @param[OUT] mail_buf a pointer to the mail buffer we wanna receive.
* @param[OUT] mail_size size of the mail buffer received(should be consistent with the mail_size passed to tos_mail_q_create).
* @param[in] timeout how much time(in k_tick_t) we would like to wait.
*
* @return errcode
* @retval #K_ERR_PEND_NOWAIT we get nothing, and we don't wanna wait.
* @retval #K_ERR_PEND_SCHED_LOCKED we can wait, but scheduler is locked.
* @retval #K_ERR_PEND_TIMEOUT the time we wait is up, we get nothing.
* @retval #K_ERR_PEND_DESTROY the queue we are pending is destroyed.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_mail_q_pend(k_mail_q_t *mail_q, void *mail_buf, size_t *mail_size, k_tick_t timeout);
/**
* @brief Post a mail queue.
* post a mail queue and wakeup one pending task.
*
* @attention when tos_mail_q_post return successfully, only one task who are waitting for the mail queue will be woken up.
*
* @param[in] mail_q pointer to the handler of the mail queue.
* @param[in] mail_buf the mail to post(a MAIL is a buffer).
* @param[in] mail_size the size of the mail to post(a MAIL is just a buffer).
*
* @return errcode
* @retval #K_ERR_RING_Q_FULL the mail queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_mail_q_post(k_mail_q_t *mail_q, void *mail_buf, size_t mail_size);
/**
* @brief Post a mail queue.
* post a mail queue and wakeup all the pending task.
*
* @attention when tos_mail_q_post_all return successfully, all of the tasks who are waitting for the message queue will be woken up.
*
* @param[in] mail_q pointer to the handler of the mail queue.
* @param[in] mail_buf the mail to post(a MAIL is a buffer).
* @param[in] mail_size the size of the mail to post(a MAIL is just a buffer).
*
* @return errcode
* @retval #K_ERR_RING_Q_FULL the mail queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_mail_q_post_all(k_mail_q_t *mail_q, void *mail_buf, size_t mail_size);
#endif
#endif /* _TOS_MAIL_QUEUE_H_ */

View File

@@ -0,0 +1,121 @@
/*----------------------------------------------------------------------------
* 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 _TOS_MESSAGE_QUEUE_H_
#define _TOS_MESSAGE_QUEUE_H_
#if TOS_CFG_MESSAGE_QUEUE_EN > 0u
typedef struct k_message_queue_st {
pend_obj_t pend_obj;
k_ring_q_t ring_q;
} k_msg_q_t;
/**
* @brief Create a message queue.
* create a message queue.
*
* @attention a MESSAGE is a "void *" pointer.
*
* @param[in] msg_q pointer to the handler of the message queue.
* @param[in] pool pool buffer of the message queue.
* @param[in] msg_cnt message count of the message queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_q_create(k_msg_q_t *msg_q, void *pool, size_t msg_cnt);
/**
* @brief Destroy a message queue.
* destroy a message queue.
*
* @attention None
*
* @param[in] msg_q pointer to the handler of the message queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_q_destroy(k_msg_q_t *msg_q);
/**
* @brief Flush the message queue.
* flush the message queue.
*
* @attention None
*
* @param[in] msg_q pointer to the handler of the message queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_q_flush(k_msg_q_t *msg_q);
/**
* @brief Pend a message queue.
* pend a message queue.
*
* @attention we DONNOT perform a memcpy when msg_ptr is received(a MESSAGE is just a pointer).
*
* @param[in] msg_q pointer to the handler of the message queue.
* @param[OUT] msg_ptr a pointer to the message we wanna receive.
* @param[in] timeout how much time(in k_tick_t) we would like to wait.
*
* @return errcode
* @retval #K_ERR_PEND_NOWAIT we get nothing, and we don't wanna wait.
* @retval #K_ERR_PEND_SCHED_LOCKED we can wait, but scheduler is locked.
* @retval #K_ERR_PEND_TIMEOUT the time we wait is up, we get nothing.
* @retval #K_ERR_PEND_DESTROY the queue we are pending is destroyed.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_q_pend(k_msg_q_t *msg_q, void **msg_ptr, k_tick_t timeout);
/**
* @brief Post a message queue.
* post a message queue and wakeup one pending task.
*
* @attention when tos_msg_q_post return successfully, only one task who are waitting for the message queue will be woken up.
*
* @param[in] msg_q pointer to the handler of the message queue.
* @param[in] msg_ptr the message to post(a MESSAGE is just a pointer).
*
* @return errcode
* @retval #K_ERR_RING_Q_FULL the message queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_q_post(k_msg_q_t *msg_q, void *msg_ptr);
/**
* @brief Post a message queue.
* post a message queue and wakeup all the pending task.
*
* @attention when tos_msg_q_post_all return successfully, all of the tasks who are waitting for the message queue will be woken up.
*
* @param[in] msg_q pointer to the handler of the message queue.
* @param[in] msg_ptr the message to post(a MESSAGE is just a pointer).
*
* @return errcode
* @retval #K_ERR_RING_Q_FULL the message queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_q_post_all(k_msg_q_t *msg_q, void *msg_ptr);
#endif
#endif /* _TOS_MESSAGE_QUEUE_H_ */

View File

@@ -1,129 +0,0 @@
/*----------------------------------------------------------------------------
* 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 _TOS_MSG_H_
#define _TOS_MSG_H_
#define TOS_OPT_MSG_PUT_LIFO (k_opt_t)0x0001
#define TOS_OPT_MSG_PUT_FIFO (k_opt_t)0x0002
typedef struct k_message_st {
k_list_t list;
void *msg_addr;
size_t msg_size;
} k_msg_t;
typedef struct k_msg_queue_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
k_list_t queue_head;
} k_msg_queue_t;
/**
* @brief Create a message queue.
* Initialize a message queue.
*
* @attention None
*
* @param[IN] msg_queue the pointer to the handler of the message queue.
*
* @return errcode.
* @retval #K_ERR_OBJ_PTR_NULL msg_queue is a null pointer
* @retval #K_ERR_NONE return successfully
*/
__API__ k_err_t tos_msg_queue_create(k_msg_queue_t *msg_queue);
/**
* @brief Destroy a message queue.
*
* @attention None
*
* @param[IN] msg_queue the pointer to the handler of the message queue.
*
* @return errcode.
* @retval #K_ERR_OBJ_PTR_NULL msg_queue is a null pointer
* @retval #K_ERR_OBJ_INVALID msg_queue is not a valid pointer to a message queue
* @retval #K_ERR_NONE return successfully
*/
__API__ k_err_t tos_msg_queue_destroy(k_msg_queue_t *msg_queue);
/**
* @brief Get a message.
* Get a message from the queue.
*
* @attention None
*
* @param[IN] msg_queue the pointer to the handler of the message queue.
* @param[OUT] msg_body the pointer to the body of the message.
* @param[OUT] msg_size the pointer to the size of the message.
*
* @return errcode.
* @retval #K_ERR_QUEUE_EMPTY the queue is empty.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_queue_get(k_msg_queue_t *msg_queue, void **msg_addr, size_t *msg_size);
/**
* @brief Put a message.
* Put a message to the queue.
*
* @attention None
*
* @param[IN] msg_queue the pointer to the handler of the message queue.
* @param[IN] msg_body the pointer to the body of the message.
* @param[IN] msg_size the pointer to the size of the message.
* @param[IN] opt option for the function call.
*
* @return errcode.
* @retval #K_ERR_QUEUE_FULL the queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_msg_queue_put(k_msg_queue_t *msg_queue, void *msg_addr, size_t msg_size, k_opt_t opt);
/**
* @brief Remove one message from the message queue.
* Remove one message with certain address from the message queue.
*
* @attention None
*
* @param[IN] msg_queue the pointer to the handler of the message queue.
* @param[IN] msg_addr the address of the message.
*
* @return errcode.
* @retval #K_ERR_MSG_QUEUE_MSG_NOT_EXIST message to remove is not existed
* @retval #K_ERR_NONE return successfully
*/
__API__ k_err_t tos_msg_queue_remove(k_msg_queue_t *msg_queue, void *msg_addr);
/**
* @brief Flush all of the messages.
* Flush all of the messages in the queue.
*
* @attention None
*
* @param[IN] msg_queue the pointer to the handler of the message queue.
*
* @return None.
*/
__API__ void tos_msg_queue_flush(k_msg_queue_t *msg_queue);
__KERNEL__ void msgpool_init(void);
#endif /* _TOS_MSG_H_ */

View File

@@ -37,13 +37,16 @@ typedef enum pend_state_en {
is initialized, or whether user pass the correct parameter.
*/
typedef enum pend_type_en {
PEND_TYPE_NONE = 0x0000,
PEND_TYPE_SEM = 0x1BEE,
PEND_TYPE_MUTEX = 0x2BEE,
PEND_TYPE_EVENT = 0x3BEE,
PEND_TYPE_QUEUE = 0x4BEE,
PEND_TYPE_COUNTDOWNLATCH = 0x5BEE,
PEND_TYPE_COMPLETION = 0x6BEE,
PEND_TYPE_NONE = 0x0000,
PEND_TYPE_SEM = 0x1BEE,
PEND_TYPE_MUTEX = 0x2BEE,
PEND_TYPE_EVENT = 0x3BEE,
PEND_TYPE_MAIL_QUEUE = 0x4BEE,
PEND_TYPE_MESSAGE_QUEUE = 0x5BEE,
PEND_TYPE_PRIORITY_MAIL_QUEUE = 0x6BEE,
PEND_TYPE_PRIORITY_MESSAGE_QUEUE = 0x7BEE,
PEND_TYPE_COUNTDOWNLATCH = 0x8BEE,
PEND_TYPE_COMPLETION = 0x9BEE,
} pend_type_t;
typedef enum opt_post_en {

View File

@@ -0,0 +1,133 @@
/*----------------------------------------------------------------------------
* 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 _TOS_PRIORITY_MAIL_QUEUE_H_
#define _TOS_PRIORITY_MAIL_QUEUE_H_
#if TOS_CFG_PRIORITY_MAIL_QUEUE_EN > 0u
typedef struct k_priority_mail_queue_st {
pend_obj_t pend_obj;
void *prio_q_mgr_array;
k_prio_q_t prio_q;
} k_prio_mail_q_t;
/**
* @brief Create a priority mail queue.
* create a priority mail queue.
*
* @attention a MAIL is a buffer with a certain size.
*
* @param[in] prio_mail_q pointer to the handler of the priority mail queue.
* @param[in] pool pool buffer of the priority mail queue.
* @param[in] mail_cnt mail count of the priority mail queue.
* @param[in] mail_size size of each mail in the priority mail queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_mail_q_create(k_prio_mail_q_t *prio_mail_q, void *pool, size_t mail_cnt, size_t mail_size);
/**
* @brief Destroy a priority mail queue.
* destroy a priority mail queue.
*
* @attention None
*
* @param[in] prio_mail_q pointer to the handler of the priority mail queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_mail_q_destroy(k_prio_mail_q_t *prio_mail_q);
/**
* @brief Flush the priority mail queue.
* flush the priority mail queue.
*
* @attention None
*
* @param[in] prio_mail_q pointer to the handler of the priority mail queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_mail_q_flush(k_prio_mail_q_t *prio_mail_q);
/**
* @brief Pend a priority mail queue.
* pend a priority mail queue.
*
* @attention
* 1. we WILL perform a memcpy when mail_buf is received(a MAIL is a buffer with a certain size).
* 2. With priority mail queue, if the poster has post several mail with different priority, the pender will receive
* the mail in priority order(numerically bigger, actually smaller, means the mail with highest priority(numerically
* smallest) will be received first, then the second highest priority mail, and so on).
*
* @param[in] prio_mail_q pointer to the handler of the priority mail queue.
* @param[OUT] mail_buf a pointer to the mail buffer we wanna receive.
* @param[OUT] mail_size size of the mail buffer received(should be consistent with the mail_size passed to tos_prio_mail_q_create).
* @param[in] timeout how much time(in k_tick_t) we would like to wait.
*
* @return errcode
* @retval #K_ERR_PEND_NOWAIT we get nothing, and we don't wanna wait.
* @retval #K_ERR_PEND_SCHED_LOCKED we can wait, but scheduler is locked.
* @retval #K_ERR_PEND_TIMEOUT the time we wait is up, we get nothing.
* @retval #K_ERR_PEND_DESTROY the queue we are pending is destroyed.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_mail_q_pend(k_prio_mail_q_t *prio_mail_q, void *mail_buf, size_t *mail_size, k_tick_t timeout);
/**
* @brief Post a priority mail queue.
* post a priority mail queue and wakeup one pending task.
*
* @attention when tos_prio_mail_q_post return successfully, only one task who are waitting for the mail queue will be woken up.
*
* @param[in] prio_mail_q pointer to the handler of the priority mail queue.
* @param[in] mail_buf the mail to post(a MAIL is a buffer).
* @param[in] mail_size the size of the mail to post(a MAIL is just a buffer).
* @param[in] prio the priority of the mail.
*
* @return errcode
* @retval #K_ERR_PRIO_Q_FULL the mail queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_mail_q_post(k_prio_mail_q_t *prio_mail_q, void *mail_buf, size_t mail_size, k_prio_t prio);
/**
* @brief Post a priority mail queue.
* post a priority mail queue and wakeup all the pending task.
*
* @attention when tos_prio_mail_q_post_all return successfully, all of the tasks who are waitting for the message queue will be woken up.
*
* @param[in] prio_mail_q pointer to the handler of the priority mail queue.
* @param[in] mail_buf the mail to post(a MAIL is a buffer).
* @param[in] mail_size the size of the mail to post(a MAIL is just a buffer).
* @param[in] prio the priority of the mail.
*
* @return errcode
* @retval #K_ERR_PRIO_Q_FULL the mail queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_mail_q_post_all(k_prio_mail_q_t *prio_mail_q, void *mail_buf, size_t mail_size, k_prio_t prio);
#endif
#endif /* TOS_CFG_PRIORITY_MAIL_QUEUE_EN */

View File

@@ -0,0 +1,129 @@
/*----------------------------------------------------------------------------
* 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 _TOS_PRIORITY_MESSAGE_QUEUE_H_
#define _TOS_PRIORITY_MESSAGE_QUEUE_H_
#if TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN > 0u
typedef struct k_priority_message_queue_st {
pend_obj_t pend_obj;
void *prio_q_mgr_array;
k_prio_q_t prio_q;
} k_prio_msg_q_t;
/**
* @brief Create a priority message queue.
* create a priority message queue.
*
* @attention a MESSAGE is a "void *" pointer.
*
* @param[in] prio_msg_q pointer to the handler of the priority message queue.
* @param[in] pool pool buffer of the priority message queue.
* @param[in] msg_cnt message count of the priority message queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_msg_q_create(k_prio_msg_q_t *prio_msg_q, void *pool, size_t msg_cnt);
/**
* @brief Destroy a priority message queue.
* destroy a priority message queue.
*
* @attention None
*
* @param[in] prio_msg_q pointer to the handler of the priority message queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_msg_q_destroy(k_prio_msg_q_t *prio_msg_q);
/**
* @brief Flush the priority message queue.
* flush the priority message queue.
*
* @attention None
*
* @param[in] prio_msg_q pointer to the handler of the priority message queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_msg_q_flush(k_prio_msg_q_t *prio_msg_q);
/**
* @brief Pend a priority message queue.
* pend a priority message queue.
*
* @attentio
* 1. we DONNOT perform a memcpy when msg_ptr is received(a MESSAGE is just a pointer).
* 2. With priority message queue, if the poster has post several message with different priority, the pender will receive
* the message in priority order(numerically bigger, actually smaller, means the message with highest priority(numerically
* smallest) will be received first, then the second highest priority message, and so on).
*
* @param[in] prio_msg_q pointer to the handler of the priority message queue.
* @param[OUT] msg_ptr a pointer to the message we wanna receive.
* @param[in] timeout how much time(in k_tick_t) we would like to wait.
*
* @return errcode
* @retval #K_ERR_PEND_NOWAIT we get nothing, and we don't wanna wait.
* @retval #K_ERR_PEND_SCHED_LOCKED we can wait, but scheduler is locked.
* @retval #K_ERR_PEND_TIMEOUT the time we wait is up, we get nothing.
* @retval #K_ERR_PEND_DESTROY the queue we are pending is destroyed.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_msg_q_pend(k_prio_msg_q_t *prio_msg_q, void **msg_ptr, k_tick_t timeout);
/**
* @brief Post a priority message queue.
* post a priority message queue and wakeup one pending task.
*
* @attention when tos_prio_msg_q_post return successfully, only one task who are waitting for the priority message queue will be woken up.
*
* @param[in] prio_msg_q pointer to the handler of the priority message queue.
* @param[in] msg_ptr the message to post(a MESSAGE is just a pointer).
* @param[in] prio the priority of the message.
*
* @return errcode
* @retval #K_ERR_PRIO_Q_FULL the priority message queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_msg_q_post(k_prio_msg_q_t *prio_msg_q, void *msg_ptr, k_prio_t prio);
/**
* @brief Post a priority message queue.
* post a priority message queue and wakeup all the pending task.
*
* @attention when tos_prio_msg_q_post_all return successfully, all of the tasks who are waitting for the priority message queue will be woken up.
*
* @param[in] prio_msg_q pointer to the handler of the priority message queue.
* @param[in] msg_ptr the priority message to post(a MESSAGE is just a pointer).
* @param[in] prio the priority of the message.
*
* @return errcode
* @retval #K_ERR_PRIO_Q_FULL the priority message queue is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_msg_q_post_all(k_prio_msg_q_t *prio_msg_q, void *msg_ptr, k_prio_t prio);
#endif
#endif /* _TOS_PRIORITY_MESSAGE_QUEUE_H_ */

View File

@@ -0,0 +1,178 @@
/*----------------------------------------------------------------------------
* 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 _TOS_PRIORITY_QUEUE_H_
#define _TOS_PRIORITY_QUEUE_H_
typedef uint16_t prio_q_slot_t;
typedef struct prio_q_pool_manager_entry_st {
prio_q_slot_t next;
} prio_q_pool_mgr_ent_t;
typedef struct prio_q_pool_manager_st {
prio_q_slot_t first_free;
prio_q_pool_mgr_ent_t *pool_mgr_ent_array;
} prio_q_pool_mgr_t;
typedef struct prio_q_priority_manager_entry_st {
k_prio_t priority;
prio_q_slot_t slot;
} prio_q_prio_mgr_ent_t;
typedef struct prio_q_prio_manager_st {
k_bin_heap_t prio_mgr_bin_heap;
prio_q_prio_mgr_ent_t *prio_mgr_ent_pool;
} prio_q_prio_mgr_t;
typedef struct k_priority_queue_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
prio_q_pool_mgr_t pool_mgr;
prio_q_prio_mgr_t prio_mgr;
size_t total;
size_t item_size;
size_t item_cnt;
uint8_t *pool;
} k_prio_q_t;
#define PRIO_Q_POOL_SLOT_INVALID ((prio_q_slot_t)-1)
#define PRIO_Q_POOL_MGR_ENT_ARRAY_SIZE(item_cnt) \
(item_cnt * sizeof(prio_q_pool_mgr_ent_t))
#define PRIO_Q_PRIO_MGR_ENT_POOL_SIZE(item_cnt) \
(item_cnt * sizeof(prio_q_prio_mgr_ent_t))
#define PRIO_Q_THE_ITEM(prio_q, slot) (void *)(&prio_q->pool[slot * prio_q->item_size])
// get the size of mgr_array to create a priority queue
#define TOS_PRIO_Q_MGR_ARRAY_SIZE(item_cnt) \
(PRIO_Q_POOL_MGR_ENT_ARRAY_SIZE(item_cnt) + PRIO_Q_PRIO_MGR_ENT_POOL_SIZE(item_cnt))
/**
* @brief Create a priority queue.
* create a priority queue.
*
* @attention if we wanna create a priority queue, we should offer a manager array buffer of which the size can be calculated by TOS_PRIO_Q_MGR_ARRAY_SIZE.
*
* @param[in] prio_q pointer to the handler of the priority queue.
* @param[in] mgr_array manager array buffer of the priority queue.
* @param[in] pool pool buffer of the priority queue.
* @param[in] item_cnt item count of the priority queue.
* @param[in] item_size size of each item of the priority queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_q_create(k_prio_q_t *prio_q, void *mgr_array, void *pool, size_t item_cnt, size_t item_size);
/**
* @brief Destroy a priority queue.
* destroy a priority queue.
*
* @attention None
*
* @param[in] prio_q pointer to the handler of the bpriority queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_q_destroy(k_prio_q_t *prio_q);
/**
* @brief Enqueue an priority queue.
* enqueue an item into the priority queue.
*
* @attention None
*
* @param[in] prio_q pointer to the handler of priority queue.
* @param[in] item the item to be enqueued.
* @param[in] item_size size of the item(should be consistent with the item_size passed to tos_prio_q_create).
* @param[in] prio priority of the item to be enqueued(should be consistent with the item_size passed to tos_prio_q_create).
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_PRIO_Q_ITEM_SIZE_NOT_MATCH the item_size is not consistent with the item_size passed to tos_prio_q_create.
* @retval #K_ERR_PRIO_Q_FULL the priority queue is full.
*/
__API__ k_err_t tos_prio_q_enqueue(k_prio_q_t *prio_q, void *item, size_t item_size, k_prio_t prio);
/**
* @brief Dequeue an item.
* dequeue an item from the priority queue.
*
* @attention None
*
* @param[in] prio_q pointer to the handler of the priority queue.
* @param[out] item buffer to hold the item dequeued.
* @param[out] item_size size of the item dequeued(should be consistent with the item_size passed to tos_prio_q_create).
* @param[out] prio priority of the item dequeued.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_PRIO_Q_EMPTY the priority queue is empty.
*/
__API__ k_err_t tos_prio_q_dequeue(k_prio_q_t *prio_q, void *item, size_t *item_size, k_prio_t *prio);
/**
* @brief Flush the priority queue.
* flush the priority queue.
*
* @attention None
*
* @param[in] prio_q pointer to the handler of the priority queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_prio_q_flush(k_prio_q_t *prio_q);
/**
* @brief Whether the priority queue is empty.
* Whether the priority queue is empty.
*
* @attention None
*
* @param[in] prio_q pointer to the handler of the priority queue.
*
* @return whether the priority queue is emtpy.
* @retval #0 the priority queue is not empty.
* @retval #Not 0 the priority queue is empty.
*/
__API__ int tos_prio_q_is_empty(k_prio_q_t *prio_q);
/**
* @brief Whether the priority queue is full.
* Whether the priority queue is full.
*
* @attention None
*
* @param[in] prio_q pointer to the handler of the priority queue.
*
* @return whether the priority queue is full.
* @retval #0 the priority queue is not full.
* @retval #Not 0 the priority queue is full.
*/
__API__ int tos_prio_q_is_full(k_prio_q_t *prio_q);
#endif /* _TOS_PRIORITY_QUEUE_H_ */

View File

@@ -1,134 +0,0 @@
/*----------------------------------------------------------------------------
* 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 _TOS_QUEUE_H_
#define _TOS_QUEUE_H_
#if TOS_CFG_QUEUE_EN > 0u
typedef struct k_queue_st {
pend_obj_t pend_obj;
k_msg_queue_t msg_queue;
} k_queue_t;
/**
* @brief Create a queue.
* create a queue.
*
* @attention None
*
* @param[in] queue pointer to the handler of the queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_queue_create(k_queue_t *queue);
/**
* @brief Destroy a queue.
* destroy a queue.
*
* @attention None
*
* @param[in] queue pointer to the handler of the queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_queue_destroy(k_queue_t *queue);
/**
* @brief Pend a queue.
* pend a queue.
*
* @attention we DONNOT perform a memcpy when msg_addr returned, we just let the *msg_addr point to an inner memory block.
* that means you DONNOT need to alloc memory for msg_addr, msg_addr can just be a pointer.
*
* @param[in] queue pointer to the handler of the queue.
* @param[out] msg_addr a pointer point to the message we wanna recive.
* @param[out] msg_size pointer to the message size returned.
* @param[in] timeout how much time(in k_tick_t) we would like to wait.
*
* @return errcode
* @retval #K_ERR_PEND_NOWAIT we get nothing, and we don't wanna wait.
* @retval #K_ERR_PEND_SCHED_LOCKED we can wait, but scheduler is locked.
* @retval #K_ERR_PEND_TIMEOUT the time we wait is up, we get nothing.
* @retval #K_ERR_PEND_DESTROY the queue we are pending is destroyed.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_queue_pend(k_queue_t *queue, void **msg_addr, size_t *msg_size, k_tick_t timeout);
/**
* @brief Post a queue.
* post a queue and wakeup one pending task.
*
* @attention when tos_queue_post return successfully, only one task who are waitting for the queue will be woken up.
*
* @param[in] queue pointer to the handler of the queue.
*
* @return errcode
* @retval #K_ERR_QUEUE_FULL the message pool is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_queue_post(k_queue_t *queue, void *msg_addr, size_t msg_size);
/**
* @brief Post a queue.
* post a queue and wakeup all the pending task.
*
* @attention when tos_queue_post_all return successfully, all of the tasks who are waitting for the queue will be woken up.
*
* @param[in] queue pointer to the handler of the queue.
*
* @return errcode
* @retval #K_ERR_QUEUE_FULL the message pool is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_queue_post_all(k_queue_t *queue, void *msg_addr, size_t msg_size);
/**
* @brief Flush a queue.
* flush a queue, clear all the msg in the queue.
*
* @attention None
*
* @param[in] queue pointer to the handler of the queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_queue_flush(k_queue_t *queue);
/**
* @brief Remove one message from the queue.
* Remove one message with certain address from the queue.
*
* @attention None
*
* @param[in] queue pointer to the handler of the queue.
* @param[in] msg_addr the address of the message.
*
* @return errcode
* @retval #K_ERR_QUEUE_MSG_NOT_EXIST message to remove is not existed.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_queue_remove(k_queue_t *queue, void *msg_addr);
#endif
#endif /* _TOS_QUEUE_H_ */

View File

@@ -0,0 +1,144 @@
/*----------------------------------------------------------------------------
* 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 _TOS_RING_QUEUE_H_
#define _TOS_RING_QUEUE_H_
typedef struct k_ring_queue_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
uint16_t head;
uint16_t tail;
size_t total;
uint8_t *pool;
size_t item_size;
size_t item_cnt;
} k_ring_q_t;
#define RING_HEAD_ITEM(ring_q) (uint8_t *)(&ring_q->pool[ring_q->head * ring_q->item_size])
#define RING_TAIL_ITEM(ring_q) (uint8_t *)(&ring_q->pool[ring_q->tail * ring_q->item_size])
#define RING_NEXT(ring_q, index) ((index + 1) % ring_q->item_cnt)
/**
* @brief Create a ring queue.
* create a ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
* @param[in] pool pool buffer of the ring queue.
* @param[in] item_cnt item count of the ring queue.
* @param[in] item_size size of each item of the ring queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_ring_q_create(k_ring_q_t *ring_q, void *pool, size_t item_cnt, size_t item_size);
/**
* @brief Destroy a ring queue.
* destroy a ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_ring_q_destroy(k_ring_q_t *ring_q);
/**
* @brief Enqueue an item.
* enqueue an item into the ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
* @param[in] item the item to be enqueued.
* @param[in] item_size size of the item(should be consistent with the item_size passed to tos_ring_q_create).
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RING_Q_ITEM_SIZE_NOT_MATCH the item_size is not consistent with the item_size passed to tos_ring_q_create.
* @retval #K_ERR_RING_Q_FULL the ring queue is full.
*/
__API__ k_err_t tos_ring_q_enqueue(k_ring_q_t *ring_q, void *item, size_t item_size);
/**
* @brief Dequeue an item.
* dequeue an item from the ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
* @param[out] item buffer to hold the item dequeued.
* @param[out] item_size size of the item dequeued(should be consistent with the item_size passed to tos_ring_q_create).
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RING_Q_EMPTY the ring queue is empty.
*/
__API__ k_err_t tos_ring_q_dequeue(k_ring_q_t *ring_q, void *item, size_t *item_size);
/**
* @brief Flush the ring queue.
* flush the ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_ring_q_flush(k_ring_q_t *ring_q);
/**
* @brief Whether the ring queue is empty.
* Whether the ring queue is empty.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return whether the ring queue is emtpy.
* @retval #0 the ring queue is not empty.
* @retval #Not 0 the ring queue is empty.
*/
__API__ int tos_ring_q_is_empty(k_ring_q_t *ring_q);
/**
* @brief Whether the ring queue is full.
* Whether the ring queue is full.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return whether the ring queue is full.
* @retval #0 the ring queue is not full.
* @retval #Not 0 the ring queue is full.
*/
__API__ int tos_ring_q_is_full(k_ring_q_t *ring_q);
#endif

View File

@@ -29,13 +29,16 @@ typedef enum knl_state_en {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
// some kind of magic number, mainly for identifing whether the object is initialized, or whether user pass the correct parameter.
typedef enum knl_obj_type_en {
KNL_OBJ_TYPE_NONE = 0x0000,
KNL_OBJ_TYPE_TASK = 0xDAD1,
KNL_OBJ_TYPE_TASK_DYN = 0xDAD2,
KNL_OBJ_TYPE_TIMER = 0xDAD3,
KNL_OBJ_TYPE_MSG_QUEUE = 0xDAD4,
KNL_OBJ_TYPE_MMBLK_POOL = 0xDAD5,
KNL_OBJ_TYPE_FIFO = 0xDAD6,
KNL_OBJ_TYPE_NONE = 0x0000,
KNL_OBJ_TYPE_TASK = 0xDAD1,
KNL_OBJ_TYPE_TASK_DYN = 0xDAD2,
KNL_OBJ_TYPE_TIMER = 0xDAD3,
KNL_OBJ_TYPE_MSG_QUEUE = 0xDAD4,
KNL_OBJ_TYPE_MMBLK_POOL = 0xDAD5,
KNL_OBJ_TYPE_RING_QUEUE = 0xDAD6,
KNL_OBJ_TYPE_BINARY_HEAP = 0xDAD7,
KNL_OBJ_TYPE_PRIORITY_QUEUE = 0xDAD8,
KNL_OBJ_TYPE_CHAR_FIFO = 0xDAD9,
} knl_obj_type_t;
typedef struct knl_object_st {

View File

@@ -112,9 +112,13 @@ typedef struct k_task_st {
k_timeslice_t timeslice; /**< how much time slice left for us? */
#endif
#if TOS_CFG_MSG_EN > 0u
void *msg_addr; /**< if we pend a queue successfully, our msg_addr and msg_size will be set by the queue poster */
size_t msg_size;
#if (TOS_CFG_MESSAGE_QUEUE_EN > 0u) || (TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN > 0u)
void *msg; /**< if we pend a message queue successfully, our msg will be set by the message queue poster */
#endif
#if (TOS_CFG_MAIL_QUEUE_EN > 0u) || (TOS_CFG_PRIORITY_MAIL_QUEUE_EN > 0u)
void *mail; /**< if we pend a mail queue successfully, our mail and mail_size will be set by the message queue poster */
size_t mail_size;
#endif
#if TOS_CFG_EVENT_EN > 0u