Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Stack APIs

Macros

#define K_STACK_DEFINE(name, stack_num_entries)
 Statically define and initialize a stack.
 

Functions

void k_stack_init (struct k_stack *stack, stack_data_t *buffer, uint32_t num_entries)
 Initialize a stack.
 
int32_t k_stack_alloc_init (struct k_stack *stack, uint32_t num_entries)
 Initialize a stack.
 
int k_stack_cleanup (struct k_stack *stack)
 Release a stack's allocated buffer.
 
int k_stack_push (struct k_stack *stack, stack_data_t data)
 Push an element onto a stack.
 
int k_stack_pop (struct k_stack *stack, stack_data_t *data, k_timeout_t timeout)
 Pop an element from a stack.
 

Detailed Description

Macro Definition Documentation

◆ K_STACK_DEFINE

#define K_STACK_DEFINE (   name,
  stack_num_entries 
)

#include <zephyr/kernel.h>

Value:
stack_data_t __noinit \
_k_stack_buf_##name[stack_num_entries]; \
STRUCT_SECTION_ITERABLE(k_stack, name) = \
Z_STACK_INITIALIZER(name, _k_stack_buf_##name, \
stack_num_entries)

Statically define and initialize a stack.

The stack can be accessed outside the module where it is defined using:

extern struct k_stack <name>;
Parameters
nameName of the stack.
stack_num_entriesMaximum number of values that can be stacked.

Function Documentation

◆ k_stack_alloc_init()

int32_t k_stack_alloc_init ( struct k_stack *  stack,
uint32_t  num_entries 
)

#include <zephyr/kernel.h>

Initialize a stack.

This routine initializes a stack object, prior to its first use. Internal buffers will be allocated from the calling thread's resource pool. This memory will be released if k_stack_cleanup() is called, or userspace is enabled and the stack object loses all references to it.

Parameters
stackAddress of the stack.
num_entriesMaximum number of values that can be stacked.
Returns
-ENOMEM if memory couldn't be allocated

◆ k_stack_cleanup()

int k_stack_cleanup ( struct k_stack *  stack)

#include <zephyr/kernel.h>

Release a stack's allocated buffer.

If a stack object was given a dynamically allocated buffer via k_stack_alloc_init(), this will free it. This function does nothing if the buffer wasn't dynamically allocated.

Parameters
stackAddress of the stack.
Return values
0on success
-EAGAINwhen object is still in use

◆ k_stack_init()

void k_stack_init ( struct k_stack *  stack,
stack_data_t *  buffer,
uint32_t  num_entries 
)

#include <zephyr/kernel.h>

Initialize a stack.

This routine initializes a stack object, prior to its first use.

Parameters
stackAddress of the stack.
bufferAddress of array used to hold stacked values.
num_entriesMaximum number of values that can be stacked.

◆ k_stack_pop()

int k_stack_pop ( struct k_stack *  stack,
stack_data_t *  data,
k_timeout_t  timeout 
)

#include <zephyr/kernel.h>

Pop an element from a stack.

This routine removes a stack_data_t value from stack in a "last in, first out" manner and stores the value in data.

Note
timeout must be set to K_NO_WAIT if called from ISR.
Function properties (list may not be complete)
isr-ok
Parameters
stackAddress of the stack.
dataAddress of area to hold the value popped from the stack.
timeoutWaiting period to obtain a value, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Element popped from stack.
-EBUSYReturned without waiting.
-EAGAINWaiting period timed out.

◆ k_stack_push()

int k_stack_push ( struct k_stack *  stack,
stack_data_t  data 
)

#include <zephyr/kernel.h>

Push an element onto a stack.

This routine adds a stack_data_t value data to stack.

Function properties (list may not be complete)
isr-ok
Parameters
stackAddress of the stack.
dataValue to push onto the stack.
Return values
0on success
-ENOMEMif stack is full