Skip to content

Commit

Permalink
Make main thread stack size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ReservedField committed Jun 29, 2016
1 parent c222885 commit 01a96cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions include/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ extern "C" {
*/
#define THREAD_SYSTICK_MS 1

/**
* Default stack size for the main thread.
*/
#define THREAD_DEFAULT_STACKSIZE 1024

/**
* Defines the stack size for the main thread.
* This must be used outside of any function. If this
* macro isn't used, the stack size will default to
* THREAD_DEFAULT_STACKSIZE.
*/
#define THREAD_MAIN_STACKSIZE(size) uint16_t Startup_mainThreadStackSize = (size)

/**
* Type for thread handles.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/startup/mainthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
* Copyright (C) 2016 ReservedField
*/

#include <stdint.h>
#include <M451Series.h>
#include <Thread.h>

extern void __libc_init_array();
extern void __libc_fini_array();
extern int main();

// Weak: address will be NULL if not defined by application code
extern uint16_t Startup_mainThreadStackSize __attribute__((weak));

/**
* Main thread.
*
Expand Down Expand Up @@ -52,6 +56,12 @@ void *Startup_MainThread(void *args) {
*/
void Startup_CreateMainThread() {
Thread_t mainThread;
uint16_t stackSize;

stackSize = THREAD_DEFAULT_STACKSIZE;
if(&Startup_mainThreadStackSize != NULL) {
stackSize = Startup_mainThreadStackSize;
}

Thread_Create(&mainThread, Startup_MainThread, NULL, 1024);
Thread_Create(&mainThread, Startup_MainThread, NULL, stackSize);
}

0 comments on commit 01a96cb

Please sign in to comment.