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

📄 os_cpu_c.c

📁 uc_os II__PIC24fj128ga010
💻 C
字号:
/*
*********************************************************************************************************
*                               				uC/OS-II
*                          				  The Real-Time Kernel
*
*                  				(c) Copyright 2006, Micrium, Weston, FL
*                            			All Rights Reserved
*
*
*                                     PIC24FJ128GA010 MPLab Port
*
*
* File : OS_CPU_C.C
* By : 不负责任的天使(^_^)
* Port Version : V2.51 
*********************************************************************************************************
*/

#ifndef  OS_MASTER_FILE
#include "includes.h"
#endif
#include    <p24fj128ga010.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
*
* 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_).
*
* 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) You may pass a task creation parameters through the opt variable. You MUST only use the
* upper 8 bits of 'opt' because the lower bits are reserved by uC/OS-II. If you make
* changes to the code below, you will need to ensure that it doesn't affect the behaviour
* of OSTaskIdle() and OSTaskStat().
* 2) Registers are initialized to make them easy to differentiate with a debugger.
*
* 3) Setup the stack frame of the task:
*
* ptos - 0  -> PC (15..0)
* ptos - 2  -> PC (22..16)     Simulate function call
* ptos - 4  -> PC (15..0)
* ptos - 6  -> 0 (15..8) | CORCON.IPL3 | PC (22..16)Simulate SR
* ptos - 8  -> p_arg
* ptos - 10 -> W1
* ptos - 12 -> W2
* ptos - 14 -> W3
* ptos - 16 -> W4
* ptos - 18 -> W5
* ptos - 20 -> W6
* ptos - 22 -> W7
* ptos - 24 -> W8
* ptos - 26 -> W9
* ptos - 28 -> W10
* ptos - 30 -> W11
* ptos - 32 -> W12
* ptos - 34 -> W13
* ptos - 36 -> W14
* ptos - 38 -> TBLPAG
* ptos - 40 -> PSVPAG
* ptos - 42 -> RCOUNT
* ptos - 44 -> SR (initialized to 0)
* ptos - 46 -> CORCON
* ptos - 48 -> 

注释:由于RETFIE中断返回函数工作过程如下
(W15)-2 ->W15
(TOS<15:8>)->(SR<7:0>)
(TOS<7>)->(IPL3,CORCON<3>)
(TOS<6:0>)->(PC<22:16>)
(W15)-2 ->W15
(TOS<15:0>)->(PC<15:0>)
*********************************************************************************************************
*/

OS_STK *OSTaskStkInit (void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT16U opt)
{
	INT16U  x;
	INT8U   pc_high;
	
	pc_high =   0;                                                       /* Upper byte of PC always 0. Pointers are 16 bit unsigned  */
	
	*ptos++  =  (OS_STK)task;                                            /* Simulate a call to the task by putting 32 bits of data   */
	*ptos++  =  (OS_STK)pc_high;                                         /* data on the stack.                                       */
	
	 	                                                                 /* Simulate an interrupt                                    */
	*ptos++  =  (OS_STK)task;                                            /* Put the address of this task on the stack (PC)           */
	
	x       =  0;                                                      	 /* Set the SR to enable ALL interrupts                      */                       
	if (CORCONbits.IPL3) {                                               /* Check the CPU's current interrupt level 3 bit            */
	   x  |= 0x0080;                                                     /* If set, then save the priority level bit in x bit [7]    */
	}
	*ptos++  = (OS_STK)(x | (INT16U)pc_high);                            /* Push the SR Low, CORCON IPL3 and PC (22..16)             */
	
	/* Push all of the registers to stack */
	p_arg  = p_arg;            			/*出现警告为了编译器 */
	*ptos++ = 0x0000;					/*Initialize register W0 */
	*ptos++ = 0x1111;                   /*Initialize register W1 */
	*ptos++ = 0x2222;                   /*Initialize register W2 */
	*ptos++ = 0x3333;     			    /*Initialize register W3 */
	*ptos++ = 0x4444; 					/*Initialize register W4 */
	*ptos++ = 0x5555; 					/*Initialize register W5 */
	*ptos++ = 0x6666; 					/*Initialize register W6 */
	*ptos++ = 0x7777; 					/*Initialize register W7 */
	*ptos++ = 0x8888; 					/*Initialize register W8 */
	*ptos++ = 0x9999; 					/*Initialize register W9 */
	*ptos++ = 0xAAAA; 					/*Initialize register W10 */
	*ptos++ = 0xBBBB; 					/*Initialize register W11 */
	*ptos++ = 0xCCCC; 					/*Initialize register W12 */
	*ptos++ = 0xDDDD; 					/*Initialize register W13 */
	*ptos++ = 0xEEEE; 					/*Initialize register W14 */
	
	*ptos++ = TBLPAG; 				/* Push the Data Table Page Address onto the stack */
	*ptos++ = PSVPAG; 				/* Push the Program Space Visability Register on the stack */
	*ptos++ = RCOUNT; 				/* Push the Repeat Loop Counter Register onto the stack */
	
	*ptos++ = 0; 					/* Force the SR to enable all interrupt, clear flags */
	*ptos++ = CORCON; 				/* Push the Core Control Register on to the stack */
	
	return (ptos); 					/* Return the stack pointer to the new tasks stack */
}




#if OS_CPU_HOOKS_EN

void OSTaskCreateHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}


void OSTaskDelHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}


void OSTaskSwHook (void)
{
}

void OSTaskIdleHook(void)
{
  
 /* printf("This is Idletask.\n");  
  printf("OSIdleCtr is %ld\n",OSIdleCtr); */
}
void OSTaskStatHook (void)
{
}


void OSTimeTickHook (void)
{
}
void OSInitHookBegin(void)
{
}
void OSInitHookEnd(void)
{
}

void OSTCBInitHook(OS_TCB *ptcb)
{
  ptcb=ptcb;
}
#endif     


⌨️ 快捷键说明

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