Re: zephyr thread


Raj Gundi
 

The stack is not allocated in your example when you are using k_thread_create. Use the below code instead.

 

 

static K_THREAD_STACK_DEFINE(threadStack1, 1024);

static struct k_thread thread1;

k_thread_create(&thread1, threadStack1, 1024, (void*)DL_StateMachine_ModeHandler, NULL, NULL, NULL, 7, 0, K_NO_WAIT);

 

 

K_THREAD_STACK_DEFINE is called internally if you use K_THREAD_DEFINE instead of k_thread_create,

 

Regards,

Raj

 

From: devel@... [mailto:devel@...] On Behalf Of Florian Fouillet
Sent: Wednesday, December 26, 2018 11:07 PM
To: devel@...
Subject: [Zephyr-devel] zephyr thread

 

Hi everyone,

 

I am currently working on the Zephyr OS with a FDRM_K64f board from NXP.

 

To create thread I was first using K_THREAD_DEFINE.

 

I want to create an abstraction layer if I need to use different OS (a platform with generic definition for thread) so I won't have to modify the source code.

 

Since I can't call K_THREAD_DEFINE inside a function (I was ending up with an error). I am trying to use k_thread_create.

 

It's working when I create 1 thread but I have error as soon as I am trying to create multiple one.

 

Here for example I am creating 2 threads:

 

struct k_thread thread1 ;

k_thread_stack_t threadStack1 ;

 

struct k_thread thread2 ;

k_thread_stack_t threadStack2 ;

 

 

k_thread_create(&thread1, & threadStack1, 1024, (void*)DL_StateMachine_ModeHandler, NULL, NULL, NULL, 7, 0, K_NO_WAIT);

k_thread_create(&thread2, & threadStack2, 1024, (void*)DL_StateMachine_MsgHandler, NULL, NULL, NULL, 7, 0, K_NO_WAIT);

 

 

it compiles but then when I am trying to execute it I have the following issue:

 

 

 

 

Does anyone know how to correctly use the k_thread_create? My other question is, what’s k_thread_stack_t and what to do with it?

 

 

Thank you,

 

 

 

 

Join devel@lists.zephyrproject.org to automatically receive all group messages.