From febcac6d438ec28bd6877faf38cf552bf5e51293 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 14 Jul 2015 14:37:30 +0200 Subject: [PATCH] core: add capability to output message queue --- core/include/thread.h | 5 +++++ core/thread_print_msg_queue.c | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 core/thread_print_msg_queue.c diff --git a/core/include/thread.h b/core/include/thread.h index 267857e42..13540a6b7 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -243,6 +243,11 @@ static inline kernel_pid_t thread_getpid(void) return sched_active_pid; } +/** + * @brief Prints the message queue of the current thread. + */ +void thread_print_msg_queue(void); + #ifdef DEVELHELP /** * @brief Returns the name of a process diff --git a/core/thread_print_msg_queue.c b/core/thread_print_msg_queue.c new file mode 100644 index 000000000..c4ac20bdd --- /dev/null +++ b/core/thread_print_msg_queue.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @author Martine Lenders + */ + +#include + +#include "sched.h" +#include "thread.h" + +void thread_print_msg_queue(void) +{ + volatile tcb_t *tcb = sched_active_thread; + volatile cib_t *msg_queue = &tcb->msg_queue; + msg_t *msg_array = tcb->msg_array; + unsigned int i = msg_queue->read_count & msg_queue->mask; + + printf("Message queue of thread %" PRIkernel_pid "\n", tcb->pid); + printf(" size: %u (avail: %d)\n", msg_queue->mask + 1, + cib_avail((cib_t *)msg_queue)); + + for (; i != (msg_queue->write_count & msg_queue->mask); + i = (i + 1) & msg_queue->mask) { + msg_t *m = &msg_array[i]; + printf(" * %u: sender: %" PRIkernel_pid ", type: 0x%04" PRIu16 + ", content: %" PRIu32 " (%p)\n", i, m->sender_pid, m->type, + m->content.value, (void *)m->content.ptr); + } +} + +/** @} */