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

📄 kernellib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* kernelLib.c - VxWorks kernel library *//* Copyright 1984-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02n,13may02,cyr  update round-robin scheduling documentation section02m,09nov01,jhw  Revert WDB_INFO to be inside WIND_TCB.02l,27oct01,jhw  Set pTcb->pWdbInfo to NULL for the root task.02k,11oct01,cjj  updated kernel version to 2.6.  Removed Am29k support.02j,10apr00,hk   put SH interrupt stack in same space to VBR. use the original                 vxIntStackBase and removed sysIntStackSpace reference for SH.02i,03mar00,zl   merged SH support into T202h,24feb98,dbt  initialize activeQHead to be able to dectect from a host tool                 if the OS is multitasking02h,28nov96,cdp  added ARM support.02g,02oct96,p_m  set version number to 2.5.02f,07jul94,tpr  added MC68060 cpu support.02g,26apr94,hdn  added a int stack alloc to make checkStack() work for I80X86.02f,09jun93,hdn  added a support for I80X8602f,02dec93,pme  added Am29K family support with 512 bytes aligned 		 interrupt stack.02e,20jan93,jdi  documentation cleanup for 5.1.02d,23aug92,jcf  changed bzero to bfill.02c,12jul92,jcf  cleaned up padding around root task's tcb.02b,07jul92,rrr  added pad around the root task's tcb and stack so that                 memAddToPool (called in taskDestroy) woundn't clobber the tcb.02a,04jul92,jcf  moved most of kernelInit to usrInit.		 changed the way root task is initialized to avoid excJobAdd.		 removed kernelRoot().01w,26may92,rrr  the tree shuffle01v,21may92,yao  added bzero of initTcb for all architectures (spr 1272).01u,18mar92,yao  removed conditional definition for STACK_GROWS_DOWN/UP.		 removed macro MEM_ROUND_UP.  removed unused sentinel[].		 changed copyright notice.  removed bzero of initTcb for		 I960.  changed not to carve interrupt stack for MC680{0,1}0.01t,23oct91,wmd  fixed bug in kernelInit() to compensate for pumped up stack		 size for i960.01s,04oct91,rrr  passed through the ansification filter                  -changed functions to ansi style		  -fixed #else and #endif		  -changed VOID to void		  -changed copyright notice01r,26sep91,jwt  added code to 8-byte align input address parameters.01q,21aug91,ajm  added MIPS support.01p,14aug91,del  padded excJobAdd, qInit, and taskInit calls with 0's.01o,17jun91,del  added bzero of initTcb for I960.01n,23may91,jwt  forced 8-byte alignment of stack for SPARC and other RISCs.01m,26apr91,hdn  added conditional checks for TRON family of processors.01l,05apr91,jdi	 documentation -- removed header parens and x-ref numbers;		 doc review by jcf.01k,25mar91,del  I960 needs init stack base aligned.01j,08feb91,jaa	 documentation cleanup.01i,30sep90,jcf  added kernelRootCleanup, to reclaim root task memory safely.01h,28aug90,jcf  documentation.01g,09jul90,dnw  added initialization of msg queue class		 deleted include of qPriHeapLib.h01f,05jul90,jcf  added STACK_GROWS_XXX to resolve stack growth direction issues.		 reworked object initialization.		 timer queue is now a simple linked list.		 added room for MEM_TAG at beginning of root task memory.01e,26jun90,jcf  changed semaphore object initialization.		 changed topOfStack to endOfStack.01d,28aug89,jcf  modified to wind version 2.0.01c,21apr89,jcf  added kernelType.01b,23aug88,gae  documentation.01a,19jan88,jcf  written.*//*DESCRIPTIONThe VxWorks kernel provides tasking control services to an application.  Thelibraries kernelLib, taskLib, semLib, tickLib, and wdLib comprise the kernelfunctionality.  This library is the interface to the VxWorks kernelinitialization, revision information, and scheduling control.KERNEL INITIALIZATIONThe kernel must be initialized before any other kernel operation isperformed.  Normally kernel initialization is taken care of by the systemconfiguration code in usrInit() in usrConfig.c.Kernel initialization consists of the following:.IP "(1)" 4Defining the starting address and size of the system memory partition.The malloc() routine uses this partition to satisfy memory allocationrequests of other facilities in VxWorks..IP "(2)"Allocating the specified memory size for an interrupt stack.  Interruptservice routines will use this stack unless the underlying architecturedoes not support a separate interrupt stack, in which case the serviceroutine will use the stack of the interrupted task..IP "(3)"Specifying the interrupt lock-out level.  VxWorks will not exceed thespecified level during any operation.  The lock-out level is normallydefined to mask the highest priority possible.  However, in situationswhere extremely low interrupt latency is required, the lock-out level maybe set to ensure timely response to the interrupt in question.  Interruptservice routines handling interrupts of priority greater than theinterrupt lock-out level may not call any VxWorks routine..LPOnce the kernel initialization is complete, a root task is spawned withthe specified entry point and stack size.  The root entry point is normallyusrRoot() of the usrConfig.c module.  The remaining VxWorks initializationtakes place in usrRoot().ROUND-ROBIN SCHEDULINGRound-robin scheduling allows the processor to be shared fairly by all tasksof the same priority.  Without round-robin scheduling, when multiple tasks ofequal priority must share the processor, a single non-blocking task can usurpthe processor until preempted by a task of higher priority, thus never givingthe other equal-priority tasks a chance to run.Round-robin scheduling is disabled by default.  It can be enabled ordisabled with the routine kernelTimeSlice(), which takes a parameter forthe "time slice" (or interval) that each task will be allowed to runbefore relinquishing the processor to another equal-priority task.  If theparameter is zero, round-robin scheduling is turned off.  If round-robinscheduling is enabled and preemption is enabled for the executing task,the system tick handler will increment the task's time-slice count.When the specified time-slice interval is completed, the system tickhandler clears the counter and the task is placed at the tail of the listof tasks at its priority.  New tasks joining a given priority group areplaced at the tail of the group with a run-time counter initialized to zero.Enabling round-robin scheduling does not affect the performance of taskcontext switches, nor is additional memory allocated.If a task blocks or is preempted by a higher priority task during itsinterval, it's time-slice count is saved and then restored when the taskis eligible for execution.  In the case of preemption, the task willresume execution once the higher priority task completes, assuming noother task of a higher priority is ready to run.  For the case when thetask blocks, it is placed at the tail of the list of tasks at its priority.If preemption is disabled during round-robin scheduling, the time-slicecount of the executing task is not incremented.Time-slice counts are accrued against the task that is executing when a systemtick occurs regardless of whether the task has executed for the entire tickinterval.  Due to preemption by higher priority tasks or ISRs stealing CPUtime from the task, scenarios exist where a task can execute for less or moretotal CPU time than it's allotted time slice.INCLUDE FILES: kernelLib.hSEE ALSO: taskLib, intLib,.pG "Basic OS"*/#include "vxWorks.h"#include "tickLib.h"#include "memLib.h"#include "qLib.h"#include "string.h"#include "intLib.h"#include "qPriBMapLib.h"#include "classLib.h"#include "semLib.h"#include "wdLib.h"#include "msgQLib.h"#include "private/kernelLibP.h"#include "private/windLibP.h"#include "private/workQLibP.h"#include "private/taskLibP.h"#include "private/memPartLibP.h"#if (CPU==SH7750 || CPU==SH7729 || CPU==SH7700)#include "cacheLib.h"#endif/* macros */#define WIND_TCB_SIZE		((unsigned) STACK_ROUND_UP (sizeof(WIND_TCB)))#define MEM_BLOCK_HDR_SIZE	((unsigned) STACK_ROUND_UP (sizeof(BLOCK_HDR)))#define MEM_FREE_BLOCK_SIZE	((unsigned) STACK_ROUND_UP (sizeof(FREE_BLOCK)))#define MEM_BASE_BLOCK_SIZE	(MEM_BLOCK_HDR_SIZE + MEM_FREE_BLOCK_SIZE)#define MEM_END_BLOCK_SIZE	(MEM_BLOCK_HDR_SIZE)#define MEM_TOT_BLOCK_SIZE	((2 * MEM_BLOCK_HDR_SIZE) + MEM_FREE_BLOCK_SIZE)/* global variables */char *    vxIntStackEnd;		/* end of interrupt stack */char *	  vxIntStackBase;		/* base of interrupt stack */char *	  pRootMemStart;		/* bottom of root task's stack */unsigned  rootMemNBytes;		/* memory for TCB and root stack */int 	  rootTaskId;			/* root task ID */BOOL	  roundRobinOn;			/* boolean reflecting round robin mode*/ULONG	  roundRobinSlice;		/* round robin slice in ticks */Q_HEAD	  activeQHead = {NULL,0,0,NULL};/* multi-way active queue head */Q_HEAD	  tickQHead;			/* multi-way tick queue head */Q_HEAD	  readyQHead;			/* multi-way ready queue head */#if     (CPU_FAMILY == ARM)char *    vxSvcIntStackBase;            /* base of SVC-mode interrupt stack */char *    vxSvcIntStackEnd;             /* end of SVC-mode interrupt stack */char *    vxIrqIntStackBase;            /* base of IRQ-mode interrupt stack */char *    vxIrqIntStackEnd;             /* end of IRQ-mode interrupt stack */VOIDFUNCPTR _func_armIntStackSplit = NULL;      /* ptr to fn to split stack */#endif  /* (CPU_FAMILY == ARM) *//********************************************************************************* kernelInit - initialize the kernel** This routine initializes and starts the kernel.  It should be called only* once.  The parameter <rootRtn> specifies the entry point of the user's* start-up code that subsequently initializes system facilities (i.e., the* I/O system, network).  Typically, <rootRtn> is set to usrRoot().** Interrupts are enabled for the first time after kernelInit() exits.* VxWorks will not exceed the specified interrupt lock-out level during any* of its brief uses of interrupt locking as a means of mutual exclusion.** The system memory partition is initialized by kernelInit() with the size* set by <pMemPoolStart> and <pMemPoolEnd>.  Architectures that support a* separate interrupt stack allocate a portion of memory for this* purpose, of <intStackSize> bytes starting at <pMemPoolStart>.** NOTE SH77XX:* The interrupt stack is emulated by software, and it has to be located in* a fixed physical address space (P1 or P2) if the on-chip MMU is enabled.* If <pMemPoolStart> is in a logical address space (P0 or P3), the interrupt* stack area is reserved on the same logical address space.  The actual* interrupt stack is relocated to a fixed physical space pointed by VBR.** INTERNAL* The routine kernelRoot() is called before the user's root routine so that* memory management can be initialized.  The memory setup is as follows:** For _STACK_GROWS_DOWN:** .CS*	  - HIGH MEMORY -*     ------------------------ <--- pMemPoolEnd*     |                      |  We have to leave room for this block headers*     |     1 BLOCK_HDR      |	so we can add the root task memory to the pool.*     |                      |*     ------------------------*     |                      |   *     |       WIND_TCB       |*     |                      |*     ------------------------ <--- pRootStackBase;*     |                      |*     |      ROOT STACK      |*     |                      |*     ------------------------*     |                      |  We have to leave room for these block headers*     |     1 FREE_BLOCK     |	so we can add the root task memory to the pool.*     |     1 BLOCK_HDR      |*     |                      |*     ------------------------ <--- pRootMemStart;*     ------------------------*     |                      |

⌨️ 快捷键说明

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