/**************************************************************************//**
 * @item     CosyOS-II Kernel
 * @file     os_api.c
 * @brief    系统内核专用API
 * @author   迟凯峰
 * @version  V1.3.0
 * @date     2024.01.23
 ******************************************************************************/

#include "os_var.h"

#if SYSCFG_MCUCORE == 8051
#pragma NOAREGS
#endif

void s_scheduling_taskpri(s_tasknode_tsp node)
{
	if(node->pri > s_task_current->pri){
		s_sign_scheduling = true;
	}
}

void s_scheduling_notnull(s_tasknode_tsp node)
{
	if(node != NULL){
		s_scheduling_taskpri(node);
	}
}

void s_scheduling_ready(s_tasknode_tsp node)
{
	if(node->status <= OS_STATUS_FLOATING){
		s_scheduling_taskpri(node);
	}
}

void s_scheduling_taskmsg(s_tasknode_tsp node)
{
	if(node->status == OS_STATUS_BLOCKED && (node->blocktype & OS_BLOCKED_TASKMSG)){
		s_scheduling_taskpri(node);
	}
}

void s_set_taskpri(s_tasknode_tsp node)
{
	node->last->next = node->next;
	node->next->last = node->last;
	node->next = node->last = NULL;
	if(s_taskpri_tail != NULL){
		s_taskpri_tail->next = node;
		node->last = s_taskpri_tail;
	}
	s_taskpri_tail = node;
}
