mirror of
https://gitee.com/cosyos/cosyos.git
synced 2026-08-17 16:52:27 +08:00
150 lines
3.2 KiB
C
150 lines
3.2 KiB
C
/**************************************************************************//**
|
|
* @item CosyOS-III Kernel
|
|
* @file sv_int_loc.c
|
|
* @brief 中断本地服务
|
|
* @details 在用户中断中调用并直接在本地执行。
|
|
* @author 迟凯峰
|
|
* @version v3.0.0
|
|
* @date 2026.07.21
|
|
******************************************************************************/
|
|
|
|
#include "os_var.h"
|
|
#include "sv_com.h"
|
|
|
|
/* 相对寄存器访问 for C51 */
|
|
#if defined ( __C51__ )
|
|
#pragma NOAREGS
|
|
#endif
|
|
|
|
/**
|
|
@addtogroup 中断本地服务
|
|
@{
|
|
*/
|
|
|
|
#if (SYSCFG_BINARY == __ENABLED__)
|
|
/**
|
|
\brief 获取二值信号量
|
|
\param[in] hbin 二值信号量句柄
|
|
\return 结果 [true:成功,false:失败]
|
|
*/
|
|
bool si_take_binary(s_binary_tsp hbin)
|
|
{
|
|
if(hbin->binary){
|
|
hbin->binary = false;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
#if (SYSCFG_FETION == __ENABLED__)
|
|
/**
|
|
\brief 接收飞信
|
|
\param[in] htbox 信箱句柄
|
|
\return 飞信数据 [false:失败]
|
|
*/
|
|
m_fetion_t si_recv_fetion(s_tionbox_tsp htbox)
|
|
{
|
|
m_fetion_t tion = htbox->tion;
|
|
htbox->tion = false;
|
|
return tion;
|
|
}
|
|
#endif
|
|
|
|
#if (SYSCFG_MAILBOX == __ENABLED__)
|
|
/**
|
|
\brief 接收邮件
|
|
\param[in] hmbox 邮箱句柄
|
|
\return 邮件指针 [NULL:失败]
|
|
*/
|
|
void *si_recv_mail(s_mailbox_tsp hmbox)
|
|
{
|
|
if(hmbox->flag){
|
|
hmbox->flag = false;
|
|
return hmbox->mail;
|
|
}
|
|
return OS_NULL;
|
|
}
|
|
#endif
|
|
|
|
#if (SYSCFG_MSGQUEUE == __ENABLED__) && (SYSCFG_MSGQUEUE_INTRECV == __ENABLED__)
|
|
#if defined ( __C51__ )
|
|
/**
|
|
\brief 获取队列互斥量
|
|
\details 获取队列访问权限 for C51接收消息。
|
|
\param[in] hque 队列句柄
|
|
\return 结果 [true:成功,false:失败]
|
|
*/
|
|
bool si_take_quemut(s_msgque_tsp hque)
|
|
{
|
|
if(!hque->lock) return false;
|
|
hque->lock = false;
|
|
__mx_MMB();
|
|
|
|
if(hque->type == __DYNAMIC__){
|
|
#if (SYSCFG_DEBUGGING == __ENABLED__)
|
|
s_fault.error_recvmsg_int = true;
|
|
#endif
|
|
}
|
|
else if(!hque->counter);
|
|
else return true;
|
|
|
|
__mx_MMB();
|
|
hque->lock = true;
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
\brief 归还并返回
|
|
\details 归还队列互斥量并返回消息指针 for C51接收消息。
|
|
\param[out] mut 队列互斥量指针
|
|
\param[in] msg 消息指针
|
|
\return 消息指针 [NULL:失败]
|
|
*/
|
|
static void *_back_ret_(bool _STATIC_MEM_ *mut, void *msg)
|
|
{
|
|
*mut = true;
|
|
return msg;
|
|
}
|
|
|
|
/**
|
|
\brief C51接收消息
|
|
\param[in] hque 队列句柄
|
|
\return 消息指针 [NULL:失败]
|
|
*/
|
|
void *si_recv_msg_c51(s_msgque_tsp hque)
|
|
{
|
|
void *msg = sc_recv_msg_staque((s_staque_tsp)hque);
|
|
return _back_ret_((bool *)&hque->lock, msg);
|
|
}
|
|
#else
|
|
/**
|
|
\brief 非51接收消息
|
|
\param[in] hque 队列句柄
|
|
\return 消息指针 [NULL:失败]
|
|
*/
|
|
void *si_recv_msg_n51(s_msgque_tsp hque)
|
|
{
|
|
void *msg = OS_NULL;
|
|
if(!hque->lock) return OS_NULL;
|
|
hque->lock = false;
|
|
__mx_MMB();
|
|
|
|
if(hque->type == __DYNAMIC__){
|
|
#if (SYSCFG_DEBUGGING == __ENABLED__)
|
|
s_fault.error_recvmsg_int = true;
|
|
#endif
|
|
}
|
|
else if(hque->counter){
|
|
msg = sc_recv_msg_staque((s_staque_tsp)hque);
|
|
}
|
|
|
|
__mx_MMB();
|
|
hque->lock = true;
|
|
return msg;
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
/** @} */
|