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

📄 os_cpu_c.c

📁 MPLAB-uCOS-II-PIC18-V101.操作系统在PIC单片机上的移植
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                               uC/OS-II
*                                         The Real-Time Kernel
*
*                           (c) Copyright 2002, Nathan Brown, Longview, TX
*                                      http://www.sputnickonline.com/
*                                          All Rights Reserved
*
*                                       PIC18xxxx Specific Code
*                                       V1.00 - October 27, 2002
*
* File : OS_CPU_C.C
* By   : Nathan Brown
*********************************************************************************************************
*/

#define  OS_CPU_GLOBALS
#include "includes.h"

/*
*********************************************************************************************************
*                                        INITIALIZE A TASK'S STACK
*
* Description: 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.
*
* Arguments  : task          is a pointer to the task code
*
*              pdata         is a pointer to a user supplied data area that will be passed to the task
*                            when the task first executes.  For the TASKING compiler, 'pdata' is passed
*                            in R1:R0.
*
*              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_???).
*
* Returns    : Always returns the location of the new top-of-stack' once the processor registers have
*              been placed on the stack in the proper order.
*
* Note(s)    : 1) Interrupts are enabled when your task starts executing.
*
*              2) Save the current context onto the stack
*
*              3) The return addresses are in a different stack, so save all of those into the stack
*
*              4) The last stacking operation (before the return) places the number of return stack
*                 items in the software stack.
*********************************************************************************************************
*/

OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
    OS_STK *stk;

    stk     = ptos;                     // local pointer to our new proccess stack
    *stk++  = (OS_STK)*(((INT8U*)&pdata));  // data being passed
    *stk++  = (OS_STK)*(((INT8U*)&pdata)+1);
    *stk++  = 0xFF;                     // <-- FSR1 Pointer position on function call.
    *stk++  = 0x1A;                     // STATUS register
    *stk++  = 0x1B;                     // BSR register
    *stk++  = 0x1C;                     // W register
    *stk++  = 0x1D;                     // FSR0L register
    *stk++  = 0x1E;                     // FSR0H register
    *stk++  = 0x1F;                     // FSR2L register
    *stk++  = 0x2A;                     // FSR2H register
    *stk++  = 0x2B;                     // TBLPTRL Prog Mem Table Pointer Upper
    *stk++  = 0x2C;                     // TBLPTRH Prog Mem Table Pointer High
    *stk++  = 0x2D;                     // TBLPTRU Prog Mem Table Pointer Low
    *stk++  = 0x2E;                     // PRODL Product Reg high
    *stk++  = 0x2F;                     // PRODH Product Reg low
    *stk++  = 0x3A;						// AARGB3
    *stk++  = 0x3B;						// AARGB2
    *stk++  = 0x3C;						// AARGB1
    *stk++  = 0x3D;						// AARGB0

    // first return address, the task address, goes on the hardware return stack in a context switch
    *stk++  = (OS_STK)*(((INT8U*)&task));   // TOSL - Top of stack - Lower bits
    *stk++  = (OS_STK)*(((INT8U*)&task)+1); // TOSH - Top of stack - High bits
    *stk++  = (OS_STK)*(((INT8U*)&task)+2); // TOSU - Top of stack - Uppre bits
    // repeat...

    *stk++  = 0x01;                     // size of return stack

    return ((OS_STK *)stk);             // Return pointer to task's top-of-stack
}

#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)
{
}


/*
*********************************************************************************************************
*                                           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)
{
}

/*
*********************************************************************************************************
*                                           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)
{
	// Clear watch dog timer on context switches.  If enabled, the processor
	// will reset if this does not get called (application frozen).
_asm
	CLRWDT
_endasm
}

/*
*********************************************************************************************************
*                                           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)
{
}



/*
*********************************************************************************************************
*                                           OSTCBInit() HOOK
*
* Description: This function is called by OSTCBInit() after setting up most of the TCB.
*
* Arguments  : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSTCBInitHook(struct os_tcb *ptcb)
{
}
#endif


/*
*********************************************************************************************************
*                                           IDLE TASK HOOK
*
* Description: This function is called by OS_TaskIdle() which is executed whenever no other task is
*              ready to run.  This function can put the CPU to sleep, ready to be woken by an interupt
*              or it can blink a LED to indicate how busy the processor is.
*
* Arguments  : none
*********************************************************************************************************
*/
void OSTaskIdleHook (void)
{
}


/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*                                            (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSInitHookBegin (void)
{
}
#endif

/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*                                               (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSInitHookEnd (void)
{
}
#endif


#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                                       START HIGHEST PRIORITY TASK
*
* Description : This function is called by OSStart() to start the highest priority task that was created
*               by your application before calling OSStart().
*
* Arguments   : none
*
* Note(s)     : 1)  Interupts are disabled when calling.
*
*               2) The stack frame (8-bit wide stack) is assumed to look as follows:
*
*                                                                                          LOW MEMORY
*                                           -   23      pdata (lower 8 bits)
*                                           -   22      pdata (upper 8 bits)
*                                           -   21      XX (pointed to by FSR1, frame pointer)
*                                           -   20      STATUS  register
*                                           -   19      BSR     register
*                                           -   18      W       register
*                                           -   17      FSR0L   register
*                                           -   16      FSR0H   register
*                                           -   15      FSR2L   register (frame pointer, low)
*                                           -   14      FSR2H   register (frame pointer, high)
*                                           -   13      TBLPTRL register
*                                           -   12      TBLPTRH register
*                                           -   11      TBLPTRU register
*                                           -   10      PRODL   register

⌨️ 快捷键说明

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