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

📄 os_cpu_c.c

📁 在keil大模式下编译的ucos-2源码
💻 C
字号:
/*
/*******************************************************************************
                                      uS/OS-II v2.8
文 件 名  : os_cpu_c.c
作    者  : czn
版    本  : v1.0
********************************************************************************
*/
#define  OS_CPU_GLOBALS
#include "includes.h"

/*
*******************************************************************************
                                OSTaskStkInit()
功能描述: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
          stack frame of the task being created.  This function is highly processor specific.
参    数: task      is a pointer to the task code
          p_arg     is a pointer to a user supplied data area that will be passed to the task
                    when the task first executes.
          ptos      is a pointer to the top of stack.  It is assumed that 'ptos' points to
                    a 'free' entry on the task stack.  If OS_STK_GROWTH is set to 1 then 
                    'ptos' will contain the HIGHEST valid address of the stack.  Similarly, if
                    OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
                    of the stack.
          opt       specifies options that can be used to alter the behavior of OSTaskStkInit().
                    (see uCOS_II.H for OS_TASK_OPT_???).
说    明: Interrupts are enabled when your task starts executing.
*******************************************************************************
*/
OS_STK *OSTaskStkInit(void (*task)(void *p_arg),void *p_arg, OS_STK *ptos, INT16U opt) reentrant
{
    OS_STK *stk;

    p_arg = p_arg;
    opt    = opt;
    stk    = (OS_STK *)ptos;
    *stk++ = 15;                                /*用户堆栈长度              */
    *stk++ = (INT16U)task & 0xFF;               /*任务地址低8位             */
    *stk++ = (INT16U)task >> 8;                 /*任务地址高8位             */
    *stk++ = 0x00;                              /*PSW                       */
    *stk++ = 0x0A;                              /*ACC                       */
    *stk++ = 0x0B;                              /*B                         */
    *stk++ = 0x00;                              /*DPL                       */
    *stk++ = 0x00;                              /*DPH                       */
    *stk++ = 0x00;                              /*R0                        */
    
	/*R3、R2、R1用于传递任务参数ppdata,其中R3代表存储器类型,R2为高字节偏移,R1为低字节位移。*/
	/*通过分析KEIL汇编,了解到任务的void *ppdata参数恰好是用R3、R2、R1传递,不是通过虚拟堆栈。*/
    *stk++ = (INT16U)p_arg & 0xFF;             /*R1                        */
    *stk++ = (INT16U)p_arg >> 8;               /*R2                        */
    *stk++ = 0x01;                              /*R3  XDATA,存储器类型为1  */

    *stk++ = 0x04;                              /*R4                        */
    *stk++ = 0x05;                              /*R5                        */
    *stk++ = 0x06;                              /*R6                        */
    *stk++ = 0x07;                              /*R7                        */
                                                /*不用保存SP,任务切换时根据用户堆栈长度计算得出。*/    
    *stk++ = (INT16U) (ptos+MaxStkSize) >> 8;   /*?C_XBP 仿真堆栈指针高8位  */
    *stk++ = (INT16U) (ptos+MaxStkSize) & 0xFF; /*?C_XBP 仿真堆栈指针低8位  */

    return ((void *)ptos);
}
/*
*******************************************************************************
                                OSTaskCreateHook()
功能描述: This function is called when a task is created.
参    数: ptcb   is a pointer to the task control block of the task being created.
说    明: 1) Interrupts are disabled during this call.
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 
void OSTaskCreateHook(OS_TCB *ptcb) reentrant
{
    ptcb = ptcb;                 /* Prevent compiler warning                 */
}
#endif
/*
*******************************************************************************
                                OSTaskDelHook()
功能描述: This function is called when a task is deleted.
参    数: ptcb   is a pointer to the task control block of the task being deleted.
说    明: 1) Interrupts are disabled during this call.
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 
void OSTaskDelHook(OS_TCB *ptcb) reentrant
{
    ptcb = ptcb;                 /* Prevent compiler warning                 */
}
#endif
/*
*******************************************************************************
                                OSTaskSwHook()
功能描述: This function is called when a task switch is performed.  This allows you to perform other
          operations during a context switch.
参    数: none
说    明: 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).
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 
void OSTaskSwHook(void) reentrant
{
}
#endif
/*
*******************************************************************************
                                OSTaskIdleHook()
功能描述: This function is called by the idle task.  This hook has been added to allow you to do  
          such things as STOP the CPU to conserve power.
参    数: none
说    明: 1) Interrupts are enabled during this call.
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION >= 251
void  OSTaskIdleHook (void)reentrant
{
}
#endif
/*
*******************************************************************************
                                OSTaskStatHook()
功能描述: This function is called every second by uC/OS-II's statistics task.  This allows your 
          application to add functionality to the statistics task.
参    数: none
说    明:
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 
void OSTaskStatHook(void) reentrant
{
}
#endif
/*
*******************************************************************************
                                OSTimeTickHook()
功能描述: This function is called every tick.
参    数: none
说    明: 1) Interrupts may or may not be ENABLED during this call.
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTimeTickHook (void) reentrant
{
}
#endif
/*
*******************************************************************************
                                OSInitHookBegin()
功能描述: This function is called by OSInit() at the beginning of OSInit().
参    数: none
说    明: 1) Interrupts should be disabled during this call.
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void  OSInitHookBegin (void) reentrant
{
}
#endif
/*
*******************************************************************************
                                OSInitHookEnd()
功能描述: This function is called by OSInit() at the beginning of OSInit().
参    数: none
说    明: 1) Interrupts should be disabled during this call.
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void  OSInitHookEnd (void) reentrant
{
}
#endif
/*
*******************************************************************************
                                OSTCBInitHook()
功能描述: This function is called by OS_TCBInit() after setting up most of the TCB.
参    数: ptcb    is a pointer to the TCB of the task being created.
说    明: 1) Interrupts may or may not be ENABLED during this call.
*******************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void  OSTCBInitHook (OS_TCB *ptcb) reentrant
{
    ptcb = ptcb;                 /* Prevent Compiler warning                 */
}
#endif

⌨️ 快捷键说明

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