...
is a pointer to the task’s OS_TCB
to use. It is assumed that storage for the TCB of the task will be allocated by the user code. You can declare a “global” variable as follows, and pass a pointer to this variable to OSTaskCreate()
:
OS_TCB MyTaskTCB MyTaskTCB;
p_name
is a pointer to an ASCII string (NUL terminated) to assign a name to the task. The name can be displayed by debuggers or by µC/Probe.
...
is the task priority. The lower the number, the higher the priority (i.e., the importance) of the task. If OS_CFG_ISR_POST_DEFERRED_EN
is set to 1 DEF_ENABLED
in
, the user cannot use priority os_cfg.h
0.
Task priority must also have a lower number than OS_CFG_PRIO_MAX-1
. Priorities 0
, 1
, OS_CFG_PRIO_MAX-2
and OS_CFG_PRIO_MAX-1
are reserved. In other words, a task should have a priority between 2
and OOSOS_CFG_PRIO_MAX-3
, inclusively.
...
The user would then pass p_stk_base
the address of the first element of this array or, &MyTaskStk[0]
. “???
” represents the size of the stack.
...
A µC/OS-III task contains an optional internal message queue (if OS_CFG_TASK_Q_EN > 0
is set to DEF_ENABLED
in os_cfg.h
). This argument specifies the maximum number of messages that the task can receive through this message queue. The user may specify that the task is unable to receive messages by setting this argument to 0
.
...
If the caller doesn’t want or need TLS (Thread Local Storage) support for the task being created. If you do not include this option, TLS will be supported by default, assuming Micriµm supports TLS for the toolchain you are using. TLS support was added in V3.03.00.
...
p_err
is a pointer to a variable that will receive an error code:
...
If the function is successful.
OS_ERR_ILLEGAL_CREATE_RUN_TIME
If OS_SAFETY_CRITICAL_IEC61508
is defined: you called this after calling OSStart()
and thus you are no longer allowed to create additional kernel objects.
OS_ERR_PRIO_INVALID
If OS_CFG_ARG_CHK_EN
is set to 1
in DEF_ENABLED
in os_cfg.h
: if prio
is higher than the maximum value allowed (i.e., > OS_PRIO_MAX-1
). AlsoOr, you will get this error if the user set OS_CFG_ISR_POST_DEFERRED_EN
to 1
and tried to use priority 0
if your tried to use any in-use priority by the kernel, see the prio
argument.
OS_ERR_STAT_STK_SIZE_INVALID
If the task's stack overflowed during initialization.
OS_ERR_STK_INVALID
If OS_CFG_ARG_CHK_EN
is set to 1
in DEF_ENABLED
in os_cfg.h
: if specifying a NULL
pointer for p_stk_base
.
...
If OS_CFG_ARG_CHK_EN
is set to 1
in DEF_ENABLED
in os_cfg.h
: if specifying a stack size smaller than what is currently specified by OS_CFG_STK_SIZE_MIN
(see the os_cfg.h
).
OS_ERR_STK_LIMIT_INVALID
If OS_CFG_ARG_CHK_EN
is set to DEF_ENABLED
in os_cfg.h
: if specifying a stack limit greater than or equal to the stack size.
OS_ERR_TASK_CREATE_ISR
If OS_CFG_CALLED_FROM_ISR_CHK_EN
set to 1
in DEF_ENABLED
in os_cfg.h
: if attempting to create the task from an ISR.
...
If OS_CFG_ARG_CHK_EN
is set to 1
in DEF_ENABLED
in os_cfg.h
: if specifying a NULL
pointer for p_task
.
OS_ERR_TCB_INVALID
If OS_CFG_ARG_CHK_EN
is set to 1
in DEF_ENABLED
in os_cfg.h
: if specifying a NULL
pointer for p_tcb
.
OS_ERR_ILLEGAL_CREATE_RUN_TIME
If OS_SAFETY_CRITICAL_IEC61508
is defined: you called this after calling OSSafetyCriticalStart()
and thus you are no longer allowed to create additional kernel objects.
Returned Value
...
Returned Value
None
Required Configuration
None
Callers
Application.
Notes/Warnings
- The stack must be declared with the
CPU_STK
type. - A task must always invoke one of the services provided by µC/OS-III to wait for time to expire, suspend the task, or wait on an object (wait on a message queue, event flag, mutex, semaphore, a signal or a message to be sent directly to the task). This allows other tasks to gain control of the CPU.
- You should not use task priorities
0
,1
,OS_CFG_PRIO_MAX-2
andOS_CFG_PRIO_MAX-1
because they are reserved for use by µC/OS-III.
Example Usage
OSTaskCreate()
can be called from main()
(in C), or a previously created task.