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

📄 os_cpu_c.c

📁 这是一个飞思卡尔智能车比赛的一个完整的程序
💻 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
  
*******************************************************************************************************/
/********************************************************************
                               //
//     Author: CaiXinBo      \\\\\\\                            //
//                          ( o   o )                           //
//----------------------oOO----(_)----OOo-----------------------//
                                                              
    FileName:       OS_CPU_C.C	
    Created Date:   23/5/2006   9:45
    Modify Date:    
    Purpose:	
*********************************************************************/

#include "mc9s12dg128.h"
#define  OS_CPU_GLOBALS
#include "includes.h"
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
		}
		
}
OS_STK *OSTaskStkInit(void (*task)(void *pd), void *pdata, OS_STK *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 ((OS_STK *)stk);
}

/*$PAGE*/


/******************************************
*      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 + -