/**************************************************************************//** * @item CosyOS-III Kernel * @file sv_int_pend_fifo.c * @brief 中断挂起服务_FIFO-执行函数 * @details 仅在 PendSV中断 中由系统调用并执行。 * @author 迟凯峰 * @version V2.3.0 * @date 2026.02.01 ******************************************************************************/ #include "os_var.h" #if (MCUCFG_PENDSVFIFO_DEPTH > 0) #include "os_api.h" #include "sv_com.h" #include "ur_api.h" /** @addtogroup 中断挂起服务_FIFO @{ *//** \defgroup 中断挂起服务_FIFO-执行函数 @{ */ /** \page 手动裁剪说明: \li 本页中的各个执行函数,任何编译器都无法自动移除未使用,原因是
它们是通过函数指针间接调用的。 \li 如果您希望做到极致的裁剪,可逐一查看这些函数,确定不使用的,
可通过 编译开关 进行手动移除。 */ /** \brief 清除就绪延时 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iClearDelay()。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _clear_delay_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { __UNUSED(sv); sc_clear_delay(); } #else #define _clear_delay_ OS_NULL #endif /** \brief 恢复任务 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iResumeTask(task)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _resume_task_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_tasknode_tsp htask = ((sp_task_tsp)sv)->htask; #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) s_ecode_t _ecode = sc_resume_task(htask); if(_ecode){ s_psvfifo_ecode = _ecode; pResumeTask_ErrorCallback(htask); } #else if(htask == OS_NULL) return; if(htask->status & OS_STATUS_SUSPENDED){ sa_resume_task(htask); } #endif } #else #define _resume_task_ OS_NULL #endif /** \brief 挂起任务 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iSuspendTask(task)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _suspend_task_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_tasknode_tsp htask = ((sp_task_tsp)sv)->htask; #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) s_ecode_t _ecode = sc_suspend_task(htask); if(_ecode){ s_psvfifo_ecode = _ecode; pSuspendTask_ErrorCallback(htask); } #else if(htask == OS_NULL) return; if(htask->status < OS_STATUS_SUSPENDED){ sa_suspend_task(htask); } #endif } #else #define _suspend_task_ OS_NULL #endif /** \brief 删除任务 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iDeleteTask(task)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _delete_task_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_tasknode_tsp htask = ((sp_task_tsp)sv)->htask; #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) s_ecode_t _ecode = sc_delete_task(htask); if(_ecode){ s_psvfifo_ecode = _ecode; pDeleteTask_ErrorCallback(htask); } #else if(htask == OS_NULL) return; if(htask->status < OS_STATUS_DELETED){ sa_delete_task(htask); } #endif } #else #define _delete_task_ OS_NULL #endif /** \brief 清除阻塞(状态) \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iClearBlock(task)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _clear_block_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_tasknode_tsp htask = ((sp_task_tsp)sv)->htask; #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) s_ecode_t _ecode = sc_clear_block(htask); if(_ecode){ s_psvfifo_ecode = _ecode; pClearBlock_ErrorCallback(htask); } #else if(htask == OS_NULL) return; if(htask->status == OS_STATUS_FLOATING || htask->status == OS_STATUS_BLOCKED){ sa_clear_block(htask); } #endif } #else #define _clear_block_ OS_NULL #endif /** \brief 设置阻塞(时间) \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iSetBlock_tc(task, tc)、iSetBlock_ms(task, ms)、 iSetBlock_s(task, s)、iSetBlock_m(task, m)、iSetBlock_h(task, h)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _set_block_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_tasknode_tsp htask = ((sp_blocktime_tsp)sv)->htask; s_delay_t tick = ((sp_blocktime_tsp)sv)->tick; #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) s_ecode_t _ecode = sc_set_block(htask, tick); if(_ecode){ s_psvfifo_ecode = _ecode; pSetBlock_ErrorCallback(htask, tick); } #else if(htask == OS_NULL) return; if(htask->status == OS_STATUS_FLOATING || htask->status == OS_STATUS_BLOCKED){ sa_set_block(htask, tick); } #endif } #else #define _set_block_ OS_NULL #endif /** \brief 设置任务优先级 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iSetTaskPri(task, npri)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _set_taskpri_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_tasknode_tsp htask = ((sp_taskpri_tsp)sv)->htask; s_u8_t npri = ((sp_taskpri_tsp)sv)->npri; #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) s_ecode_t _ecode = sc_set_taskpri(htask, npri); if(_ecode){ s_psvfifo_ecode = _ecode; pSetTaskPri_ErrorCallback(htask, npri); } #else if(htask == OS_NULL) return; if(htask->status < OS_STATUS_STOPPED){ if(htask->pri != npri){ sa_set_taskpri(htask, npri); } } #endif } #else #define _set_taskpri_ OS_NULL #endif /** \brief 写二值信号量 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iLockBin(bin)、iGiveBin(bin)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (SYSCFG_BINARY == __ENABLED__) static void _write_binary_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_binary_tsp hbin = ((sp_binary_tsp)sv)->hbin; bool value = ((sp_binary_tsp)sv)->value; sc_write_binary(hbin, value); } #else #define _write_binary_ OS_NULL #endif /** \brief 给予计数信号量 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iGiveSem(sem)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (SYSCFG_SEMAPHORE == __ENABLED__) static void _give_semaph_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_semaph_tsp hsem = ((sp_semaph_tsp)sv)->hsem; sc_give_semaph(hsem); } #else #define _give_semaph_ OS_NULL #endif /** \brief 发送飞信 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iSendFetion(tbox, tion)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (SYSCFG_FETION == __ENABLED__) static void _send_fetion_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_tionbox_tsp htbox = ((sp_tionbox_tsp)sv)->htbox; m_fetion_t tion = ((sp_tionbox_tsp)sv)->tion; sc_send_fetion(htbox, tion); } #else #define _send_fetion_ OS_NULL #endif /** \brief 发送邮件 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iSendMail(mbox, mail)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (SYSCFG_MAILBOX == __ENABLED__) static void _send_mail_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_mailbox_tsp hmbox = ((sp_mailbox_tsp)sv)->hmbox; void *mail = ((sp_mailbox_tsp)sv)->mail; sc_send_mail(hmbox, mail); } #else #define _send_mail_ OS_NULL #endif /** \brief 发送消息 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iSendMsg(que, msg)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (SYSCFG_MSGQUEUE == __ENABLED__) static void _send_msg_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_msgque_tsp hque = ((sp_msgque_tsp)sv)->hque; void *msg = ((sp_msgque_tsp)sv)->msg; #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) s_ecode_t _ecode = sc_send_msg(hque, msg); if(_ecode){ s_psvfifo_ecode = _ecode; pSendMsg_ErrorCallback(hque, msg); } #else sc_send_msg(hque, msg); #endif } #else #define _send_msg_ OS_NULL #endif /** \brief 定时中断 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iTimInt_tc(tmid, tc)、iTimInt_ms(tmid, ms)、iTimInt_s(tmid, s)、 iTimInt_m(tmid, m)、iTimInt_h(tmid, h)、iTimInt_Cancel(tmid)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (OS_TIMINTTOTAL > 0) static void _timint_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_u8_t tmid = ((sp_timint_tsp)sv)->tmid; s_timint_t tick = ((sp_timint_tsp)sv)->tick; sc_timint(tmid, tick); } #else #define _timint_ OS_NULL #endif /** \brief 定时查询 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iTimQry_tc(tmid, tc)、iTimQry_ms(tmid, ms)、iTimQry_s(tmid, s)、 iTimQry_m(tmid, m)、iTimQry_h(tmid, h)、iTimQry_Cancel(tmid)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (OS_TIMQRYTOTAL > 0) static void _timqry_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { s_u8_t tmid = ((sp_timqry_tsp)sv)->tmid; s_timqry_t tick = ((sp_timqry_tsp)sv)->tick; sc_timqry(tmid, tick); } #else #define _timqry_ OS_NULL #endif /** \brief 写标志组 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iClearFlagGroup(group)、 iSetFlagBit(group, bit)、iSetFlagBits(group, nbit) ...)、 iClearFlagBit(group, bit)、iClearFlagBits(group, nbit) ...)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ \ && (SYSCFG_FLAGGROUP == __ENABLED__) static void _write_group_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { switch((s_u8_t)(((sp_group_tsp)sv)->size)){ case 0x01: *(s_u8_t *)((sp_group_tsp)sv)->hgrp |= ((sp_group_tsp)sv)->value; break; case 0x02: *(s_u16_t *)((sp_group_tsp)sv)->hgrp |= ((sp_group_tsp)sv)->value; break; case 0x04: *(s_u32_t *)((sp_group_tsp)sv)->hgrp |= ((sp_group_tsp)sv)->value; break; case 0xFF: *(s_u8_t *)((sp_group_tsp)sv)->hgrp &=~((sp_group_tsp)sv)->value; break; case 0xFE: *(s_u16_t *)((sp_group_tsp)sv)->hgrp &=~((sp_group_tsp)sv)->value; break; case 0xFC: *(s_u32_t *)((sp_group_tsp)sv)->hgrp &=~((sp_group_tsp)sv)->value; break; } } #else #define _write_group_ OS_NULL #endif /** \brief 全局变量写访问 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iWriteGVar(gv, lv)、iWriteGAry(gp, lp, size)、iWriteGStr(gs, ls)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ #include static void _write_gvar_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { size_t size = ((sp_gvar_tsp)sv)->size; void * gp = ((sp_gvar_tsp)sv)->gp; void * lp = ((sp_gvar_tsp)sv)->lp; size ? s_memcpy(gp, lp, size) : s_strcpy((char *)gp, (char *)lp); } #else #define _write_gvar_ OS_NULL #endif /** \brief 挂起服务调用 \param[in] sv 服务的结构体指针 \return 无 \note 关联服务:iPendSVC(fp)。 */ #if 1 /* 编译开关 *//* 如果用户不会调用关联服务,可手动移除该函数(1 改为 0)*/ static void _pendsvc_(void _STATIC_MEM_ *sv) MCUCFG_OSIT_ATTRIBUTE { (*((sp_pendsvc_tsp)sv)->fp)(); } #else #define _pendsvc_ OS_NULL #endif /** \brief 中断挂起服务_FIFO - 执行总函数(函数指针数组) \param[in] [SVID] 服务ID \param[in] sv 服务的结构体指针 \return 无 */ void (_CODE_MEM_ * const _CONST_MEM_ sPendSV_FIFOHandler[OS_SVID_END])(void _STATIC_MEM_ *sv) = { _clear_delay_, _resume_task_, _suspend_task_, _delete_task_, _clear_block_, _set_block_, _set_taskpri_, _write_binary_, _give_semaph_, _send_fetion_, _send_mail_, _send_msg_, _timint_, _timqry_, _write_group_, _write_gvar_, _pendsvc_ }; /** @} *//** \defgroup 中断挂起服务_FIFO-错误调用返回 \note 当需要回调时,下列的回调函数可以在用户文件中实现。 @{ */ #if (SYSCFG_PENDSVFIFO_ERRORCALLBACK == __ENABLED__) /** \brief iResumeTask(task) error callback \param[in] htask 任务句柄 \return 无 */ #if 1 /* 编译开关 *//* 如果该函数在用户文件中实现且此处的弱定义无效,可手动移除该函数(1 改为 0)*/ \ && !defined (_resume_task_) __WEAK void pResumeTask_ErrorCallback(s_tasknode_tsp htask) MCUCFG_OSIT_ATTRIBUTE { /* Prevent unused argument(s) compilation warning */ __UNUSED(htask); /* NOTE: This function should not be modified, when the callback is needed, the pResumeTask_ErrorCallback could be implemented in the user file */ } #endif /** \brief iSuspendTask(task) error callback \param[in] htask 任务句柄 \return 无 */ #if 1 /* 编译开关 *//* 如果该函数在用户文件中实现且此处的弱定义无效,可手动移除该函数(1 改为 0)*/ \ && !defined (_suspend_task_) __WEAK void pSuspendTask_ErrorCallback(s_tasknode_tsp htask) MCUCFG_OSIT_ATTRIBUTE { /* Prevent unused argument(s) compilation warning */ __UNUSED(htask); /* NOTE: This function should not be modified, when the callback is needed, the pSuspendTask_ErrorCallback could be implemented in the user file */ } #endif /** \brief iDeleteTask(task) error callback \param[in] htask 任务句柄 \return 无 */ #if 1 /* 编译开关 *//* 如果该函数在用户文件中实现且此处的弱定义无效,可手动移除该函数(1 改为 0)*/ \ && !defined (_delete_task_) __WEAK void pDeleteTask_ErrorCallback(s_tasknode_tsp htask) MCUCFG_OSIT_ATTRIBUTE { /* Prevent unused argument(s) compilation warning */ __UNUSED(htask); /* NOTE: This function should not be modified, when the callback is needed, the pDeleteTask_ErrorCallback could be implemented in the user file */ } #endif /** \brief iClearBlock(task) error callback \param[in] htask 任务句柄 \return 无 */ #if 1 /* 编译开关 *//* 如果该函数在用户文件中实现且此处的弱定义无效,可手动移除该函数(1 改为 0)*/ \ && !defined (_clear_block_) __WEAK void pClearBlock_ErrorCallback(s_tasknode_tsp htask) MCUCFG_OSIT_ATTRIBUTE { /* Prevent unused argument(s) compilation warning */ __UNUSED(htask); /* NOTE: This function should not be modified, when the callback is needed, the pClearBlock_ErrorCallback could be implemented in the user file */ } #endif /** \brief iSetBlock_x(task, x) error callback \details iSetBlock_tc(task, tc)、iSetBlock_ms(task, ms)、iSetBlock_s(task, s)、 iSetBlock_m(task, m)、iSetBlock_h(task, h),都通过该函数实现错误调用返回。 \param[in] htask 任务句柄 \param[in] tick 滴答周期(阻塞时间) \return 无 */ #if 1 /* 编译开关 *//* 如果该函数在用户文件中实现且此处的弱定义无效,可手动移除该函数(1 改为 0)*/ \ && !defined (_set_block_) __WEAK void pSetBlock_ErrorCallback(s_tasknode_tsp htask, s_delay_t tick) MCUCFG_OSIT_ATTRIBUTE { /* Prevent unused argument(s) compilation warning */ __UNUSED(htask); __UNUSED(tick); /* NOTE: This function should not be modified, when the callback is needed, the pSetBlock_ErrorCallback could be implemented in the user file */ } #endif /** \brief iSetTaskPri(task, npri) error callback \param[in] htask 任务句柄 \param[in] npri 新优先级 \return 无 */ #if 1 /* 编译开关 *//* 如果该函数在用户文件中实现且此处的弱定义无效,可手动移除该函数(1 改为 0)*/ \ && !defined (_set_taskpri_) __WEAK void pSetTaskPri_ErrorCallback(s_tasknode_tsp htask, s_u8_t npri) MCUCFG_OSIT_ATTRIBUTE { /* Prevent unused argument(s) compilation warning */ __UNUSED(htask); __UNUSED(npri); /* NOTE: This function should not be modified, when the callback is needed, the pSetTaskPri_ErrorCallback could be implemented in the user file */ } #endif /** \brief iSendMsg(que, msg) error callback \param[in] hque 队列句柄 \param[in] msg 消息指针 \return 无 */ #if 1 /* 编译开关 *//* 如果该函数在用户文件中实现且此处的弱定义无效,可手动移除该函数(1 改为 0)*/ \ && !defined (_send_msg_) __WEAK void pSendMsg_ErrorCallback(s_msgque_tsp hque, void *msg) MCUCFG_OSIT_ATTRIBUTE { /* Prevent unused argument(s) compilation warning */ __UNUSED(hque); __UNUSED(msg); /* NOTE: This function should not be modified, when the callback is needed, the pSendMsg_ErrorCallback could be implemented in the user file */ } #endif #endif /** @} */ /** @} */ #endif