📄 ucosmcfc.c
字号:
/********************************************************************/
/** Unit : uCOSMCFc **/
/** **/
/** Description : This unit contains the C ColdFire specific **/
/** portions of uC/OS. It is primarily responsible for creating a **/
/** new task. **/
/** **/
/** Version History : **/
/** **/
/** A0.01 Initial version started 15/09/97 **/
/** **/
/** Copyright (c) 1997 David Fiddes, D.J.Fiddes@hw.ac.uk **/
/********************************************************************/
#include "includes.h"
/********************************************************************/
/** The INITIAL_SR makes each task start up with the following **/
/** attributes: **/
/** 1. supervisor mode **/
/** 2. all interrupts enabled **/
#define INITIAL_SR 0x2000
UBYTE OSTCBInit( UBYTE p, void *pstk ); // Prototype of dummy(ish) OSTCBInit
/********************************************************************/
/** Function : OSTaskCreate **/
/** **/
/** This function takes the Task "function", Data parameter, **/
/** its initial stack pointer and task priority and uses them to **/
/** create a ColdFire stack frame so that the task can then **/
/** be started. The ColdFire stack is dissimilar from other m68k **/
/** processors in that it HAS to be 4 byte aligned.... **/
/********************************************************************/
UBYTE OSTaskCreate(void (*task)(void *dptr), void *data, void *pstk, UBYTE p)
{
long *stk;
UBYTE err;
long stkframe;
OS_ENTER_CRITICAL();
if (OSTCBPrioTbl[p] == (OS_TCB *)0) { /* Avoid creating task if already exist */
OS_EXIT_CRITICAL();
stk = pstk; //load temporary stack pointer
*--stk = (long)data; // Task "function" parameters
// ColdFire 5200 requires stack frames be 0 modula 4
stkframe = 0x40000000; // default value
switch ( (long) pstk & (long) 0x00000003 )
{
case 0: //format field 0100
(long) stk = (long) stk - 0;
stkframe = 0x40000000;
break;
case 1: //format field 0101
(long) stk = (long) stk - 1;
stkframe = 0x50000000;
break;
case 2: //format field 0110
(long) stk = (long) stk - 2;
stkframe = 0x60000000;
break;
case 3: //format field 0111
(long) stk = (long) stk - 3;
stkframe = 0x70000000;
break;
}
stkframe = stkframe | INITIAL_SR;
*--stk = (long)task; // Task PC
*--stk = (long)stkframe; //Rest of stack frame including format
*--stk = 0xa6L; /* a6 */ /* Matches asm MOVEM instruction */
*--stk = 0xa5L; /* a5 */ /* These initial values should */
*--stk = 0xa4L; /* a4 */ /* really be changed to 00 ;-) */
*--stk = 0xa3L; /* a3 */
*--stk = 0xa2L; /* a2 */
*--stk = 0xa1L; /* a1 */
*--stk = 0xa0L; /* a0 */
*--stk = 0xd7L; /* d7 */
*--stk = 0xd6L; /* d6 */
*--stk = 0xd5L; /* d5 */
*--stk = 0xd4L; /* d4 */
*--stk = 0xd3L; /* d3 */
*--stk = 0xd2L; /* d2 */
*--stk = 0xd1L; /* d1 */
*--stk = 0xd0L; /* d0 */
err = OSTCBInit(p, (void far *)stk);/* Get and initialize a TCB */
if (err == OS_NO_ERR) {
if (OSRunning) { /* Find highest priority task if multitasking has started */
OSSched();
}
}
return (err);
} else {
OS_EXIT_CRITICAL();
return (OS_PRIO_EXIST);
}
}/** end OSTaskCreate **/
/********************************************************************/
/** Function : OSTCBInit **/
/** **/
/** This function sets up the initial Task Control Block. **/
/** Please zap this code and buy Jean Labrosse's book. This is **/
/** a pile of cack and only here to get this port to compile with **/
/** Public Domain source. - DJF **/
/********************************************************************/
UBYTE OSTCBInit( UBYTE p, void *pstk )
{
OS_TCB *ptr;
ptr = OSTCBGetFree();
ptr->OSTCBPrio = (UBYTE)p;
ptr->OSTCBStat = OS_STAT_RDY;
ptr->OSTCBDly = 0;
ptr->OSTCBStkPtr = (void *)pstk; /* Load SP in TCB */
OSTCBPrioTbl[p] = ptr;
OS_ENTER_CRITICAL();
ptr->OSTCBNext = OSTCBList;
ptr->OSTCBPrev = (OS_TCB *)0;
if (OSTCBList != (OS_TCB *)0) { /* Rev. A, This line was missing */
OSTCBList->OSTCBPrev = ptr;
}
OSTCBList = ptr;
OSRdyGrp |= OSMapTbl[p >> 3];
OSRdyTbl[p >> 3] |= OSMapTbl[p & 0x07];
OS_EXIT_CRITICAL();
return 0; /* this is BAD, should return proper Err */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -