
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)
165 lines
4.8 KiB
C
165 lines
4.8 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_SYS_H_
|
|
#define _TOS_SYS_H_
|
|
|
|
#define K_NESTING_LIMIT_IRQ (k_nesting_t)250u
|
|
#define K_NESTING_LIMIT_SCHED_LOCK (k_nesting_t)250u
|
|
|
|
typedef enum knl_state_en {
|
|
KNL_STATE_STOPPED,
|
|
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_t;
|
|
|
|
typedef struct knl_object_st {
|
|
knl_obj_type_t type;
|
|
} knl_obj_t;
|
|
#endif
|
|
|
|
/**
|
|
* @brief Initialize the kernel.
|
|
* initialize the tos tiny kernel.
|
|
*
|
|
* @attention None
|
|
*
|
|
* @param None
|
|
*
|
|
* @return errcode
|
|
* @retval Non-#K_ERR_NONE return failed.
|
|
* @retval #K_ERR_NONE return successfully.
|
|
*/
|
|
__API__ k_err_t tos_knl_init(void);
|
|
|
|
/**
|
|
* @brief Start the kernel.
|
|
* get the kernel start to run, which means start the multitask scheduling.
|
|
*
|
|
* @attention None
|
|
*
|
|
* @param None
|
|
*
|
|
* @return errcode
|
|
* @retval #K_ERR_KNL_RUNNING the kernel is already running.
|
|
* @retval #K_ERR_NONE return successfully.
|
|
*/
|
|
__API__ k_err_t tos_knl_start(void);
|
|
|
|
/**
|
|
* @brief Get the kernel state.
|
|
* whether the kernel is running.
|
|
*
|
|
* @attention None
|
|
*
|
|
* @param None
|
|
*
|
|
* @return whether the kernel is running.
|
|
* @retval Non-0 the kernel is running.
|
|
* @retval 0 the kernel is not running.
|
|
*/
|
|
__API__ int tos_knl_is_running(void);
|
|
|
|
/**
|
|
* @brief Kernel enter the interrupt.
|
|
* this function should be called in the entrance of a interrupt handler.
|
|
*
|
|
* @attention None
|
|
*
|
|
* @param None
|
|
*
|
|
* @return None
|
|
*/
|
|
__API__ void tos_knl_irq_enter(void);
|
|
|
|
/**
|
|
* @brief Kernel exit the interrupt.
|
|
* this function should be called in the exit of a interrupt handler.
|
|
*
|
|
* @attention None
|
|
*
|
|
* @param None
|
|
*
|
|
* @return None
|
|
*/
|
|
__API__ void tos_knl_irq_leave(void);
|
|
|
|
/**
|
|
* @brief Lock the scheduler.
|
|
* prevent the kernel from performing task schedule.
|
|
*
|
|
* @attention None
|
|
*
|
|
* @param None
|
|
*
|
|
* @return errcode
|
|
* @retval K_ERR_KNL_NOT_RUNNING the kernel is not running.
|
|
* @retval K_ERR_LOCK_NESTING_OVERFLOW the schedule lock nesting is overflow.
|
|
* @retval K_ERR_NONE return successfully.
|
|
*/
|
|
__API__ k_err_t tos_knl_sched_lock(void);
|
|
|
|
/**
|
|
* @brief Unlock the scheduler.
|
|
* re-enable the task schedule.
|
|
*
|
|
* @attention None
|
|
*
|
|
* @param None
|
|
*
|
|
* @return errcode
|
|
* @retval K_ERR_KNL_NOT_RUNNING the kernel is not running.
|
|
* @retval K_ERR_SCHED_NOT_LOCKED the scheduler is not locked.
|
|
* @retval K_ERR_NONE return successfully.
|
|
*/
|
|
__API__ k_err_t tos_knl_sched_unlock(void);
|
|
|
|
#if TOS_CFG_TICKLESS_EN > 0u
|
|
__KERNEL__ k_tick_t knl_next_expires_get(void);
|
|
#endif
|
|
|
|
__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);
|
|
#endif
|
|
|
|
__KERNEL__ int knl_is_sched_locked(void);
|
|
__KERNEL__ int knl_is_inirq(void);
|
|
__KERNEL__ int knl_is_idle(k_task_t *task);
|
|
__KERNEL__ int knl_is_self(k_task_t *task);
|
|
__KERNEL__ k_err_t knl_idle_init(void);
|
|
|
|
#endif /* _TOS_SYS_H_ */
|
|
|