kernel/stack: Introduce K_THREAD_STACK_LEN macro

This is a public macro which calculates the size to be allocated for
stacks inside a stack array. This is necessitated because of some
internal padding (e.g. for MPU scenarios). This is particularly
useful when a reference to K_THREAD_STACK_ARRAY_DEFINE needs to be
made from within a struct.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
This commit is contained in:
Rajavardhan Gundi 2018-06-27 13:26:20 +05:30 committed by Andrew Boie
commit d4dd928eaa
4 changed files with 53 additions and 12 deletions

View file

@ -4586,6 +4586,7 @@ extern void _timer_expiration_handler(struct _timeout *t);
#define K_THREAD_STACK_DEFINE(sym, size) _ARCH_THREAD_STACK_DEFINE(sym, size)
#define K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
_ARCH_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size)
#define K_THREAD_STACK_LEN(size) _ARCH_THREAD_STACK_LEN(size)
#define K_THREAD_STACK_MEMBER(sym, size) _ARCH_THREAD_STACK_MEMBER(sym, size)
#define K_THREAD_STACK_SIZEOF(sym) _ARCH_THREAD_STACK_SIZEOF(sym)
static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
@ -4622,6 +4623,19 @@ static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
#define K_THREAD_STACK_DEFINE(sym, size) \
struct _k_thread_stack_element __noinit __aligned(STACK_ALIGN) sym[size]
/**
* @brief Calculate size of stacks to be allocated in a stack array
*
* This macro calculates the size to be allocated for the stacks
* inside a stack array. It accepts the indicated "size" as a parameter
* and if required, pads some extra bytes (e.g. for MPU scenarios). Refer
* K_THREAD_STACK_ARRAY_DEFINE definition to see how this is used.
*
* @param size Size of the stack memory region
* @req K-TSTACK-001
*/
#define K_THREAD_STACK_LEN(size) (size)
/**
* @brief Declare a toplevel array of thread stack memory regions
*
@ -4638,7 +4652,7 @@ static inline char *K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
*/
#define K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
struct _k_thread_stack_element __noinit \
__aligned(STACK_ALIGN) sym[nmemb][size]
__aligned(STACK_ALIGN) sym[nmemb][K_THREAD_STACK_LEN(size)]
/**
* @brief Declare an embedded stack memory region