Files
TencentOS-tiny/kernel/core/include/tos_char_fifo.h
daishengdong d0b8d0675e add ring queue/message queue/mail queue, binary heap/priority queue/priority message queue/priority mail queue
1. remove the old msg queue and queue:
i. msg queue is not a common and reusable/flexible component(need user to config the msg pool size and this componet can only be used by tos_queue)
ii. tos_queue can only deliver the pointer message(cannot do a memory buffer deliver)

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

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

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

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

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

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

8. add priority mail queue(tos_prio_mail_q)
a mail(memory buffer) deliver mechanism, supply the capability of delivering the mail with priority(mail with higher priority comes faster to the pender than with lower)
2019-10-28 15:50:46 +08:00

160 lines
5.0 KiB
C

/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_CHAR_FIFO_H_
#define _TOS_CHAR_FIFO_H_
typedef struct k_char_fifo_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
k_ring_q_t ring_q;
} k_chr_fifo_t;
/**
* @brief Create a character fifo.
* Create a character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
* @param[in] buffer memory buffer provided to be as the inner buffer.
* @param[in] size size of the memory buffer.
*
* @return errno
* @retval #K_ERR_OBJ_PTR_NULL fifo is a NULL pointer.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_create(k_chr_fifo_t *chr_fifo, void *buffer, size_t size);
/**
* @brief Destroy a character fifo.
* Destroy a character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the fifo.
*
* @return errno
* @retval #K_ERR_OBJ_PTR_NULL fifo is a NULL pointer.
* @retval #K_ERR_OBJ_INVALID not a valid pointer to a fifo.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_destroy(k_chr_fifo_t *chr_fifo);
/**
* @brief Push data into character fifo.
* Push one single data into the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[in] data data to push into the fifo.
*
* @return errno
* @retval #K_ERR_RING_Q_FULL the character fifo is full.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_push(k_chr_fifo_t *chr_fifo, uint8_t data);
/**
* @brief Push stream into character fifo.
* Push a stream data into the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[IN] stream stream to be pushed into the character fifo.
* @param[OUT] size size of the stream.
*
* @return the actual number of the data pushed into the character fifo.
*/
__API__ int tos_chr_fifo_push_stream(k_chr_fifo_t *chr_fifo, uint8_t *stream, size_t size);
/**
* @brief Pop data from character fifo.
* Pop one single data from the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[OUT] out one signle buffer to hold the data poped from the character fifo.
*
* @return errno
* @retval #K_ERR_FIFO_EMPTY the character fifo is empty.
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_chr_fifo_pop(k_chr_fifo_t *chr_fifo, uint8_t *out);
/**
* @brief Pop stream from character fifo.
* Pop a stream data from the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
* @param[OUT] buffer pointer to the buffer to receive the stream poped.
* @param[OUT] size size of the buffer.
*
* @return the actual number of the data poped from the character fifo.
*/
__API__ int tos_chr_fifo_pop_stream(k_chr_fifo_t *chr_fifo, uint8_t *buffer, size_t size);
/**
* @brief Flush character fifo.
* Flush/reset the character fifo.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
*
* @return None.
*/
__API__ k_err_t tos_chr_fifo_flush(k_chr_fifo_t *chr_fifo);
/**
* @brief Whether the character fifo is empty.
* Whether the character fifo is empty.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
*
* @return whether the character fifo is emtpy.
* @retval #0 the character fifo is not empty.
* @retval #Not 0 the character fifo is empty.
*/
__API__ int tos_chr_fifo_is_empty(k_chr_fifo_t *chr_fifo);
/**
* @brief Whether the character fifo is full.
* Whether the character fifo is full.
*
* @attention None
*
* @param[in] fifo pointer to the handler of the character fifo.
*
* @return whether the character fifo is full.
* @retval #0 the character fifo is not full.
* @retval #Not 0 the character fifo is full.
*/
__API__ int tos_chr_fifo_is_full(k_chr_fifo_t *chr_fifo);
#endif // _TOS_CHAR_FIFO_H_