mirror of
https://gitee.com/cosyos/cosyos.git
synced 2026-02-05 19:39:42 +08:00
145 lines
3.1 KiB
C
145 lines
3.1 KiB
C
/**************************************************************************//**
|
||
* @item CosyOS-III Kernel
|
||
* @file sv_int_loc.c
|
||
* @brief 中断本地服务
|
||
* @details 仅在用户中断中调用,并在本地执行。
|
||
* @author 迟凯峰
|
||
* @version V2.3.0
|
||
* @date 2026.02.01
|
||
******************************************************************************/
|
||
|
||
#include "os_var.h"
|
||
#include "sv_com.h"
|
||
|
||
#if (SYSCFG_MCUCORE == 8051)
|
||
#pragma NOAREGS /* 相对寄存器访问 for C51 */
|
||
#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__)
|
||
#if (SYSCFG_MCUCORE == 8051)
|
||
/**
|
||
\brief 获取队列互斥量
|
||
\details 获取队列访问权限 for C51接收消息。
|
||
\param[in] hque 队列句柄
|
||
\return 结果 [true:成功,false:失败]
|
||
*/
|
||
bool si_take_quemut(s_msgque_tsp hque)
|
||
{
|
||
if(!hque->mutex) return false;
|
||
hque->mutex = false;
|
||
|
||
if(hque->type == __DYNAMIC__){
|
||
#if (SYSCFG_DEBUGGING == __ENABLED__)
|
||
s_fault.error_recvmsg_int = true;
|
||
#endif
|
||
}
|
||
else if(!hque->counter);
|
||
else return true;
|
||
|
||
hque->mutex = 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->mutex, msg);
|
||
}
|
||
#else
|
||
/**
|
||
\brief 非51接收消息
|
||
\param[in] hque 队列句柄
|
||
\return 消息指针 [NULL:失败]
|
||
*/
|
||
void *si_recv_msg_n51(s_msgque_tsp hque)
|
||
{
|
||
void *msg = OS_NULL;
|
||
if(!hque->mutex) return OS_NULL;
|
||
hque->mutex = false;
|
||
|
||
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);
|
||
}
|
||
|
||
hque->mutex = true;
|
||
return msg;
|
||
}
|
||
#endif
|
||
#endif
|
||
|
||
/** @} */
|