⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_cpu_c.c

📁 飞思卡尔相关的codewarrior程序开发PortucosiiV252工程范例
💻 C
字号:
/*
*********************************************************************************************************
*                                               uC/OS-II
*                                         The Real-Time Kernel
*
*                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
*                                          All Rights Reserved
*
*
*                                       MC9S12DP256/DG128 Specific code
*                                          SMALL MEMORY MODEL
*
* File : OS_CPU_C.C
* By   : Jean J. Labrosse
* Update By : Shao Senlong
************** Tsinghua University Motorola MCU & DSP Application Center
*********************************************************************************************************
*/

#define  OS_CPU_GLOBALS
#include "includes.h"
#define  CRGFLG (*((volatile unsigned char*)(0x0037)))


void OSTickISR(void)
{  
	asm{
		ldaa	$30		//save ppage to stack
		psha
		}
	OSIntEnter();
	OS_SAVE_SP();
	CRGFLG &=0xEF;			// clear the interrupt flag
	OSTimeTick();
	OSIntExit();			// exit interrupt and task switch
	
	asm{
		pula
		staa	$30		//restore ppage from stack
		nop
		rti
		}
		
}

void *OSTaskStkInit (void (*task)(void *pd), void *pdata, void *ptos, INT16U opt)
{
    INT16U *stk;

    stk    = (INT16U *)ptos;            // Load stack pointer    
    *--stk = opt;           			// opt   There is one byte blank
    *--stk = (INT16U)(task);            // PC	for use of opt in task
    *--stk = (INT16U)(task);            // PC
    *--stk = (INT16U)(0x1122);		    // Y  
    *--stk = (INT16U)(0x3344);		    // X  
   	((INT8U *)stk)--;					// Only one byte needed for A
	*(INT8U *)stk = (INT8U)(((INT16U)pdata)>>8);  // A
	((INT8U *)stk)--;					// Only one byte needed for B
	*(INT8U *)stk = (INT8U)(pdata);    	// B
 	((INT8U *)stk)--;					// Only one byte needed for CCR
	*(INT8U *)stk = (INT8U)(0x00);    	// CCR
	((INT8U *)stk)--;					// Only one byte needed for PPAGE
	*(INT8U *)stk = *(INT8U *)pdata;    // PPAGE
    
    return ((void *)stk);
}

/*$PAGE*/
#if OS_CPU_HOOKS_EN
/*
*********************************************************************************************************
*                                          TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments  : ptcb   is a pointer to the task control block of the task being created.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskCreateHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}


/*
*********************************************************************************************************
*                                           TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments  : ptcb   is a pointer to the task control block of the task being deleted.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskDelHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}

/*
*********************************************************************************************************
*                                           TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed.  This allows you to perform other
*              operations during a context switch.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts are disabled during this call.
*              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
*                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the 
*                 task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
void OSTaskSwHook (void)
{
}

/*
*********************************************************************************************************
*                                           STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task.  This allows your 
*              application to add functionality to the statistics task.
*
* Arguments  : none
*********************************************************************************************************
*/
void OSTaskStatHook (void)
{
}

/*
*********************************************************************************************************
*                                               TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
void OSTimeTickHook (void)
{
}


void OSTaskIdleHook(void)
{
}

void OSInitHookBegin(void)
{
}

void OSInitHookEnd(void)
{
}

void OSTCBInitHook(OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}


#endif

/******************************************
*      START HIGHEST PRIORITY TASK READY-TO-RUN
*******************************************/
void	OSStartHighRdy(void)
{

	OSTaskSwHook();				// Call Hook function
	
	asm{
		ldx		OSTCBCur		// Load the value in OSTCBCur or the TCB's address to x
		lds		0,x				// Load the value pointed by OSTCBCur to sp
		ldaa	OSRunning
		inca					// OSRunning = 1
		staa	OSRunning
		pula
		staa	$30			//restore ppage from stack
		nop
		rti
		}	
	
}

/**********************************************
*       INTERRUPT LEVEL CONTEXT SWITCH
**********************************************/
void	OSIntCtxSw(void)
{
/*	asm{
		leas	4,sp				// Adjust the sp 
		ldx		OSTCBCur			// Get the TCB's address
		sts		0,x					// Save the sp to TCB's first word
		}	*/	
	OSTaskSwHook();					// Call Hook function
	OSTCBCur = OSTCBHighRdy;		// Change OSTCBCur and OSPrioCur
	OSPrioCur = OSPrioHighRdy;
	asm{
		ldx		OSTCBCur			// Get the new task's TCB's address
		lds		0,x					// Load the new task's sp to sp register from its TCB
		pula
		staa	$30				//restore ppage from stack
		nop
		rti
		}	
		
		
}

/*******************************************
*        TASK LEVEL CONTEXT SWITCH
******************************************/
void	OSCtxSw(void)
{
	asm{
		ldaa	$30				//save ppage to stack
		psha
		ldx		OSTCBCur			// Get the TCB's address
		sts		0,x					// Save the sp to TCB's first word
		}
	OSTaskSwHook();					// Call Hook function
	OSTCBCur = OSTCBHighRdy;		// Change OSTCBCur and OSPrioCur
	OSPrioCur = OSPrioHighRdy;
	asm{
		ldx		OSTCBCur			// Get the new task's TCB's address
		lds		0,x					// Load the new task's sp to sp register from its TCB
		pula
		staa	$30				//restore ppage from stack
		nop
		rti
		}	
	
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -