Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Initializes µC/OS-III and it must be called prior to calling any other µC/OS-III function. Including Including OSStart() which  which will start multitasking. OSInit() returns  returns as soon as an error is detected.

Files

os.h/os_core.c

Prototype

Code Block
void  OSInit (OS_ERR *p_err);

Arguments

p_cfgerr

is a pointer to a OS_CFG structure. See Note #3 below for a description of OS_CFG. To support the old os_cfg_app.h scheme, p_cfg can be DEF_NULL if OS_CFG_COMPAT_INIT_EN is equal to DEF_ENABLED.

p_mem_seg

is a pointer to a MEM_SEG structure. This segment will be used to allocate the kernel objects. Can be DEF_NULL to allocate objects on the heap.

p_err

is a pointer to an error code. Some of the error codes below are issued only if the associated feature is enabled.

RTOS_ERR_NONE

initialization was successful.

*NEED TO COMPLETE*an error code. Some of the error codes below are issued only if the associated feature is enabled.

OS_ERR_NONE

initialization was successful.

OS_ERR_INT_Q

If OS_CFG_ISR_POST_DEFERRED_EN is set to DEF_ENABLED in os_cfg.hOSCfg_IntQBasePtr is NULL. The error is detected by OS_IntQTaskInit() in os_int.c.

OS_ERR_INT_Q_SIZE

If OS_CFG_ISR_POST_DEFERRED_EN is set to DEF_ENABLED  in os_cfg.hOSCfg_IntQSize must have at least 2 elements. The error is detected by OS_IntQTaskInit() in os_int.c.

OS_ERR_INT_Q_STK_INVALID

If OS_CFG_ISR_POST_DEFERRED_EN is set to DEF_ENABLED  in os_cfg.hOSCfg_IntQTaskStkBasePtr is NULL. The error is detected by OS_IntQTaskInit() in os_int.c

OS_ERR_INT_Q_STK_SIZE_INVALID

If OS_CFG_ISR_POST_DEFERRED_EN is set to DEF_ENABLED  in os_cfg.hOSCfg_IntQTaskStkSize is less than OSCfg_StkSizeMin. The error is detected by OS_IntQTaskInit() in os_int.c.

OS_ERR_MSG_POOL_EMPTY

If OS_CFG_ARG_CHK_EN and OS_CFG_Q_EN or OS_CFG_TASK_Q_EN are set to DEF_ENABLED  in os_cfg.h: OSCfg_MsgPoolSize is zero. The error is detected by OS_MsgPoolInit() in os_msg.c.

OS_ERR_MSG_POOL_NULL_PTR

If OS_CFG_ARG_CHK_EN and OS_CFG_Q_EN or OS_CFG_TASK_Q_EN are set to DEF_ENABLED  in os_cfg.h: OSCfg_MsgPoolBasePtr is NULL in os_msg.c. The error is detected by OS_MsgPoolInit() in os_msg.c.

OS_ERR_STAT_PRIO_INVALID

If OS_CFG_STAT_TASK_EN is set to DEF_ENABLED in os_cfg.h: OSCfg_StatTaskPrio is invalid. The error is detected by OS_StatTaskInit() in os_stat.c.

OS_ERR_STAT_STK_INVALID

If OS_CFG_STAT_TASK_EN is set to DEF_ENABLED in os_cfg.hOSCfg_StatTaskStkBasePtr is NULL. The error is detected by OS_StatTaskInit() in os_stat.c.

OS_ERR_STAT_STK_SIZE_INVALID

IfOS_CFG_STAT_TASK_EN is set to DEF_ENABLED in os_cfg.hOSCfg_StatTaskStkSize is less than OSCfg_StkSizeMin. The error is detected by OS_StatTaskInit() in os_stat.c.

OS_ERR_TICK_PRIO_INVALID

If OSCfg_TickTaskPrio is invalid, The error is detected by OS_TickTaskInit() in os_tick.c.

OS_ERR_TICK_STK_INVALID

OSCfg_TickTaskStkBasePtr is NULL. The error is detected by OS_TickTaskInit() in os_tick.c.

OS_ERR_TICK_STK_SIZE_INVALID

OSCfg_TickTaskStkSize is less than OSCfg_StkSizeMin. This error was detected by OS_TickTaskInit() in os_tick.c.

OS_ERR_TMR_PRIO_INVALID

If OS_CFG_TMR_EN is set to DEF_ENABLED in os_cfg.h: OSCfg_TmrTaskPrio is invalid. The error is detected by see OS_TmrInit() in os_tmr.c.

OS_ERR_TMR_STK_INVALID

If OS_CFG_TMR_EN is set to DEF_ENABLED in os_cfg.hOSCfg_TmrTaskBasePtr is pointing at NULL. The error is detected by OS_TmrInit() in os_tmr.c.

OS_ERR_TMR_STK_SIZE_INVALID

If OS_CFG_TMR_EN is set to DEF_ENABLED in os_cfg.hOSCfg_TmrTaskStkSize is less than OSCfg_StkSizeMin. The error is detected by OS_TmrInit() in os_tmr.c.

Returned Values

None

Required Configuration

...

Application.

Notes/Warnings

  1. OSInit() must  must be called before before OSStart().
  2. OSInit() returns  returns as soon as it detects an error in any of the sub-functions it calls. For example, if if OSInit() encounters  encounters a problem initializing the task manager, an appropriate error code will be returned and and OSInit() will  will not go any further. It is therefore important that the user checks the error code before starting multitasking.
  3. The listing below shows the OS_CFG and OS_TASK_CFG structures. The OS_APP_CFG_???_DFLT defines in os.h contain the default values for every OS_CFG field.

...

Example Usage

Code Block
titleOSInit() example usage
          void main (void)
          {
              OS_ERR  err;
             
                 : 
              OSInit(&err);                   /* Initialize µC/OS-III              */
              /* Check "err" */
              :
              :
              OSStart(&err);                  /* Start Multitasking                */
              /* Check "err" */               /* Code not supposed to end up here! */
              :
              :
          }