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

📄 os_core.s43

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 S43
📖 第 1 页 / 共 5 页
字号:
	NAME	os_core(16)
	RSEG	CODE(1)
	RSEG	CONST(1)
	RSEG	UDATA0(1)
	PUBLIC	OSCPUUsage
	EXTERN	OSCtxSw
	PUBLIC	OSCtxSwCtr
	PUBLIC	OSEventFreeList
	PUBLIC	OSEventTbl
	PUBLIC	OSFlagFreeList
	PUBLIC	OSFlagTbl
	PUBLIC	OSIdleCtr
	PUBLIC	OSIdleCtrMax
	PUBLIC	OSIdleCtrRun
	PUBLIC	OSInit
	EXTERN	OSInitHookBegin
	EXTERN	OSInitHookEnd
	EXTERN	OSIntCtxSw
	PUBLIC	OSIntEnter
	PUBLIC	OSIntExit
	PUBLIC	OSIntExitY
	PUBLIC	OSIntNesting
	PUBLIC	OSLockNesting
	PUBLIC	OSMapTbl
	PUBLIC	OSMemFreeList
	PUBLIC	OSMemTbl
	PUBLIC	OSPrioCur
	PUBLIC	OSPrioHighRdy
	PUBLIC	OSQFreeList
	PUBLIC	OSQTbl
	PUBLIC	OSRdyGrp
	PUBLIC	OSRdyTbl
	PUBLIC	OSRunning
	PUBLIC	OSSchedLock
	PUBLIC	OSSchedUnlock
	PUBLIC	OSStart
	EXTERN	OSStartHighRdy
	PUBLIC	OSStatInit
	PUBLIC	OSStatRdy
	PUBLIC	OSTCBCur
	PUBLIC	OSTCBFreeList
	PUBLIC	OSTCBHighRdy
	EXTERN	OSTCBInitHook
	PUBLIC	OSTCBList
	PUBLIC	OSTCBPrioTbl
	PUBLIC	OSTCBTbl
	EXTERN	OSTaskCreateExt
	EXTERN	OSTaskCreateHook
	PUBLIC	OSTaskCtr
	EXTERN	OSTaskIdleHook
	PUBLIC	OSTaskIdleStk
	EXTERN	OSTaskStatHook
	PUBLIC	OSTaskStatStk
	PUBLIC	OSTime
	EXTERN	OSTimeDly
	PUBLIC	OSTimeTick
	EXTERN	OSTimeTickHook
	PUBLIC	OSUnMapTbl
	PUBLIC	OSVersion
	PUBLIC	OS_Dummy
	PUBLIC	OS_EventTO
	PUBLIC	OS_EventTaskRdy
	PUBLIC	OS_EventTaskWait
	PUBLIC	OS_EventWaitListInit
	EXTERN	OS_FlagInit
	EXTERN	OS_MemInit
	EXTERN	OS_QInit
	PUBLIC	OS_Sched
	PUBLIC	OS_TCBInit
	PUBLIC	OS_TaskIdle
	PUBLIC	OS_TaskStat
	EXTERN	?CL430_1_26_L08
	EXTERN	?UL_DIVMOD_L03
	RSEG	CODE
OSInit:
; 1.	/*
; 2.	*********************************************************************************************************
; 3.	*                                                uC/OS-II
; 4.	*                                          The Real-Time Kernel
; 5.	*                                             CORE FUNCTIONS
; 6.	*
; 7.	*                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; 8.	*                                           All Rights Reserved
; 9.	*
; 10.	* File : OS_CORE.C
; 11.	* By   : Jean J. Labrosse
; 12.	*********************************************************************************************************
; 13.	*/
; 14.	
; 15.	#ifndef  OS_MASTER_FILE
; 16.	#define  OS_GLOBALS
; 17.	#include "includes.h"
; 18.	#endif
; 19.	
; 20.	/*
; 21.	*********************************************************************************************************
; 22.	*                              MAPPING TABLE TO MAP BIT POSITION TO BIT MASK
; 23.	*
; 24.	* Note: Index into table is desired bit position, 0..7
; 25.	*       Indexed value corresponds to bit mask
; 26.	*********************************************************************************************************
; 27.	*/
; 28.	
; 29.	INT8U  const  OSMapTbl[]   = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
; 30.	
; 31.	/*
; 32.	*********************************************************************************************************
; 33.	*                                       PRIORITY RESOLUTION TABLE
; 34.	*
; 35.	* Note: Index into table is bit pattern to resolve highest priority
; 36.	*       Indexed value corresponds to highest priority bit position (i.e. 0..7)
; 37.	*********************************************************************************************************
; 38.	*/
; 39.	
; 40.	INT8U  const  OSUnMapTbl[] = {
; 41.	    0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x00 to 0x0F                             */
; 42.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x10 to 0x1F                             */
; 43.	    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x20 to 0x2F                             */
; 44.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x30 to 0x3F                             */
; 45.	    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x40 to 0x4F                             */
; 46.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x50 to 0x5F                             */
; 47.	    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x60 to 0x6F                             */
; 48.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x70 to 0x7F                             */
; 49.	    7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x80 to 0x8F                             */
; 50.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x90 to 0x9F                             */
; 51.	    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xA0 to 0xAF                             */
; 52.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xB0 to 0xBF                             */
; 53.	    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xC0 to 0xCF                             */
; 54.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xD0 to 0xDF                             */
; 55.	    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xE0 to 0xEF                             */
; 56.	    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0        /* 0xF0 to 0xFF                             */
; 57.	};
; 58.	
; 59.	/*
; 60.	*********************************************************************************************************
; 61.	*                                       FUNCTION PROTOTYPES
; 62.	*********************************************************************************************************
; 63.	*/
; 64.	static  void  OS_InitEventList(void);
; 65.	static  void  OS_InitMisc(void);
; 66.	static  void  OS_InitRdyList(void);
; 67.	static  void  OS_InitTaskIdle(void);
; 68.	static  void  OS_InitTaskStat(void);
; 69.	static  void  OS_InitTCBList(void);
; 70.	
; 71.	/*$PAGE*/
; 72.	/*
; 73.	*********************************************************************************************************
; 74.	*                                             INITIALIZATION
; 75.	*
; 76.	* Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
; 77.	*              creating any uC/OS-II object and, prior to calling OSStart().
; 78.	*
; 79.	* Arguments  : none
; 80.	*
; 81.	* Returns    : none
; 82.	*********************************************************************************************************
; 83.	*/
; 84.	
; 85.	void  OSInit (void)
; 86.	{
; 87.	#if OS_VERSION >= 204
; 88.	    OSInitHookBegin();                                           /* Call port specific initialization code   */
	CALL	#OSInitHookBegin	
; 89.	#endif
; 90.	
; 91.	    OS_InitMisc();                                               /* Initialize miscellaneous variables       */
	CALL	#OS_InitMisc	
; 92.	
; 93.	    OS_InitRdyList();                                            /* Initialize the Ready List                */
	CALL	#OS_InitRdyList	
; 94.	    OS_InitTCBList();                                            /* Initialize the free list of OS_TCBs      */
	CALL	#OS_InitTCBList	
; 95.	    OS_InitEventList();                                          /* Initialize the free list of OS_EVENTs    */
	CALL	#OS_InitEventList	
; 96.	
; 97.	#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
; 98.	    OS_FlagInit();                                               /* Initialize the event flag structures     */
	CALL	#OS_FlagInit	
; 99.	#endif
; 100.	
; 101.	#if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
; 102.	    OS_MemInit();                                                /* Initialize the memory manager            */
	CALL	#OS_MemInit	
; 103.	#endif
; 104.	
; 105.	#if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
; 106.	    OS_QInit();                                                  /* Initialize the message queue structures  */
	CALL	#OS_QInit	
; 107.	#endif
; 108.	
; 109.	    OS_InitTaskIdle();                                           /* Create the Idle Task                     */
	CALL	#OS_InitTaskIdle	
; 110.	#if OS_TASK_STAT_EN > 0
; 111.	    OS_InitTaskStat();                                           /* Create the Statistic Task                */
	CALL	#OS_InitTaskStat	
; 112.	#endif
; 113.	
; 114.	#if OS_VERSION >= 204
; 115.	    OSInitHookEnd();                                             /* Call port specific init. code            */
	CALL	#OSInitHookEnd	
; 116.	#endif
; 117.	}
	RET		
OSIntEnter:
; 118.	/*$PAGE*/
; 119.	/*
; 120.	*********************************************************************************************************
; 121.	*                                              ENTER ISR
; 122.	*
; 123.	* Description: This function is used to notify uC/OS-II that you are about to service an interrupt
; 124.	*              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
; 125.	*              only perform rescheduling at the last nested ISR.
; 126.	*
; 127.	* Arguments  : none
; 128.	*
; 129.	* Returns    : none
; 130.	*
; 131.	* Notes      : 1) This function should be called ith interrupts already disabled
; 132.	*              2) Your ISR can directly increment OSIntNesting without calling this function because
; 133.	*                 OSIntNesting has been declared 'global'.  
; 134.	*              3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
; 135.	*              4) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
; 136.	*                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
; 137.	*                 end of the ISR.
; 138.	*              5) You are allowed to nest interrupts up to 255 levels deep.
; 139.	*              6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
; 140.	*                 OSIntEnter() is always called with interrupts disabled.
; 141.	*********************************************************************************************************
; 142.	*/
; 143.	
; 144.	void  OSIntEnter (void)
; 145.	{
; 146.	    if (OSRunning == TRUE) {
	CMP.B	#1,&OSRunning	
	JNE	(?0065)	
; 147.	        if (OSIntNesting < 255) {
	CMP.B	#255,&OSIntNesting	
	JC	(?0065)	
; 148.	            OSIntNesting++;                      /* Increment ISR nesting level                        */
	ADD.B	#1,&OSIntNesting	
?0065:
; 149.	        }
; 150.	    }
; 151.	}
	RET		
OSIntExit:
; 152.	/*$PAGE*/
; 153.	/*
; 154.	*********************************************************************************************************
; 155.	*                                               EXIT ISR
; 156.	*
; 157.	* Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
; 158.	*              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
; 159.	*              a new, high-priority task, is ready to run.
; 160.	*
; 161.	* Arguments  : none
; 162.	*
; 163.	* Returns    : none
; 164.	*
; 165.	* Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
; 166.	*                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
; 167.	*                 end of the ISR.
; 168.	*              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
; 169.	*********************************************************************************************************
; 170.	*/
; 171.	
; 172.	void  OSIntExit (void)
; 173.	{
; 174.	#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
; 175.	    OS_CPU_SR  cpu_sr;
; 176.	#endif
; 177.	    
; 178.	    
; 179.	    if (OSRunning == TRUE) {
	CMP.B	#1,&OSRunning	
	JNE	(?0067)	
; 180.	        OS_ENTER_CRITICAL();
	DINT		
; 181.	        if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping       */
	CMP.B	#0,&OSIntNesting	
	JEQ	(?0069)	
; 182.	            OSIntNesting--;
	ADD.B	#-1,&OSIntNesting	
?0069:
; 183.	        }
; 184.	        if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Reschedule only if all ISRs complete ... */
	CMP.B	#0,&OSIntNesting	
	JNE	(?0075)	
	CMP.B	#0,&OSLockNesting	
	JNE	(?0075)	
; 185.	            OSIntExitY    = OSUnMapTbl[OSRdyGrp];          /* ... and not locked.                      */
	MOV.B	&OSRdyGrp,R12	
	MOV.B	OSUnMapTbl(R12),&OSIntExitY	
; 186.	            OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
	MOV.B	&OSIntExitY,R12	
	MOV.B	OSRdyTbl(R12),R12	
	MOV.B	&OSIntExitY,R13	
	ADD.B	R13,R13	
	ADD.B	R13,R13	
	ADD.B	R13,R13	
	ADD.B	OSUnMapTbl(R12),R13	
	MOV.B	R13,&OSPrioHighRdy	
; 187.	            if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy */
	CMP.B	&OSPrioHighRdy,&OSPrioCur	
	JEQ	(?0075)	
; 188.	                OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
	MOV.B	&OSPrioHighRdy,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),&OSTCBHighRdy	
; 189.	                OSCtxSwCtr++;                              /* Keep track of the number of ctx switches */
	ADD	#1,&OSCtxSwCtr	
	ADDC	#0,&(OSCtxSwCtr+2)	
; 190.	                OSIntCtxSw();                              /* Perform interrupt level ctx switch       */
	CALL	#OSIntCtxSw	
?0075:
; 191.	            }
; 192.	        }
; 193.	        OS_EXIT_CRITICAL();
	EINT		
?0067:
; 194.	    }
; 195.	}
	RET		

⌨️ 快捷键说明

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