/*
************************************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
*
* (c) Copyright 2009, Micrium, Weston, FL
* All Rights Reserved
* www.Micrium.com
*
* CORE FUNCTIONS
*
* File : OS_CORE.C
* By : JJL
* Version : V3.00.4
*
* LICENSING TERMS:
* ---------------
* uC/OS-III is provided in source form to registered licensees. It is illegal to distribute this source
* code to any third party unless you receive written permission by an authorized Micrium officer.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest software available. Your
* honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
************************************************************************************************************************
*/
#include <os.h>
/*
************************************************************************************************************************
* INITIALIZATION
*
* Description: This function is used to initialize the internals of uC/OS-III and MUST be called prior to
* creating any uC/OS-III object and, prior to calling OS_Start().
*
* Arguments : p_err is a pointer to a variable that will contain an error code returned by this function.
*
* OS_ERR_NONE Initialization was successful
* Other Other OS_ERR_xxx depending on the sub-functions called by OSInit().
* Returns : none
************************************************************************************************************************
*/
void OSInit (OS_ERR *p_err)
{
CPU_STK *p_stk;
OS_STK_SIZE size;
#ifdef OS_SAFETY_CRITICAL_RELEASE
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
}
#endif
OSIntNestingCtr = (OS_NESTING_CTR)0; /* Clear the interrupt nesting counter */
OSRunning = OS_STATE_OS_STOPPED; /* Indicate that multitasking not started */
OSSchedLockNestingCtr = (OS_NESTING_CTR)0; /* Clear the scheduling lock counter */
#if OS_CFG_SCHED_ROUND_ROBIN_EN > 0u
OSSchedRoundRobinEn = DEF_FALSE;
OSSchedRoundRobinDfltTimeQuanta = OSCfg_TickRate_Hz / 10u;
#endif
if (OSCfg_ISRStkSize > (OS_STK_SIZE)0) {
p_stk = OSCfg_ISRStkBasePtr; /* Clear exception stack for stack checking. */
if (p_stk != (CPU_STK *)0) {
size = OSCfg_ISRStkSize;
while (size > (OS_STK_SIZE)0) {
size--;
*p_stk = (CPU_STK)0;
p_stk++;
}
}
}
#if OS_CFG_APP_HOOKS_EN > 0u
OS_AppTaskCreateHookPtr = (OS_APP_HOOK_TCB )0; /* Clear application hook pointers */
OS_AppTaskDelHookPtr = (OS_APP_HOOK_TCB )0;
OS_AppTaskReturnHookPtr = (OS_APP_HOOK_TCB )0;
OS_AppIdleTaskHookPtr = (OS_APP_HOOK_VOID)0;
OS_AppStatTaskHookPtr = (OS_APP_HOOK_VOID)0;
OS_AppTaskSwHookPtr = (OS_APP_HOOK_VOID)0;
OS_AppTimeTickHookPtr = (OS_APP_HOOK_VOID)0;
#endif
OS_PrioInit(); /* Initialize the priority bitmap table */
OS_RdyListInit(); /* Initialize the Ready List */
OS_TaskInit(p_err); /* Initialize the task manager */
if (*p_err != OS_ERR_NONE) {
return;
}
OS_IdleTaskInit(p_err); /* Initialize the Idle Task */
if (*p_err != OS_ERR_NONE) {
return;
}
#if OS_CFG_ISR_POST_DEFERRED_EN > 0u
OS_IntQTaskInit(p_err); /* Initialize the Interrupt Queue Handler Task */
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
OS_TickTaskInit(p_err); /* Initialize the Tick Task */
if (*p_err != OS_ERR_NONE) {
return;
}
#if OS_CFG_STAT_TASK_EN > 0u /* Initialize the Statistic Task */
OS_StatTaskInit(p_err);
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if OS_CFG_FLAG_EN > 0u /* Initialize the Event Flag module */
OS_FlagInit(p_err);
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if OS_CFG_MEM_EN > 0u /* Initialize the Memory Manager module */
OS_MemInit(p_err);
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if (OS_MSG_EN) > 0u /* Initialize the free list of OS_MSGs */
OS_MsgPoolInit(p_err);
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if OS_CFG_MUTEX_EN > 0u /* Initialize the Mutex Manager module */
OS_MutexInit(p_err);
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if OS_CFG_Q_EN > 0u
OS_QInit(p_err); /* Initialize the Message Queue Manager module */
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if OS_CFG_SEM_EN > 0u /* Initialize the Semaphore Manager module */
OS_SemInit(p_err);
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if OS_CFG_TMR_EN > 0u /* Initialize the Timer Manager module */
OS_TmrInit(p_err);
if (*p_err != OS_ERR_NONE) {
return;
}
#endif
#if OS_CFG_DBG_EN > 0u
OS_Dbg_Init();
#endif
OSInitHook(); /* Call port specific initialization code */
OSCfg_Init();
}
/*$PAGE*/
/*
************************************************************************************************************************
* ENTER ISR
*
* Description: This function is used to notify uC/OS-III that you are about to service an interrupt service routine
* (ISR). This allows uC/OS-III to keep track of interrupt nesting and thus only perform rescheduling at
* the last nested ISR.
*
* Arguments : none
*
* Returns : none
*
* Note(s) : 1) This function MUST be called with interrupts already disabled
*
* 2) Your ISR can directly increment 'OSIntNestingCtr' without calling this function because OSIntNestingCtr has
* been declared 'global', the port is actually considered part of the OS and thus is allowed to access
* uC/OS-III variables.
*
* 3) You MUST still call OSIntExit() even though you increment 'OSIntNestingCtr' directly.
*
* 4) You MUST inv
ucos 3.00.4源码
需积分: 10 69 浏览量
2011-07-29
21:40:05
上传
评论
收藏 107KB RAR 举报
ounie
- 粉丝: 3
- 资源: 44