?? os_cpu_c.c
字號(hào):
/* os_cpu_c.c
*
* Motorola Coldfire MCF5307 port to MicroC/OS-II
*
* Ross Berteig
* Cheshire Engineering Corp
* 650 Sierra Madre Villa, Suite 201
* Pasadena CA 91107
* +1-626-351-5493 +1-626-351-8645 FAX
* Ross@CheshireEng.com, www.CheshireEng.com
*
* Copyright (C) 1998 Cheshire Engineering Corporation.
* Based on a port to uCOS version 1.x by David Fiddes.
* Portions Copyright (C) 1997 David Fiddes, D.J.Fiddes@hw.ac.uk
* Anything that no longer works is probably not his fault.
*/
#define OS_CPU_GLOBALS
#include "includes.h"
/* TaskCallSite
*
* Provide a simulated call site for every task function.
*
* This allows a task function which accidentally returns to
* delete itself.
*
* The actual fake return address used in the stack frame is
* the label _CallSite, corresponding to the extern CallSite()
* declaration (which makes the compiler happier since it is
* visible at compile time).
*/
void TaskCallSite()
{
asm (" nop ");
asm ("_CallSite: nop ");
//printf("!!!!! Task at prio %d function returned.\n", OSPrioCur);
OSTaskDel(OS_PRIO_SELF);
asm (" HALT ");
}
extern void CallSite(void);
/*
* The INITIAL_SR makes each task start up with the following
* attributes:
* 1. supervisor mode
* 2. all interrupts enabled
*/
#define INITIAL_SR 0x2000
/* OSTaskStkInit
*
* Build the initial stack frame for a new task.
*
* Note that the ColdFire stack *must* be 4 byte aligned, and
* that the exception flag word at the top contains an alignment
* code describing the initial misalignment at the time of
* the exception.
*
* This code will adjust the passed top of stack for the
* required alignment *before* building the stack frame
* and thus use the constant value 4 for the format field
* in the exception frame.
*
* The stack will contain an exception taken after the call of
* the task function and before the execution of any of the
* task function prolog. A dummy return address will be pushed
* pointing to a call site which will fall into a call to
* OSDeleteTask() to delete any task whos function returns.
*
* (high address)
* +------+------+------+------+
* TOP_OF_STACK: | pdata |
* +------+------+------+------+
* | dummy return address |
* +------+------+------+------+
* | format, vector, fault, SR |
* +------+------+------+------+
* |PC of exception (task func)|
* +------+------+------+------+
* | A6 |
* +------+------+------+------+
* | |
* . . .
* | |
* +------+------+------+------+
* | A1 (pdata) |
* +------+------+------+------+
* | |
* . . .
* | |
* +------+------+------+------+
* SP ---> | D0 |
* +------+------+------+------+
* (low address)
*/
void *OSTaskStkInit(void (*task)(void *pd), void *pdata, void *ptos,
INT16U opt)
{
OS_STK *stk;
UBYTE err;
long stkframe;
stk = (OS_STK *)ptos; // load temporary stack pointer
stkframe = 0x40000000; // default format field
switch ( (long) ptos & (long) 0x00000003 )
{
case 0: //format field 0100
#define LOFFSETBY(src,o) (OS_STK *)((long)(src) + (o))
stk = LOFFSETBY(stk, -0);
//stkframe = 0x40000000;
break;
case 1: //format field 0101
stk = LOFFSETBY(stk, -1);
//stkframe = 0x50000000;
break;
case 2: //format field 0110
stk = LOFFSETBY(stk, -2);
//stkframe = 0x60000000;
break;
case 3: //format field 0111
stk = LOFFSETBY(stk, -3);
//stkframe = 0x70000000;
break;
#undef LOFFSETBY
}
stkframe = stkframe | INITIAL_SR;
*stk = 0;
*--stk = (OS_STK)pdata; /* Task "function" parameters */
*--stk = (OS_STK)CallSite; /* Dummy return address part */
/*
* Build the balance of an exception frame. See Section 3.4 in
* the MCF5307 User's Manual for exception frame details.
*/
*--stk = (long)task; /* Task PC */
*--stk = (long)stkframe; /* Format and status */
/*
* And include all the registers as for the
* lea -60(a7),a7
* movem.l d0-d7/a0-a6,(a7)
* instructions used at the top of all interrupts.
* For debugging, use meaningful values for most registers.
* Arguably, registers should be initialized to 0 instead.
*
* To support tasks built with the register calling convention,
* the only argument (which is a pointer) is also passed in
* register a1.
*/
*--stk = (OS_STK)ptos; /* a6 */
*--stk = 0xa5L; /* a5 */
*--stk = 0xa4L; /* a4 */
*--stk = 0xa3L; /* a3 */
*--stk = 0xa2L; /* a2 */
*--stk = (OS_STK)pdata; /* 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 */
return (void *)stk;
}
#if OS_CPU_HOOKS_EN
void OSTaskCreateHook(OS_TCB *ptcb)
{
}
void OSTaskDelHook(OS_TCB *ptcb)
{
}
void OSTaskSwHook(void)
{
}
void OSTaskStatHook(void)
{
}
void OSTimeTickHook(void)
{
}
#endif
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -