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 <stdio.h>
12 #include <zephyr/sys/printk.h>
13 #include <zephyr/logging/log.h>
14 #include <zephyr/shell/shell.h>
15
16 LOG_MODULE_REGISTER(hello_world, LOG_LEVEL_DBG);
17
18 static const char *hexdump_msg = "HEXDUMP! HEXDUMP@ HEXDUMP#";
19
main(void)20 int main(void)
21 {
22 int8_t i8 = 1;
23 uint8_t u8 = 2;
24 int16_t i16 = 16;
25 uint16_t u16 = 17;
26 int32_t i32 = 32;
27 uint32_t u32 = 33;
28 int64_t i64 = 64;
29 uint64_t u64 = 65;
30 char c = '!';
31 char *s = "static str";
32 char *s1 = "c str";
33 char vs0[32];
34 char vs1[32];
35 void *p = s;
36
37 printk("Hello World! %s\n", CONFIG_BOARD);
38
39 LOG_ERR("error string");
40 LOG_DBG("debug string");
41 LOG_INF("info string");
42
43 LOG_DBG("int8_t %" PRId8 ", uint8_t %" PRIu8, i8, u8);
44 LOG_DBG("int16_t %" PRId16 ", uint16_t %" PRIu16, i16, u16);
45 LOG_DBG("int32_t %" PRId32 ", uint32_t %" PRIu32, i32, u32);
46 LOG_DBG("int64_t %" PRId64 ", uint64_t %" PRIu64, i64, u64);
47
48 memset(vs0, 0, sizeof(vs0));
49 snprintk(&vs0[0], sizeof(vs0), "%s", "dynamic str");
50
51 memset(vs1, 0, sizeof(vs1));
52 snprintk(&vs1[0], sizeof(vs1), "%s", "another dynamic str");
53
54 LOG_DBG("char %c", c);
55 LOG_DBG("s str %s %s", s, s1);
56 LOG_DBG("d str %s", vs0);
57 LOG_DBG("mixed str %s %s %s %s %s %s %s", vs0, "---", vs0, "---", vs1, "---", vs1);
58 LOG_DBG("mixed c/s %c %s %s %s %c", c, s, vs0, s, c);
59
60 LOG_DBG("pointer %p", p);
61
62 LOG_HEXDUMP_DBG(hexdump_msg, strlen(hexdump_msg), "For HeXdUmP!");
63
64 #ifdef CONFIG_FPU
65 float f = 66.67;
66 double d = 68.69;
67
68 LOG_DBG("float %f, double %f", (double)f, d);
69 #ifdef CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE
70 long double ld = 70.71L;
71
72 LOG_DBG("long double %Lf", ld);
73 #endif
74 #endif
75
76 #if defined(CONFIG_STDOUT_CONSOLE)
77 /*
78 * When running through twister with pytest, we need to add a newline
79 * at the end of logging output for the output to be registered via
80 * pipe or FIFO in the pytest harness as reading is on a line-by-line
81 * basis. So send newline characters to flush the output.
82 */
83 fputc('\r', stdout);
84 fputc('\n', stdout);
85 #endif
86
87 return 0;
88 }
89
rt_demo_cmd(const struct shell * sh,size_t argc,char ** argv)90 static int rt_demo_cmd(const struct shell *sh, size_t argc, char **argv)
91 {
92 ARG_UNUSED(sh);
93 LOG_ERR("demo %s", argc > 1 ? argv[1] : "");
94 LOG_WRN("demo %s", argc > 1 ? argv[1] : "");
95 LOG_INF("demo %s", argc > 1 ? argv[1] : "");
96 LOG_DBG("demo %s", argc > 1 ? argv[1] : "");
97
98 return 0;
99 }
100
101 SHELL_CMD_REGISTER(log_rt_demo, NULL, "Command can be used to test runtime filtering", rt_demo_cmd);
102