Merge remote-tracking branch 'TOS/master'
port to msp430fr
This commit is contained in:
@@ -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>
|
||||
|
180
kernel/core/include/tos_binary_heap.h
Normal file
180
kernel/core/include/tos_binary_heap.h
Normal file
@@ -0,0 +1,180 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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 {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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);
|
||||
|
||||
#if TOS_CFG_MMHEAP_EN > 0u
|
||||
|
||||
/**
|
||||
* @brief Create a binary heap with a dynamic allocated pool.
|
||||
* create a binary heap with a dynamic allocated pool.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] bin_heap pointer to the handler 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_dyn(k_bin_heap_t *bin_heap, size_t item_cnt, size_t item_size, k_bin_heap_cmp cmp);
|
||||
|
||||
/**
|
||||
* @brief Destroy a binary heap with a dynamic allocated pool.
|
||||
* destroy a binary heap with a dynamic allocated pool.
|
||||
*
|
||||
* @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_dyn(k_bin_heap_t *bin_heap);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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_ */
|
||||
|
191
kernel/core/include/tos_char_fifo.h
Normal file
191
kernel/core/include/tos_char_fifo.h
Normal file
@@ -0,0 +1,191 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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 {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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);
|
||||
|
||||
#if TOS_CFG_MMHEAP_EN > 0u
|
||||
|
||||
/**
|
||||
* @brief Create a character fifo with a dynamic allocated buffer.
|
||||
* Create a character fifo with a dynamic allocated buffer.
|
||||
*
|
||||
* @attention the buffer is dynamic allocated(tos_mmheap_alloc)
|
||||
*
|
||||
* @param[in] fifo pointer to the handler of the fifo.
|
||||
* @param[in] fifo_size size of the fifo.
|
||||
*
|
||||
* @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_dyn(k_chr_fifo_t *chr_fifo, size_t fifo_size);
|
||||
|
||||
/**
|
||||
* @brief Destroy a character fifo with a dynamic allocated buffer.
|
||||
* Destroy a character fifo with a dynamic allocated buffer.
|
||||
*
|
||||
* @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_dyn(k_chr_fifo_t *chr_fifo);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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_
|
||||
|
@@ -23,6 +23,10 @@
|
||||
typedef uint16_t completion_done_t;
|
||||
|
||||
typedef struct k_completion_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
pend_obj_t pend_obj;
|
||||
completion_done_t done;
|
||||
} k_completion_t;
|
||||
@@ -82,9 +86,7 @@ __API__ k_err_t tos_completion_pend_timed(k_completion_t *completion, k_tick_t t
|
||||
* @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 completion we are pending is destroyed.
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
|
@@ -40,8 +40,16 @@
|
||||
#error "INVALID config, TOS_CFG_TASK_PRIO_MAX must be >= 8"
|
||||
#endif
|
||||
|
||||
#if (TOS_CFG_QUEUE_EN > 0u) && (TOS_CFG_MSG_EN == 0u)
|
||||
#error "INVALID config, must enable tos_msg to use tos_queue"
|
||||
#if (TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u)
|
||||
#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to support dynamic task create"
|
||||
#endif
|
||||
|
||||
#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))
|
||||
@@ -55,7 +63,7 @@
|
||||
#endif
|
||||
|
||||
#if (TOS_CFG_VFS_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u)
|
||||
#error "INVALID config, must enable tos_mmheap to use tos_vfs"
|
||||
#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to use tos_vfs"
|
||||
#endif
|
||||
|
||||
#ifndef TOS_CFG_CPU_HRTIMER_EN
|
||||
|
@@ -33,6 +33,15 @@
|
||||
/////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
// disable dynamic task create
|
||||
#ifdef TOS_CFG_TASK_DYNAMIC_CREATE_EN
|
||||
#undef TOS_CFG_TASK_DYNAMIC_CREATE_EN
|
||||
#endif
|
||||
#define TOS_CFG_TASK_DYNAMIC_CREATE_EN 0u
|
||||
/////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
// disable event
|
||||
#ifdef TOS_CFG_EVENT_EN
|
||||
@@ -51,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
|
||||
@@ -167,7 +167,11 @@
|
||||
#else /* TOS_CFG_EVENT_DRIVEN_EN */
|
||||
|
||||
#ifndef TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN
|
||||
#define TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN 0u
|
||||
#define TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN 0u
|
||||
#endif
|
||||
|
||||
#ifndef TOS_CFG_TASK_DYNAMIC_CREATE_EN
|
||||
#define TOS_CFG_TASK_DYNAMIC_CREATE_EN 0u
|
||||
#endif
|
||||
|
||||
#ifndef TOS_CFG_ROUND_ROBIN_EN
|
||||
@@ -182,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
|
||||
@@ -198,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
|
||||
@@ -212,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
|
||||
@@ -275,6 +281,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u)
|
||||
#if TOS_CFG_IDLE_TASK_STK_SIZE < 512
|
||||
#undef TOS_CFG_IDLE_TASK_STK_SIZE
|
||||
#define TOS_CFG_IDLE_TASK_STK_SIZE 512u
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef TOS_CFG_FAULT_BACKTRACE_EN
|
||||
#define TOS_CFG_FAULT_BACKTRACE_EN 0u
|
||||
#endif
|
||||
|
@@ -21,6 +21,10 @@
|
||||
#if TOS_CFG_COUNTDOWNLATCH_EN > 0u
|
||||
|
||||
typedef struct k_countdownlatch_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
pend_obj_t pend_obj;
|
||||
k_countdownlatch_cnt_t count;
|
||||
} k_countdownlatch_t;
|
||||
|
@@ -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,26 +52,17 @@ 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,
|
||||
|
||||
K_ERR_OBJ_PTR_NULL = 1100u,
|
||||
K_ERR_OBJ_INVALID,
|
||||
K_ERR_OBJ_INVALID_ALLOC_TYPE,
|
||||
|
||||
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 +70,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,
|
||||
|
||||
@@ -91,6 +96,7 @@ typedef enum k_err_en {
|
||||
K_ERR_TASK_SUSPEND_IDLE,
|
||||
K_ERR_TASK_STK_OVERFLOW,
|
||||
K_ERR_TASK_STK_SIZE_INVALID,
|
||||
K_ERR_TASK_OUT_OF_MEMORY,
|
||||
|
||||
K_ERR_TICKLESS_WKUP_ALARM_NOT_INSTALLED = 2000u,
|
||||
K_ERR_TICKLESS_WKUP_ALARM_NO_INIT,
|
||||
|
@@ -20,10 +20,10 @@
|
||||
|
||||
#if TOS_CFG_EVENT_EN > 0
|
||||
|
||||
// if we are pending an event, for any flag we expect is set is ok, this flag should be passed to tos_event_pend
|
||||
// if we are pending an event, for any flag we expect is set is ok, this flag should be passed to tos_event_pend
|
||||
#define TOS_OPT_EVENT_PEND_ANY (k_opt_t)0x0001
|
||||
|
||||
// if we are pending an event, must all the flag we expect is set is ok, this flag should be passed to tos_event_pend
|
||||
// if we are pending an event, must all the flag we expect is set is ok, this flag should be passed to tos_event_pend
|
||||
#define TOS_OPT_EVENT_PEND_ALL (k_opt_t)0x0002
|
||||
|
||||
// if we are pending an event, and we wanna clear the event's flag after we read, this flag should be passed to tos_event_pend
|
||||
@@ -41,6 +41,10 @@ typedef enum opt_event_post_en {
|
||||
} opt_event_post_t;
|
||||
|
||||
typedef struct k_event_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
pend_obj_t pend_obj;
|
||||
k_event_flag_t flag;
|
||||
} k_event_t;
|
||||
@@ -128,6 +132,6 @@ __API__ k_err_t tos_event_post(k_event_t *event, k_event_flag_t flag);
|
||||
__API__ k_err_t tos_event_post_keep(k_event_t *event, k_event_flag_t flag);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _TOS_EVENT_H_ */
|
||||
|
||||
|
@@ -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_
|
||||
|
@@ -44,7 +44,15 @@ extern k_stack_t k_idle_task_stk[];
|
||||
extern k_stack_t *const k_idle_task_stk_addr;
|
||||
extern size_t const k_idle_task_stk_size;
|
||||
|
||||
/* list to hold all the task delayed or pend for timeout */
|
||||
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u
|
||||
/* list to hold all the destroyed dynamic created tasks */
|
||||
extern k_list_t k_dead_task_list;
|
||||
#endif
|
||||
|
||||
/* list to hold all the tasks for statistics */
|
||||
extern k_list_t k_stat_list;
|
||||
|
||||
/* list to hold all the tasks delayed or pend for timeout */
|
||||
extern k_list_t k_tick_list;
|
||||
|
||||
/* how many ticks will be triggered in a second */
|
||||
@@ -82,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;
|
||||
|
||||
|
@@ -21,7 +21,6 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TOS_OFFSET_OF_FIELD(type, field) \
|
||||
@@ -37,6 +36,13 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define TOS_PTR_SANITY_CHECK_RC(ptr, return_code) \
|
||||
do { \
|
||||
if (unlikely((ptr) == K_NULL)) { \
|
||||
return return_code; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define TOS_IN_IRQ_CHECK() \
|
||||
do { \
|
||||
if (unlikely(knl_is_inirq())) { \
|
||||
@@ -44,6 +50,26 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
#define TOS_OBJ_VERIFY(obj, obj_type) \
|
||||
do { \
|
||||
if (!knl_object_verify(&obj->knl_obj, obj_type)) { \
|
||||
return K_ERR_OBJ_INVALID; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TOS_OBJ_VERIFY_RC(obj, obj_type, return_code) \
|
||||
do { \
|
||||
if (!knl_object_verify(&obj->knl_obj, obj_type)) { \
|
||||
return return_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
#define TOS_OBJ_VERIFY(obj, obj_type)
|
||||
#define TOS_OBJ_VERIFY_RC(obj, obj_type, return_code)
|
||||
#endif
|
||||
|
||||
// currently we use default microlib supplied by mdk
|
||||
#define tos_kprintf(...) printf(__VA_ARGS__);
|
||||
|
||||
@@ -51,5 +77,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_ */
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#define _TOS_KTYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef uint8_t k_prio_t;
|
||||
typedef uint8_t k_stack_t;
|
||||
|
159
kernel/core/include/tos_mail_queue.h
Normal file
159
kernel/core/include/tos_mail_queue.h
Normal 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_MAIL_QUEUE_H_
|
||||
#define _TOS_MAIL_QUEUE_H_
|
||||
|
||||
#if TOS_CFG_MAIL_QUEUE_EN > 0u
|
||||
|
||||
typedef struct k_mail_queue_st {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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);
|
||||
|
||||
#if TOS_CFG_MMHEAP_EN > 0u
|
||||
|
||||
/**
|
||||
* @brief Create a mail queue with dynamic allocated pool.
|
||||
* create a mail queue with dynamic allocated pool.
|
||||
*
|
||||
* @attention a MAIL is a buffer with a certain size.
|
||||
*
|
||||
* @param[in] mail_q pointer to the handler 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_dyn(k_mail_q_t *mail_q, size_t mail_cnt, size_t mail_size);
|
||||
|
||||
/**
|
||||
* @brief Destroy a mail queue with dynamic allocated pool.
|
||||
* destroy a mail queue with dynamic allocated pool.
|
||||
*
|
||||
* @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_dyn(k_mail_q_t *mail_q);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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_ */
|
||||
|
154
kernel/core/include/tos_message_queue.h
Normal file
154
kernel/core/include/tos_message_queue.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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 {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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);
|
||||
|
||||
#if TOS_CFG_MMHEAP_EN > 0u
|
||||
|
||||
/**
|
||||
* @brief Create a message queue with dynamic allocated pool.
|
||||
* create a message queue with dynamic allocated pool.
|
||||
*
|
||||
* @attention a MESSAGE is a "void *" pointer.
|
||||
*
|
||||
* @param[in] msg_q pointer to the handler 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_dyn(k_msg_q_t *msg_q, size_t msg_cnt);
|
||||
|
||||
/**
|
||||
* @brief Destroy a message queue with dynamic allocated pool.
|
||||
* destroy a message queue with dynamic allocated pool.
|
||||
*
|
||||
* @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_dyn(k_msg_q_t *msg_q);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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_ */
|
||||
|
@@ -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_ */
|
||||
|
@@ -21,6 +21,10 @@
|
||||
#if TOS_CFG_MUTEX_EN > 0u
|
||||
|
||||
typedef struct k_mutex_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
pend_obj_t pend_obj;
|
||||
k_nesting_t pend_nesting;
|
||||
k_task_t *owner;
|
||||
|
@@ -32,36 +32,19 @@ typedef enum pend_state_en {
|
||||
PEND_STATE_OWNER_DIE, /**< the pend object owner task is destroyed. */
|
||||
} pend_state_t;
|
||||
|
||||
// what we are pending
|
||||
/* actually, it's some kind of magic number, mainly for identifing whether the pend
|
||||
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_t;
|
||||
|
||||
typedef enum opt_post_en {
|
||||
OPT_POST_ONE,
|
||||
OPT_POST_ALL,
|
||||
} opt_post_t;
|
||||
|
||||
typedef struct pend_object_st {
|
||||
pend_type_t type;
|
||||
k_list_t list;
|
||||
} pend_obj_t;
|
||||
|
||||
__KERNEL__ void pend_object_init(pend_obj_t *object, pend_type_t type);
|
||||
__KERNEL__ void pend_object_init(pend_obj_t *object);
|
||||
|
||||
__KERNEL__ void pend_object_deinit(pend_obj_t *object);
|
||||
|
||||
__KERNEL__ int pend_object_verify(pend_obj_t *object, pend_type_t type);
|
||||
|
||||
__KERNEL__ int pend_is_nopending(pend_obj_t *object);
|
||||
|
||||
__KERNEL__ k_prio_t pend_highest_pending_prio_get(pend_obj_t *object);
|
||||
|
164
kernel/core/include/tos_priority_mail_queue.h
Normal file
164
kernel/core/include/tos_priority_mail_queue.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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 {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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 Create a priority mail queue with dynamic allocated pool.
|
||||
* create a priority mail queue with dynamic allocated pool.
|
||||
*
|
||||
* @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_dyn(k_prio_mail_q_t *prio_mail_q, size_t mail_cnt, size_t mail_size);
|
||||
|
||||
/**
|
||||
* @brief Destroy a priority mail queue with dynamic allocated pool.
|
||||
* destroy a priority mail queue with dynamic allocated pool.
|
||||
*
|
||||
* @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_dyn(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 */
|
||||
|
159
kernel/core/include/tos_priority_message_queue.h
Normal file
159
kernel/core/include/tos_priority_message_queue.h
Normal 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_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 {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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 Create a priority message queue with dynamic allocated pool.
|
||||
* create a priority message queue with dynamic allocated pool.
|
||||
*
|
||||
* @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_dyn(k_prio_msg_q_t *prio_msg_q, size_t msg_cnt);
|
||||
|
||||
/**
|
||||
* @brief Destroy a priority message queue with dynamic allocated pool.
|
||||
* destroy a priority message queue with dynamic allocated pool.
|
||||
*
|
||||
* @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_dyn(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_ */
|
||||
|
211
kernel/core/include/tos_priority_queue.h
Normal file
211
kernel/core/include/tos_priority_queue.h
Normal file
@@ -0,0 +1,211 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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 {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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 *mgr_pool;
|
||||
uint8_t *data_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->data_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);
|
||||
|
||||
#if TOS_CFG_MMHEAP_EN > 0u
|
||||
|
||||
/**
|
||||
* @brief Create a priority queue with dynamic allocated mgr array and data pool.
|
||||
* create a priority queue with dynamic allocated mgr array and data pool.
|
||||
*
|
||||
* @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_dyn(k_prio_q_t *prio_q, size_t item_cnt, size_t item_size);
|
||||
|
||||
/**
|
||||
* @brief Destroy a priority queue with dynamic allocated mgr array and data pool.
|
||||
* destroy a priority queue with dynamic allocated mgr array and data pool.
|
||||
*
|
||||
* @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_dyn(k_prio_q_t *prio_q);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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_ */
|
||||
|
@@ -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_ */
|
||||
|
178
kernel/core/include/tos_ring_queue.h
Normal file
178
kernel/core/include/tos_ring_queue.h
Normal 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_RING_QUEUE_H_
|
||||
#define _TOS_RING_QUEUE_H_
|
||||
|
||||
typedef struct k_ring_queue_st {
|
||||
knl_obj_t knl_obj;
|
||||
|
||||
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.
|
||||
* @retval #K_ERR_OBJ_INVALID_ALLOC_TYPE invalid alloc type(is dynamic allocated not static)
|
||||
*/
|
||||
__API__ k_err_t tos_ring_q_destroy(k_ring_q_t *ring_q);
|
||||
|
||||
#if TOS_CFG_MMHEAP_EN > 0u
|
||||
|
||||
/**
|
||||
* @brief Create a ring queue with dynamic allocated pool.
|
||||
* create a ring queue with dynamic allocated pool.
|
||||
*
|
||||
* @attention pool inside is dynamic allocated.
|
||||
*
|
||||
* @param[in] ring_q pointer to the handler 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.
|
||||
* @retval #K_ERR_OUT_OF_MEMORY out of memory
|
||||
*/
|
||||
__API__ k_err_t tos_ring_q_create_dyn(k_ring_q_t *ring_q, size_t item_cnt, size_t item_size);
|
||||
|
||||
/**
|
||||
* @brief Destroy a ring queue with a dynamic allocated pool.
|
||||
* destroy a ring queue with a dynamic allocated pool.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] ring_q pointer to the handler of the ring queue.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
* @retval #K_ERR_OBJ_INVALID_ALLOC_TYPE invalid alloc type(is static allocated not dynamic)
|
||||
*/
|
||||
__API__ k_err_t tos_ring_q_destroy_dyn(k_ring_q_t *ring_q);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
@@ -21,10 +21,30 @@
|
||||
#if TOS_CFG_SEM_EN > 0u
|
||||
|
||||
typedef struct k_sem_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
pend_obj_t pend_obj;
|
||||
k_sem_cnt_t count;
|
||||
k_sem_cnt_t count_max;
|
||||
} k_sem_t;
|
||||
|
||||
/**
|
||||
* @brief Create a semaphore with a limitation of maximum count.
|
||||
* create a semaphore with a limitation of maximum count.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] sem pointer to the handler of the semaphore.
|
||||
* @param[in] init_count initial count of the semaphore.
|
||||
* @param[in] max_count maximum count of the semaphore.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_sem_create_max(k_sem_t *sem, k_sem_cnt_t init_count, k_sem_cnt_t max_count);
|
||||
|
||||
/**
|
||||
* @brief Create a semaphore.
|
||||
* create a semaphore.
|
||||
@@ -32,6 +52,7 @@ typedef struct k_sem_st {
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] sem pointer to the handler of the semaphore.
|
||||
* @param[in] init_count initial count of the semaphore.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
|
@@ -26,21 +26,42 @@ typedef enum knl_state_en {
|
||||
KNL_STATE_RUNNING,
|
||||
} knl_state_t;
|
||||
|
||||
#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_TIMER = 0xDAD2,
|
||||
KNL_OBJ_TYPE_MSG_QUEUE = 0xDAD4,
|
||||
KNL_OBJ_TYPE_MMBLK_POOL = 0xDAD8,
|
||||
KNL_OBJ_TYPE_FIFO = 0xDAE1,
|
||||
KNL_OBJ_TYPE_NONE = 0x0000,
|
||||
KNL_OBJ_TYPE_TASK = 0xDAD1,
|
||||
KNL_OBJ_TYPE_TIMER = 0xDAD2,
|
||||
KNL_OBJ_TYPE_MSG_QUEUE = 0xDAD3,
|
||||
KNL_OBJ_TYPE_MMBLK_POOL = 0xDAD4,
|
||||
KNL_OBJ_TYPE_RING_QUEUE = 0xDAD5,
|
||||
KNL_OBJ_TYPE_BINARY_HEAP = 0xDAD6,
|
||||
KNL_OBJ_TYPE_PRIORITY_QUEUE = 0xDAD7,
|
||||
KNL_OBJ_TYPE_CHAR_FIFO = 0xDAD8,
|
||||
|
||||
// ipc object
|
||||
KNL_OBJ_TYPE_SEMAPHORE = 0x1BEE,
|
||||
KNL_OBJ_TYPE_MUTEX = 0x2BEE,
|
||||
KNL_OBJ_TYPE_EVENT = 0x3BEE,
|
||||
KNL_OBJ_TYPE_MAIL_QUEUE = 0x4BEE,
|
||||
KNL_OBJ_TYPE_MESSAGE_QUEUE = 0x5BEE,
|
||||
KNL_OBJ_TYPE_PRIORITY_MAIL_QUEUE = 0x6BEE,
|
||||
KNL_OBJ_TYPE_PRIORITY_MESSAGE_QUEUE = 0x7BEE,
|
||||
KNL_OBJ_TYPE_COUNTDOWNLATCH = 0x8BEE,
|
||||
KNL_OBJ_TYPE_COMPLETION = 0x9BEE,
|
||||
} knl_obj_type_t;
|
||||
|
||||
typedef enum knl_obj_alloc_type_en {
|
||||
KNL_OBJ_ALLOC_TYPE_NONE,
|
||||
KNL_OBJ_ALLOC_TYPE_STATIC,
|
||||
KNL_OBJ_ALLOC_TYPE_DYNAMIC,
|
||||
} knl_obj_alloc_type_t;
|
||||
|
||||
typedef struct knl_object_st {
|
||||
knl_obj_type_t type;
|
||||
} knl_obj_t;
|
||||
knl_obj_alloc_type_t alloc_type; /* is dynamic allocated(using tos_mmheap) or static memory? */
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_type_t type;
|
||||
#endif
|
||||
} knl_obj_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the kernel.
|
||||
@@ -145,9 +166,17 @@ __KERNEL__ k_tick_t knl_next_expires_get(void);
|
||||
__KERNEL__ void knl_sched(void);
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
__KERNEL__ int knl_object_verify(knl_obj_t *object, knl_obj_type_t type);
|
||||
__KERNEL__ int knl_object_init(knl_obj_t *object, knl_obj_type_t type);
|
||||
__KERNEL__ int knl_object_deinit(knl_obj_t *object);
|
||||
__KERNEL__ int knl_object_verify(knl_obj_t *knl_obj, knl_obj_type_t type);
|
||||
__KERNEL__ void knl_object_init(knl_obj_t *knl_obj, knl_obj_type_t type);
|
||||
__KERNEL__ void knl_object_deinit(knl_obj_t *knl_obj);
|
||||
#endif
|
||||
|
||||
#if TOS_CFG_MMHEAP_EN > 0u
|
||||
__KERNEL__ void knl_object_alloc_reset(knl_obj_t *knl_obj);
|
||||
__KERNEL__ void knl_object_alloc_set_dynamic(knl_obj_t *knl_obj);
|
||||
__KERNEL__ void knl_object_alloc_set_static(knl_obj_t *knl_obj);
|
||||
__KERNEL__ int knl_object_alloc_is_dynamic(knl_obj_t *knl_obj);
|
||||
__KERNEL__ int knl_object_alloc_is_static(knl_obj_t *knl_obj);
|
||||
#endif
|
||||
|
||||
__KERNEL__ int knl_is_sched_locked(void);
|
||||
|
@@ -61,15 +61,15 @@
|
||||
|
||||
typedef void (*k_task_entry_t)(void *arg);
|
||||
|
||||
typedef void (*k_task_walker)(k_task_t *task);
|
||||
|
||||
/**
|
||||
* task control block
|
||||
*/
|
||||
typedef struct k_task_st {
|
||||
k_stack_t *sp; /**< task stack pointer. This lady always comes first, we count on her in port_s.S for context switch. */
|
||||
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj; /**< just for verification, test whether current object is really a task. */
|
||||
#endif
|
||||
|
||||
char *name; /**< task name */
|
||||
k_task_entry_t entry; /**< task entry */
|
||||
@@ -80,6 +80,12 @@ typedef struct k_task_st {
|
||||
k_stack_t *stk_base; /**< task stack base address */
|
||||
size_t stk_size; /**< stack size of the task */
|
||||
|
||||
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u
|
||||
k_list_t dead_list; /**< when a dynamic allocated task destroyed, we hook the task's dead_list to the k_dead_task_list */
|
||||
#endif
|
||||
|
||||
k_list_t stat_list; /**< list for hooking us to the k_stat_list */
|
||||
|
||||
k_tick_t tick_expires; /**< if we are in k_tick_list, how much time will we wait for? */
|
||||
|
||||
k_list_t tick_list; /**< list for hooking us to the k_tick_list */
|
||||
@@ -104,9 +110,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
|
||||
@@ -131,7 +141,6 @@ typedef struct k_task_st {
|
||||
* @param[in] stk_base stack base address of the task.
|
||||
* @param[in] stk_size stack size of the task.
|
||||
* @param[in] timeslice time slice of the task.
|
||||
* @param[in] opt option for the function call.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_TASK_STK_SIZE_INVALID stack size is invalid.
|
||||
@@ -161,6 +170,51 @@ __API__ k_err_t tos_task_create(k_task_t *task,
|
||||
*/
|
||||
__API__ k_err_t tos_task_destroy(k_task_t *task);
|
||||
|
||||
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u
|
||||
|
||||
/**
|
||||
* @brief Create a task with a dynamic allocated task handler and stack.
|
||||
* create a task with a dynamic allocated task handler and stack.
|
||||
*
|
||||
* @attention a task created by tos_task_create_dyn, should be destroyed by tos_task_destroy_dyn.
|
||||
* @param[out] task dynamic allocated task handler.
|
||||
* @param[in] name name of the task.
|
||||
* @param[in] entry running entry of the task.
|
||||
* @param[in] arg argument for the entry of the task.
|
||||
* @param[in] prio priority of the task.
|
||||
* @param[in] stk_size stack size of the task.
|
||||
* @param[in] timeslice time slice of the task.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_TASK_STK_SIZE_INVALID stack size is invalid.
|
||||
* @retval #K_ERR_TASK_PRIO_INVALID priority is invalid.
|
||||
* @retval #K_ERR_TASK_OUT_OF_MEMORY out of memory(insufficient heap memory).
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_task_create_dyn(k_task_t **task,
|
||||
char *name,
|
||||
k_task_entry_t entry,
|
||||
void *arg,
|
||||
k_prio_t prio,
|
||||
size_t stk_size,
|
||||
k_timeslice_t timeslice);
|
||||
|
||||
/**
|
||||
* @brief Destroy a dynamic created task.
|
||||
* delete a dynamic created task.
|
||||
*
|
||||
* @attention the API to destroy a dynamic created task.
|
||||
*
|
||||
* @param[in] task pointer to the handler of the task to be deleted.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_TASK_DESTROY_IDLE attempt to destroy idle task.
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_task_destroy_dyn(k_task_t *task);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Delay current task for ticks.
|
||||
* Delay for a specified amount of ticks.
|
||||
@@ -245,6 +299,18 @@ __API__ k_err_t tos_task_prio_change(k_task_t *task, k_prio_t prio_new);
|
||||
*/
|
||||
__API__ void tos_task_yield(void);
|
||||
|
||||
/**
|
||||
* @brief Get current running task.
|
||||
* Get current running task.
|
||||
*
|
||||
* @attention is kernel is not running, you'll get K_NULL
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return current running task handler
|
||||
*/
|
||||
__API__ k_task_t *tos_task_curr_task_get(void);
|
||||
|
||||
|
||||
#if TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN > 0u
|
||||
|
||||
@@ -264,6 +330,30 @@ __API__ k_err_t tos_task_stack_draught_depth(k_task_t *task, int *depth);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Walk through all the tasks in the statistic list.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] walker a function involved when meeting each tasks in the list.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
__API__ void tos_task_walkthru(k_task_walker walker);
|
||||
|
||||
/**
|
||||
* @brief A debug API for display all tasks information.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
__DEBUG__ void tos_task_info_display(void);
|
||||
|
||||
__KERNEL__ void task_free_all(void);
|
||||
|
||||
__KERNEL__ __STATIC_INLINE__ int task_state_is_ready(k_task_t *task)
|
||||
{
|
||||
return task->state == K_TASK_STATE_READY;
|
||||
@@ -324,5 +414,36 @@ __KERNEL__ __STATIC_INLINE__ void task_state_set_sleeping(k_task_t *task)
|
||||
task->state |= K_TASK_STATE_SLEEP;
|
||||
}
|
||||
|
||||
__DEBUG__ __STATIC_INLINE__ void task_default_walker(k_task_t *task)
|
||||
{
|
||||
char *state_str;
|
||||
|
||||
tos_kprintln("tsk name: %s", task->name);
|
||||
|
||||
if (task->state == K_TASK_STATE_PENDTIMEOUT_SUSPENDED) {
|
||||
state_str = "PENDTIMEOUT_SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_PEND_SUSPENDED) {
|
||||
state_str = "PEND_SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_SLEEP_SUSPENDED) {
|
||||
state_str = "SLEEP_SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_PENDTIMEOUT) {
|
||||
state_str = "PENDTIMEOUT";
|
||||
} else if (task->state == K_TASK_STATE_SUSPENDED) {
|
||||
state_str = "SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_PEND) {
|
||||
state_str = "PEND";
|
||||
} else if (task->state == K_TASK_STATE_SLEEP) {
|
||||
state_str = "SLEEP";
|
||||
} else if (task->state == K_TASK_STATE_READY) {
|
||||
state_str = "READY";
|
||||
}
|
||||
tos_kprintln("tsk stat: %s", state_str);
|
||||
|
||||
tos_kprintln("stk size: %d", task->stk_size);
|
||||
tos_kprintln("stk base: 0x%p", task->stk_base);
|
||||
tos_kprintln("stk top : 0x%p", task->stk_base + task->stk_size);
|
||||
tos_kprintf("\n");
|
||||
}
|
||||
|
||||
#endif /* _TOS_TASK_H_ */
|
||||
|
||||
|
@@ -48,9 +48,7 @@ typedef void (*k_timer_callback_t)(void *arg);
|
||||
* timer control block
|
||||
*/
|
||||
typedef struct k_timer_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj; /**< just for verification, test whether current object is really a timer */
|
||||
#endif
|
||||
|
||||
k_timer_callback_t cb; /**< callback when time is up */
|
||||
void *cb_arg; /**< argument for callback */
|
||||
|
Reference in New Issue
Block a user