samples: logging: Add usermode showcase
This commit extends existing logging sample in order to present logger usage from user mode thread. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com> Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commit is contained in:
parent
892ab4e356
commit
b52a902fdf
5 changed files with 58 additions and 22 deletions
|
@ -1,8 +0,0 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_LOG_RUNTIME_FILTERING=y
|
||||
CONFIG_LOG_BUFFER_SIZE=2048
|
||||
CONFIG_LOG_PRINTK=y
|
||||
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=0
|
||||
CONFIG_LOG_BACKEND_RTT=y
|
||||
CONFIG_USE_SEGGER_RTT=y
|
||||
CONFIG_COVERAGE=n
|
|
@ -21,4 +21,13 @@ tests:
|
|||
tags: logging
|
||||
filter: CONFIG_HAS_SEGGER_RTT
|
||||
harness: keyboard
|
||||
extra_args: CONF_FILE="prj_rtt.conf"
|
||||
extra_configs:
|
||||
- CONFIG_LOG_BACKEND_RTT=y
|
||||
- CONFIG_USE_SEGGER_RTT=y
|
||||
|
||||
samples.logger.usermode:
|
||||
tags: logging usermode
|
||||
filter: CONFIG_ARCH_HAS_USERSPACE
|
||||
harness: keyboard
|
||||
extra_configs:
|
||||
- CONFIG_USERSPACE=y
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <app_memory/app_memdomain.h>
|
||||
#include "ext_log_system.h"
|
||||
|
||||
static ext_log_handler log_handler;
|
||||
K_APP_BMEM(app_part) static ext_log_handler log_handler;
|
||||
|
||||
void ext_log_handler_set(ext_log_handler handler)
|
||||
{
|
||||
|
|
|
@ -7,26 +7,38 @@
|
|||
#include <zephyr.h>
|
||||
#include <string.h>
|
||||
#include <sys/printk.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
#include "sample_instance.h"
|
||||
#include "sample_module.h"
|
||||
#include "ext_log_system.h"
|
||||
#include "ext_log_system_adapter.h"
|
||||
#include <logging/log_ctrl.h>
|
||||
#include <app_memory/app_memdomain.h>
|
||||
|
||||
#include <logging/log.h>
|
||||
|
||||
LOG_MODULE_REGISTER(main);
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
K_APPMEM_PARTITION_DEFINE(app_part);
|
||||
static struct k_mem_domain app_domain;
|
||||
static struct k_mem_partition *app_parts[] = {
|
||||
#ifdef Z_LIBC_PARTITION_EXISTS
|
||||
/* C library globals, stack canary storage, etc */
|
||||
&z_libc_partition,
|
||||
#endif
|
||||
&app_part
|
||||
};
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
/* size of stack area used by each thread */
|
||||
#define STACKSIZE 1024
|
||||
|
||||
extern void sample_module_func(void);
|
||||
|
||||
#define INST1_NAME STRINGIFY(SAMPLE_INSTANCE_NAME.inst1)
|
||||
SAMPLE_INSTANCE_DEFINE(inst1);
|
||||
SAMPLE_INSTANCE_DEFINE(app_part, inst1);
|
||||
|
||||
#define INST2_NAME STRINGIFY(SAMPLE_INSTANCE_NAME.inst2)
|
||||
SAMPLE_INSTANCE_DEFINE(inst2);
|
||||
SAMPLE_INSTANCE_DEFINE(app_part, inst2);
|
||||
|
||||
#if !defined(NRF_RTC1) && defined(CONFIG_SOC_FAMILY_NRF)
|
||||
#include <soc.h>
|
||||
|
@ -235,11 +247,14 @@ static void wait_on_log_flushed(void)
|
|||
}
|
||||
}
|
||||
|
||||
void log_demo_thread(void *dummy1, void *dummy2, void *dummy3)
|
||||
static void log_demo_thread(void *p1, void *p2, void *p3)
|
||||
{
|
||||
bool usermode = _is_user_context();
|
||||
|
||||
k_sleep(100);
|
||||
|
||||
(void)log_set_timestamp_func(timestamp_get, timestamp_freq());
|
||||
printk("\n\t---=< RUNNING LOGGER DEMO FROM %s THREAD >=---\n\n",
|
||||
(usermode) ? "USER" : "KERNEL");
|
||||
|
||||
module_logging_showcase();
|
||||
|
||||
|
@ -268,15 +283,34 @@ void log_demo_thread(void *dummy1, void *dummy2, void *dummy3)
|
|||
|
||||
wait_on_log_flushed();
|
||||
|
||||
performance_showcase();
|
||||
if (!usermode) {
|
||||
/*
|
||||
* Logger performance in user mode cannot be demonstrated
|
||||
* as precise timing API is accessible only from the kernel.
|
||||
*/
|
||||
performance_showcase();
|
||||
wait_on_log_flushed();
|
||||
|
||||
wait_on_log_flushed();
|
||||
}
|
||||
|
||||
external_log_system_showcase();
|
||||
|
||||
wait_on_log_flushed();
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(log_demo_thread_id, STACKSIZE, log_demo_thread,
|
||||
static void log_demo_supervisor(void *p1, void *p2, void *p3)
|
||||
{
|
||||
/* Timestamp function could be set only from kernel thread. */
|
||||
(void)log_set_timestamp_func(timestamp_get, timestamp_freq());
|
||||
|
||||
log_demo_thread(p1, p2, p3);
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
k_mem_domain_init(&app_domain, ARRAY_SIZE(app_parts), app_parts);
|
||||
k_mem_domain_add_thread(&app_domain, k_current_get());
|
||||
k_thread_user_mode_enter(log_demo_thread, p1, p2, p3);
|
||||
#endif
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(log_demo_thread_id, STACKSIZE, log_demo_supervisor,
|
||||
NULL, NULL, NULL,
|
||||
K_LOWEST_APPLICATION_THREAD_PRIO, 0, 1);
|
||||
|
|
|
@ -17,9 +17,9 @@ struct sample_instance {
|
|||
u32_t cnt;
|
||||
};
|
||||
|
||||
#define SAMPLE_INSTANCE_DEFINE(_name) \
|
||||
#define SAMPLE_INSTANCE_DEFINE(_part, _name) \
|
||||
LOG_INSTANCE_REGISTER(SAMPLE_INSTANCE_NAME, _name, LOG_LEVEL_INF); \
|
||||
struct sample_instance _name = { \
|
||||
K_APP_DMEM(_part) struct sample_instance _name = { \
|
||||
LOG_INSTANCE_PTR_INIT(log, SAMPLE_INSTANCE_NAME, _name) \
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue