From d81b2e88282e3819965f2d67a956a3df7ec0bfcf Mon Sep 17 00:00:00 2001
From: patacongo Last Updated: February 4, 2013 Last Updated: March 20, 2013
NuttX RTOS Porting Guide
- make
.
up_create_stack()
Prototype: STATUS up_create_stack(FAR struct tcb_s *tcb, size_t stack_size);
Prototype: STATUS up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype);
Description. - Allocate a stack for a new thread and setup - up stack-related information in the TCB. + Allocate a stack for a new thread and setup up stack-related information in the TCB.
The following TCB fields must be initialized:
@@ -1631,18 +1630,37 @@ The system can be re-made subsequently by just typing make
.
initial value of the stack pointer.
- This API is NOT required if CONFIG_CUSTOM_STACK
- is defined.
+ This API is NOT required if CONFIG_CUSTOM_STACK
is defined.
Input Parameters:
tcb
: The TCB of new task.
+
+ tcb
: The TCB of new task.
+
stack_size
: The requested stack size. At least this much
- must be allocated.
+
+ stack_size
: The requested stack size. At least this much must be allocated.
+
+ ttype
: The thread type.
+ This may be one of following (defined in include/nuttx/sched.h
):
+
TCB_FLAG_TTYPE_TASK
: Normal user taskTCB_FLAG_TTYPE_PTHREAD
: User pthreadTCB_FLAG_TTYPE_KERNEL
: Kernel thread+ This thread type is normally available in the flags field of the TCB, however, there are certain contexts where the TCB may not be fully initialized when up_create_stack is called. +
+
+ If CONFIG_NUTTX_KERNEL
is defined, then this thread type may affect how the stack is allocated. For example, kernel thread stacks should be allocated from protected kernel memory. Stacks for user tasks and threads must come from memory that is accessible to user code.
+
make
.
Description.
- Setup up stack-related information in the TCB
- using pre-allocated stack memory.
+ Setup up stack-related information in the TCB using pre-allocated stack memory.
+ This function is called only from task_init()
when a task or kernel thread is started (never for pthreads).
The following TCB fields must be initialized:
@@ -1667,8 +1685,7 @@ The system can be re-made subsequently by just typing make
.
initial value of the stack pointer.
- This API is NOT required if CONFIG_CUSTOM_STACK
- is defined.
+ This API is NOT required if CONFIG_CUSTOM_STACK
is defined.
Input Parameters:
@@ -1680,18 +1697,48 @@ The system can be re-made subsequently by just typingmake
.
stack_size
: The allocated stack size.
+
+ NOTE: Unlike up_stack_create()
and up_stack_release
, this function does not require the task type (ttype
) parameter.
+ The TCB flags will always be set to provide the task type to up_use_stack()
if the information needs that information.
+
up_release_stack()
Prototype: void up_release_stack(FAR struct tcb_s *dtcb);
Description. - A task has been stopped. Free all stack - related resources retained int the defunct TCB. + A task has been stopped. + Free all stack related resources retained int the defunct TCB.
- This API is NOT required if CONFIG_CUSTOM_STACK
- is defined.
+ This API is NOT required if CONFIG_CUSTOM_STACK
is defined.
Input Parameters:
+
+ dtcb
:
+ The TCB containing information about the stack to be released.
+
+ ttype
: The thread type.
+ This may be one of following (defined in include/nuttx/sched.h
):
+
TCB_FLAG_TTYPE_TASK
: Normal user taskTCB_FLAG_TTYPE_PTHREAD
: User pthreadTCB_FLAG_TTYPE_KERNEL
: Kernel thread+ This thread type is normally available in the flags field of the TCB, however, there are certain error recovery contexts where the TCB may not be fully initialized when up_release_stack is called. +
+
+ If CONFIG_NUTTX_KERNEL
is defined, then this thread type may affect how the stack is freed.
+ For example, kernel thread stacks may have been allocated from protected kernel memory.
+ Stacks for user tasks and threads must have come from memory that is accessible to user
+
up_unblock_task()
Prototype: void up_unblock_task(FAR struct tcb_s *tcb);