add a set of dyn(create / destroy) interface
1. tos_ring_q_create_dyn 2. tos_chr_fifo_create_dyn 3. tos_msg_q_create_dyn 4. tos_mail_q_create_dyn 5. tos_bin_heap_create_dyn 6. tos_prio_q_create_dyn 7. tos_prio_msg_q_create_dyn 8. tos_prio_mail_q_create_dyn
This commit is contained in:
@@ -21,9 +21,7 @@
|
||||
typedef int (*k_bin_heap_cmp)(void *first, void *second);
|
||||
|
||||
typedef struct k_binary_heap_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
size_t total;
|
||||
|
||||
@@ -71,6 +69,39 @@ __API__ k_err_t tos_bin_heap_create(k_bin_heap_t *bin_heap, void *pool, size_t i
|
||||
*/
|
||||
__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.
|
||||
|
@@ -19,9 +19,7 @@
|
||||
#define _TOS_CHAR_FIFO_H_
|
||||
|
||||
typedef struct k_char_fifo_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
k_ring_q_t ring_q;
|
||||
} k_chr_fifo_t;
|
||||
@@ -57,6 +55,40 @@ __API__ k_err_t tos_chr_fifo_create(k_chr_fifo_t *chr_fifo, void *buffer, size_t
|
||||
*/
|
||||
__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.
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -58,6 +58,7 @@ typedef enum k_err_en {
|
||||
|
||||
K_ERR_OBJ_PTR_NULL = 1100u,
|
||||
K_ERR_OBJ_INVALID,
|
||||
K_ERR_OBJ_INVALID_ALLOC_TYPE,
|
||||
|
||||
K_ERR_OUT_OF_MEMORY = 1150u,
|
||||
|
||||
|
@@ -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_ */
|
||||
|
||||
|
@@ -37,6 +37,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 +51,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__);
|
||||
|
||||
|
@@ -21,6 +21,8 @@
|
||||
#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;
|
||||
@@ -54,6 +56,38 @@ __API__ k_err_t tos_mail_q_create(k_mail_q_t *mail_q, void *pool, size_t mail_cn
|
||||
*/
|
||||
__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.
|
||||
|
@@ -21,6 +21,8 @@
|
||||
#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;
|
||||
@@ -53,6 +55,37 @@ __API__ k_err_t tos_msg_q_create(k_msg_q_t *msg_q, void *pool, size_t msg_cnt);
|
||||
*/
|
||||
__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.
|
||||
|
@@ -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,39 +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_MAIL_QUEUE = 0x4BEE,
|
||||
PEND_TYPE_MESSAGE_QUEUE = 0x5BEE,
|
||||
PEND_TYPE_PRIORITY_MAIL_QUEUE = 0x6BEE,
|
||||
PEND_TYPE_PRIORITY_MESSAGE_QUEUE = 0x7BEE,
|
||||
PEND_TYPE_COUNTDOWNLATCH = 0x8BEE,
|
||||
PEND_TYPE_COMPLETION = 0x9BEE,
|
||||
} pend_type_t;
|
||||
|
||||
typedef enum opt_post_en {
|
||||
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);
|
||||
|
@@ -21,6 +21,8 @@
|
||||
#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;
|
||||
@@ -56,6 +58,35 @@ __API__ k_err_t tos_prio_mail_q_create(k_prio_mail_q_t *prio_mail_q, void *pool,
|
||||
*/
|
||||
__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.
|
||||
|
@@ -21,6 +21,8 @@
|
||||
#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;
|
||||
@@ -55,6 +57,34 @@ __API__ k_err_t tos_prio_msg_q_create(k_prio_msg_q_t *prio_msg_q, void *pool, si
|
||||
*/
|
||||
__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.
|
||||
|
@@ -40,9 +40,7 @@ typedef struct prio_q_prio_manager_st {
|
||||
} prio_q_prio_mgr_t;
|
||||
|
||||
typedef struct k_priority_queue_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
prio_q_pool_mgr_t pool_mgr;
|
||||
prio_q_prio_mgr_t prio_mgr;
|
||||
@@ -51,7 +49,8 @@ typedef struct k_priority_queue_st {
|
||||
size_t item_size;
|
||||
size_t item_cnt;
|
||||
|
||||
uint8_t *pool;
|
||||
uint8_t *mgr_pool;
|
||||
uint8_t *data_pool;
|
||||
} k_prio_q_t;
|
||||
|
||||
#define PRIO_Q_POOL_SLOT_INVALID ((prio_q_slot_t)-1)
|
||||
@@ -62,7 +61,7 @@ typedef struct k_priority_queue_st {
|
||||
#define PRIO_Q_PRIO_MGR_ENT_POOL_SIZE(item_cnt) \
|
||||
(item_cnt * sizeof(prio_q_prio_mgr_ent_t))
|
||||
|
||||
#define PRIO_Q_THE_ITEM(prio_q, slot) (void *)(&prio_q->pool[slot * prio_q->item_size])
|
||||
#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) \
|
||||
@@ -98,6 +97,40 @@ __API__ k_err_t tos_prio_q_create(k_prio_q_t *prio_q, void *mgr_array, void *poo
|
||||
*/
|
||||
__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.
|
||||
|
@@ -19,9 +19,7 @@
|
||||
#define _TOS_RING_QUEUE_H_
|
||||
|
||||
typedef struct k_ring_queue_st {
|
||||
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
|
||||
knl_obj_t knl_obj;
|
||||
#endif
|
||||
|
||||
uint16_t head;
|
||||
uint16_t tail;
|
||||
@@ -62,10 +60,46 @@ __API__ k_err_t tos_ring_q_create(k_ring_q_t *ring_q, void *pool, size_t item_cn
|
||||
* @param[in] ring_q pointer to the handler of the ring queue.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
* @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.
|
||||
|
@@ -21,6 +21,10 @@
|
||||
#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;
|
||||
|
@@ -26,25 +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_TASK_DYN = 0xDAD2,
|
||||
KNL_OBJ_TYPE_TIMER = 0xDAD3,
|
||||
KNL_OBJ_TYPE_MSG_QUEUE = 0xDAD4,
|
||||
KNL_OBJ_TYPE_MMBLK_POOL = 0xDAD5,
|
||||
KNL_OBJ_TYPE_RING_QUEUE = 0xDAD6,
|
||||
KNL_OBJ_TYPE_BINARY_HEAP = 0xDAD7,
|
||||
KNL_OBJ_TYPE_PRIORITY_QUEUE = 0xDAD8,
|
||||
KNL_OBJ_TYPE_CHAR_FIFO = 0xDAD9,
|
||||
KNL_OBJ_TYPE_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.
|
||||
@@ -149,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);
|
||||
|
@@ -69,9 +69,7 @@ typedef void (*k_task_walker)(k_task_t *task);
|
||||
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 */
|
||||
|
@@ -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