1 /*
2 * Copyright (c) 2012-2014 Wind River Systems, Inc.
3 * Copyright (c) 2021 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include <inttypes.h>
9 #include <zephyr/kernel.h>
10 #include <string.h>
11 #include <zephyr/sys/printk.h>
12 #include <zephyr/logging/log.h>
13 #include <zephyr/shell/shell.h>
14
15 LOG_MODULE_REGISTER(hello_world, LOG_LEVEL_DBG);
16
17 static const char *hexdump_msg = "HEXDUMP! HEXDUMP@ HEXDUMP#";
18
main(void)19 int main(void)
20 {
21 int8_t i8 = 1;
22 uint8_t u8 = 2;
23 int16_t i16 = 16;
24 uint16_t u16 = 17;
25 int32_t i32 = 32;
26 uint32_t u32 = 33;
27 int64_t i64 = 64;
28 uint64_t u64 = 65;
29 char c = '!';
30 char *s = "static str";
31 char *s1 = "c str";
32 char vs0[32];
33 char vs1[32];
34 void *p = s;
35
36 printk("Hello World! %s\n", CONFIG_BOARD);
37
38 LOG_ERR("error string");
39 LOG_DBG("debug string");
40 LOG_INF("info string");
41
42 LOG_DBG("int8_t %" PRId8 ", uint8_t %" PRIu8, i8, u8);
43 LOG_DBG("int16_t %" PRId16 ", uint16_t %" PRIu16, i16, u16);
44 LOG_DBG("int32_t %" PRId32 ", uint32_t %" PRIu32, i32, u32);
45 LOG_DBG("int64_t %" PRId64 ", uint64_t %" PRIu64, i64, u64);
46
47 memset(vs0, 0, sizeof(vs0));
48 snprintk(&vs0[0], sizeof(vs0), "%s", "dynamic str");
49
50 memset(vs1, 0, sizeof(vs1));
51 snprintk(&vs1[0], sizeof(vs1), "%s", "another dynamic str");
52
53 LOG_DBG("char %c", c);
54 LOG_DBG("s str %s %s", s, s1);
55 LOG_DBG("d str %s", vs0);
56 LOG_DBG("mixed str %s %s %s %s %s %s %s", vs0, "---", vs0, "---", vs1, "---", vs1);
57 LOG_DBG("mixed c/s %c %s %s %s %c", c, s, vs0, s, c);
58
59 LOG_DBG("pointer %p", p);
60
61 LOG_HEXDUMP_DBG(hexdump_msg, strlen(hexdump_msg), "For HeXdUmP!");
62
63 #ifdef CONFIG_FPU
64 float f = 66.67;
65 double d = 68.69;
66
67 LOG_DBG("float %f, double %f", (double)f, d);
68 #ifdef CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE
69 long double ld = 70.71L;
70
71 LOG_DBG("long double %Lf", ld);
72 #endif
73 #endif
74 return 0;
75 }
76
rt_demo_cmd(const struct shell * sh,size_t argc,char ** argv)77 static int rt_demo_cmd(const struct shell *sh, size_t argc, char **argv)
78 {
79 ARG_UNUSED(sh);
80 LOG_ERR("demo %s", argc > 1 ? argv[1] : "");
81 LOG_WRN("demo %s", argc > 1 ? argv[1] : "");
82 LOG_INF("demo %s", argc > 1 ? argv[1] : "");
83 LOG_DBG("demo %s", argc > 1 ? argv[1] : "");
84
85 return 0;
86 }
87
88 SHELL_CMD_REGISTER(log_rt_demo, NULL, "Command can be used to test runtime filtering", rt_demo_cmd);
89