-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.c
55 lines (47 loc) · 1.28 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright (c) 2024 Linaro LTD
* SPDX-License-Identifier: Apache-2.0
*/
/* This main is brought into the Rust application. */
#include <zephyr/kernel.h>
#ifdef CONFIG_RUST
extern void rust_main(void);
#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_MINIMAL)
// Logging, to see how things things are expanded.
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(rust, 3);
void rust_log_message(uint32_t level, char *msg) {
// Ok. The log macros in Zephyr perform all kinds of macro stitching, etc, on the
// arguments. As such, we can't just pass the level to something, but actually need to
// expand things here. This puts the file and line information of the log in this file,
// rather than where we came from.
switch (level) {
case LOG_LEVEL_ERR:
LOG_ERR("%s", msg);
break;
case LOG_LEVEL_WRN:
LOG_WRN("%s", msg);
break;
case LOG_LEVEL_INF:
LOG_INF("%s", msg);
break;
case LOG_LEVEL_DBG:
default:
LOG_DBG("%s", msg);
break;
}
}
#endif /* defined(CONFIG_LOG) && !defined(CONFIG_LOG_MINIMAL) */
int main(void)
{
rust_main();
return 0;
}
/* On most arches, panic is entirely macros resulting in some kind of inline assembly. Create this
* wrapper so the Rust panic handler can call the same kind of panic.
*/
void rust_panic_wrap(void)
{
k_panic();
}
#endif