kopia lustrzana https://github.com/OpenRTX/OpenRTX
Set proper thread stack size also when using the Zephyr RTOS
rodzic
e11c529807
commit
73bfc2a15d
|
@ -43,4 +43,9 @@ void create_threads();
|
|||
*/
|
||||
#define RTX_TASK_STKSIZE 512
|
||||
|
||||
/**
|
||||
* Stack size for codec2 task, in bytes.
|
||||
*/
|
||||
#define CODEC2_TASK_STKSIZE 16384
|
||||
|
||||
#endif /* THREADS_H */
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <audio_stream.h>
|
||||
#include <audio_codec.h>
|
||||
#include <pthread.h>
|
||||
#include <threads.h>
|
||||
#include <codec2.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -37,6 +38,7 @@ static bool running;
|
|||
|
||||
static bool reqStop;
|
||||
static pthread_t codecThread;
|
||||
static pthread_attr_t codecAttr;
|
||||
static pthread_mutex_t data_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_cond_t wakeup_cond = PTHREAD_COND_INITIALIZER;
|
||||
|
@ -387,25 +389,24 @@ static bool startThread(const pathId path, void *(*func) (void *))
|
|||
numElements = 0;
|
||||
reqStop = false;
|
||||
|
||||
int ret = 0;
|
||||
|
||||
#ifdef _MIOSIX
|
||||
// Set stack size of CODEC2 thread to 16kB.
|
||||
pthread_attr_t codecAttr;
|
||||
pthread_attr_init(&codecAttr);
|
||||
pthread_attr_setstacksize(&codecAttr, 16384);
|
||||
|
||||
#if defined(_MIOSIX)
|
||||
// Set stack size of CODEC2 thread to 16kB.
|
||||
pthread_attr_setstacksize(&codecAttr, CODEC2_TASK_STKSIZE);
|
||||
|
||||
// Set priority of CODEC2 thread to the maximum one, the same of RTX thread.
|
||||
struct sched_param param;
|
||||
param.sched_priority = sched_get_priority_max(0);
|
||||
pthread_attr_setschedparam(&codecAttr, ¶m);
|
||||
|
||||
// Start thread
|
||||
ret = pthread_create(&codecThread, &codecAttr, func, ((void *) audioPath));
|
||||
#else
|
||||
ret = pthread_create(&codecThread, NULL, func, ((void *) audioPath));
|
||||
#elif defined(__ZEPHYR__)
|
||||
// Allocate and set the stack for CODEC2 thread
|
||||
void *codec_thread_stack = malloc(CODEC2_TASK_STKSIZE * sizeof(uint8_t));
|
||||
pthread_attr_setstack(&codecAttr, codec_thread_stack, CODEC2_TASK_STKSIZE);
|
||||
#endif
|
||||
|
||||
// Start thread
|
||||
int ret = pthread_create(&codecThread, &codecAttr, func, ((void *) audioPath));
|
||||
if(ret < 0)
|
||||
running = false;
|
||||
|
||||
|
@ -417,4 +418,12 @@ static void stopThread()
|
|||
reqStop = true;
|
||||
pthread_join(codecThread, NULL);
|
||||
running = false;
|
||||
|
||||
#ifdef __ZEPHYR__
|
||||
void *addr;
|
||||
size_t size;
|
||||
|
||||
pthread_attr_getstack(&codecAttr, &addr, &size);
|
||||
free(addr);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -198,17 +198,19 @@ void *rtx_threadFunc(void *arg)
|
|||
*/
|
||||
void create_threads()
|
||||
{
|
||||
pthread_t rtx_thread;
|
||||
pthread_t ui_thread;
|
||||
|
||||
// Create RTX state mutex
|
||||
pthread_mutex_init(&rtx_mutex, NULL);
|
||||
|
||||
#ifndef __ZEPHYR__
|
||||
// Create rtx radio thread
|
||||
pthread_attr_t rtx_attr;
|
||||
pthread_attr_init(&rtx_attr);
|
||||
|
||||
#ifndef __ZEPHYR__
|
||||
pthread_attr_setstacksize(&rtx_attr, RTX_TASK_STKSIZE);
|
||||
#else
|
||||
void *rtx_thread_stack = malloc(RTX_TASK_STKSIZE * sizeof(uint8_t));
|
||||
pthread_attr_setstack(&rtx_attr, rtx_thread_stack, RTX_TASK_STKSIZE);
|
||||
#endif
|
||||
|
||||
#ifdef _MIOSIX
|
||||
// Max priority for RTX thread when running with miosix rtos
|
||||
|
@ -217,16 +219,20 @@ void create_threads()
|
|||
pthread_attr_setschedparam(&rtx_attr, ¶m);
|
||||
#endif
|
||||
|
||||
pthread_t rtx_thread;
|
||||
pthread_create(&rtx_thread, &rtx_attr, rtx_threadFunc, NULL);
|
||||
|
||||
// Create UI thread
|
||||
pthread_attr_t ui_attr;
|
||||
pthread_attr_init(&ui_attr);
|
||||
|
||||
#ifndef __ZEPHYR__
|
||||
pthread_attr_setstacksize(&ui_attr, UI_TASK_STKSIZE);
|
||||
#else
|
||||
void *ui_thread_stack = malloc(UI_TASK_STKSIZE * sizeof(uint8_t));
|
||||
pthread_attr_setstack(&ui_attr, ui_thread_stack, UI_TASK_STKSIZE);
|
||||
#endif
|
||||
|
||||
pthread_t ui_thread;
|
||||
pthread_create(&ui_thread, &ui_attr, ui_threadFunc, NULL);
|
||||
#else
|
||||
// On zephyr just spawn the threads without setting the attributes
|
||||
pthread_create(&rtx_thread, NULL, rtx_threadFunc, NULL);
|
||||
pthread_create(&ui_thread, NULL, ui_threadFunc, NULL);
|
||||
#endif
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue