Skip to content

Instantly share code, notes, and snippets.

@yashi
Created July 30, 2019 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashi/517aab09ce16cda537341f5c5d958fac to your computer and use it in GitHub Desktop.
Save yashi/517aab09ce16cda537341f5c5d958fac to your computer and use it in GitHub Desktop.
k_sched_unlock debug code
#include <zephyr.h>
#define MY_STACK_SIZE 5000
K_THREAD_STACK_DEFINE(preempt_stack, MY_STACK_SIZE);
struct k_thread preempt_thread;
K_THREAD_STACK_DEFINE(coop_stack, MY_STACK_SIZE);
struct k_thread coop_thread;
static void preempt(void *arg1, void *arg2, void *arg3)
{
ARG_UNUSED(arg1);
ARG_UNUSED(arg2);
ARG_UNUSED(arg3);
k_sched_lock();
k_sched_lock();
printk("##### hello from preempt\n");
k_busy_wait(20000);
printk("##### about to unlock\n");
k_sched_unlock();
while (true) {
}
k_sched_unlock();
}
static void coop(void *arg1, void *arg2, void *arg3)
{
ARG_UNUSED(arg1);
ARG_UNUSED(arg2);
ARG_UNUSED(arg3);
printk("##### hello from coop\n");
k_usleep(1);
printk("##### This shouldn't be printed\n");
while (true) {
}
}
void main(void)
{
k_thread_priority_set(k_current_get(), -2);
k_thread_create(&preempt_thread, preempt_stack,
K_THREAD_STACK_SIZEOF(preempt_stack),
preempt,
NULL, NULL, NULL,
1, 0, K_NO_WAIT);
k_thread_create(&coop_thread, coop_stack,
K_THREAD_STACK_SIZEOF(coop_stack),
coop,
NULL, NULL, NULL,
-1, 0, K_NO_WAIT);
printk("* main: %p w/ %d\n", k_current_get(), k_thread_priority_get(k_current_get()));
printk("* preempt: %p w/ %d\n", &preempt_thread, k_thread_priority_get(&preempt_thread));
printk("* coop: %p w/ %d\n", &coop_thread, k_thread_priority_get(&coop_thread));
while (true) {
printk("##### hello from main\n");
k_sleep(100);
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment