Nikolaus Huber
void thread (void * arg1, void * arg2, void * arg3)
{
/* Thread init */
for(;;)
{
/* Thread body */
}
}
#define MY_STACK_SIZE 500
#define MY_PRIORITY 5
extern void my_entry_point(void *, void *, void *);
K_THREAD_STACK_DEFINE(my_stack_area, MY_STACK_SIZE);
struct k_thread my_thread_data;
/* in main () */
k_tid_t my_tid = k_thread_create(&my_thread_data, my_stack_area,
K_THREAD_STACK_SIZEOF(my_stack_area),
my_entry_point,
NULL, NULL, NULL,
MY_PRIORITY, 0, K_NO_WAIT);
#define MY_STACK_SIZE 500
#define MY_PRIORITY 5
extern void my_entry_point(void *, void *, void *);
K_THREAD_DEFINE(my_tid, MY_STACK_SIZE,
my_entry_point, NULL, NULL, NULL,
MY_PRIORITY, 0, 0);
void my_entry_point(void * arg1, void * arg2, void * arg3)
{
for(;;)
{
if (/* some condition */) { return; }
/* ... */
}
/* thread terminates here */
}
int sharedData;
void task1(void * a1, void * a2, void * a3)
{
for(int i = 0; i < 1000000; i++)
{
sharedData = sharedData + 1;
}
k_sleep(K_FOREVER);
}
void task2(void * a1, void * a2, void * a3)
{
for(int i = 0; i < 1000000; i++)
{
sharedData = sharedData + 1;
}
k_sleep(K_FOREVER);
}
int sharedData;
K_MUTEX_DEFINE(my_mutex);
void task1 (void * a1, void * a2, void * a3)
{
for(int i = 0; i < 1000000; i++)
{
k_mutex_lock(&my_mutex, K_FOREVER);
sharedData = sharedData + 1;
k_mutex_unlock(&my_mutex);
}
k_sleep(K_FOREVER);
}
K_MUTEX_DEFINE(mutex_A);
K_MUTEX_DEFINE(mutex_B);
void task1() {
k_mutex_lock(&mutex_A, K_FOREVER);
k_mutex_lock(&mutex_B, K_FOREVER);
/* ... */
k_mutex_unlock(&mutex_B);
k_mutex_unlock(&mutex_A);
}
void task2() {
k_mutex_lock(&mutex_B, K_FOREVER);
k_mutex_lock(&mutex_A, K_FOREVER);
/* ... */
k_mutex_unlock(&mutex_A);
k_mutex_unlock(&mutex_B);
}
bool fError;
void display (int j)
{
if (!fError)
{
printf("here");
j = 0;
fError = true;
}
else
{
printf("also here");
fError = false;
}
}
/dts-v1/;
/ {
a-node {
subnode_nodelabel: a-sub-node {
foo = <3>;
};
};
};
volatile bool global_var = false;
void main(void)
{
while(!global_var)
{
/* Wait */
}
}
void isr_routine(void)
{
global_var = true;
}