📄 os_cpu_c.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1999, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
*
* PPC555 Specific code
* CodeWarrior V6.5
*
* File : OS_CPU_C.C
* By : Liuyuan, Tianshuo
* e-mail : kinglad@tsinghua.org.cn; tianshuo99@mails.tsinghua.edu.cn
*********************************************************************************************************
*/
#include "includes.h"
const unsigned long dec_init=COUNT_PER_SEC/OS_TICKS_PER_SEC;
#define STACK_BUFFER_SIZE 40
extern char _SDA_BASE_[];
extern char _SDA2_BASE_[];
/*
*********************************************************************************
* INITIALIZE A TASK STACK
* note: This function initialize the stack frame, which would should be congruent
* with the stack usage in OS_CPU_A.ASM
**********************************************************************************
*/
void *OSTaskStkInit (void (*task)(void *pd), void *pdata, void *ptos, INT16U opt)
{
OS_STK * stkp;
INT32U INITIAL_SR;
register INT32U rA;
asm //Get MSR and stored into INITIAL_SR
{
mfmsr rA
ori rA,rA,0x8000 //Set MSR[EE]=1
stw rA,INITIAL_SR
}
opt=opt;
/* 8-byte align task's stack pointer (EABI) */
stkp = (OS_STK *)((INT32U) ptos & (INT32U) 0xFFFFFFF8);
/* Leave buffer area for locals "above the stack" */
/* in case the compiler prolog puts variables above the stack */
stkp -= STACK_BUFFER_SIZE;
/*
* Ensure any changes to the order of these initializations
* are congruent with the Stack Frame definitions in bseppca.s
*/
*--stkp = (INT32U)INITIAL_SR; /* MSR */
*--stkp = 0L; /* r31 */
*--stkp = 0L; /* r30 */
*--stkp = 0L; /* r29 */
*--stkp = 0L; /* r28 */
*--stkp = 0L; /* r27 */
*--stkp = 0L; /* r26 */
*--stkp = 0L; /* r25 */
*--stkp = 0L; /* r24 */
*--stkp = 0L; /* r23 */
*--stkp = 0L; /* r22 */
*--stkp = 0L; /* r21 */
*--stkp = 0L; /* r20 */
*--stkp = 0L; /* r19 */
*--stkp = 0L; /* r18 */
*--stkp = 0L; /* r17 */
*--stkp = 0L; /* r16 */
*--stkp = 0L; /* r15 */
*--stkp = 0L; /* r14 */
*--stkp = (INT32U)&_SDA_BASE_; /* r13 */
*--stkp = 0L; /* r12 */
*--stkp = 0L; /* r11 */
*--stkp = 0L; /* r10 */
*--stkp = 0L; /* r09 */
*--stkp = 0L; /* r08 */
*--stkp = 0L; /* r07 */
*--stkp = 0L; /* r06 */
*--stkp = 0L; /* r05 */
*--stkp = 0L; /* r04 */
*--stkp = (INT32U)pdata; /* r03 */
*--stkp = (INT32U)&_SDA2_BASE_; /* r02 */
*--stkp = (INT32U)task; /* LR */
--stkp; /* CR */
--stkp; /* XER */
--stkp; /* CTR */
*--stkp = (INT32U)INITIAL_SR; /* SRR1 */
*--stkp = (INT32U)task; /* SRR0 */
--stkp; /* R0 */
--stkp; /* BLANK for 0xA0 size */
*--stkp = (INT32U)ptos; /* Stack Ptr */
return (stkp);
}
/**********************************************************************************
* Decrement Interrupt Handler
***********************************************************************************/
void DEC_Hdlr (void)
{
OSIntEnter();
OS_ENTER_CRITICAL();
OS_Set_decrementer ();
OS_EXIT_CRITICAL();
OSTimeTick ();
OSIntExit ();
}
/**********************************************************************************
* Set decrementer to the count value
***********************************************************************************/
asm void OS_Set_decrementer (void)
{
lis r4,dec_init@ha
lwz r4,dec_init@l(r4)
mtdec r4
}
#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;
}
/*
*********************************************************************************************************
* 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;
}
/*
*********************************************************************************************************
* 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)
{
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -