Ensure stack size produces an aligned stack on platforms where it matters

This commit is contained in:
inmarket 2017-01-09 10:24:49 +10:00
parent def8fd488f
commit 9216504ce3
5 changed files with 9 additions and 5 deletions

View File

@ -65,7 +65,11 @@
* @brief Declare a thread stack * @brief Declare a thread stack
* *
* @param[in] name The name of the stack * @param[in] name The name of the stack
* @param[in] sz The size of the stack * @param[in] sz The size of the stack in bytes
*
* @note The size provided is just a suggestion to the required stack size.
* Many platforms will round the size to ensure correct stack alignment.
* Other platforms may entirely ignore the suggested size.
*/ */
#define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz]; #define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz];

View File

@ -44,7 +44,7 @@ typedef cyg_handle_t gfxThreadHandle;
#define NORMAL_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES/2) #define NORMAL_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES/2)
#define HIGH_PRIORITY 0 #define HIGH_PRIORITY 0
#define DECLARE_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[sz]; } name[1] #define DECLARE_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[(sz) & ~3]; } name[1]
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(cyg_addrword_t param) #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(cyg_addrword_t param)
#define THREAD_RETURN(retval) #define THREAD_RETURN(retval)

View File

@ -60,7 +60,7 @@ typedef portBASE_TYPE threadpriority_t;
#define HIGH_PRIORITY configMAX_PRIORITIES-1 #define HIGH_PRIORITY configMAX_PRIORITIES-1
/* FreeRTOS will allocate the stack when creating the thread, so pass the size instead of a working area */ /* FreeRTOS will allocate the stack when creating the thread, so pass the size instead of a working area */
#define DECLARE_THREAD_STACK(name, sz) size_t *name = (size_t *)sz #define DECLARE_THREAD_STACK(name, sz) size_t *name = (size_t *)(sz)
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
#define THREAD_RETURN(retval) #define THREAD_RETURN(retval)

View File

@ -26,7 +26,7 @@ typedef RAW_MUTEX gfxMutex;
typedef RAW_TASK_OBJ* gfxThreadHandle; typedef RAW_TASK_OBJ* gfxThreadHandle;
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
#define DECLARE_THREAD_STACK(name, sz) PORT_STACK name[sz]; #define DECLARE_THREAD_STACK(name, sz) PORT_STACK name[(sz) & ~3];
#define THREAD_RETURN(retval) return retval #define THREAD_RETURN(retval) return retval
#define gfxHalt(msg) for(;;) #define gfxHalt(msg) for(;;)

View File

@ -31,7 +31,7 @@ typedef int threadreturn_t;
typedef int threadpriority_t; typedef int threadpriority_t;
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
#define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz]; #define DECLARE_THREAD_STACK(name, sz) uint8_t name[(sz) & ~3];
#define THREAD_RETURN(retval) return retval #define THREAD_RETURN(retval) return retval
#define TIME_IMMEDIATE 0 #define TIME_IMMEDIATE 0