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
56
57
58
59
60
61
62
63
// Copyright 2026 Ethan Wu
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//! Compile-time debug (CDBG) shared-memory layout.
//!
//! The debug ring uses the **same** shared-memory format as the IPC region; the
//! builder injects the `[dbg]` section of `Consortium.toml` as `CONSORTIUM_DBG_*`
//! environment variables, which this module reads with `option_env!` and parses
//! in a `const` context. The builder emits numeric values as decimal strings;
//! this replaces the previous `extern "C"` linker symbols
//! (`CONSORTIUM_DBG_SRAM_BASE`/`CONSORTIUM_DBG_SRAM_SIZE`) and the matching
//! `#[no_mangle]` statics the firmware had to define.
//!
//! When the variables are absent (a plain `cargo build`), [`CONFIGURED`] is
//! `false`, [`BASE`] is `0`, and the `logger::ConsortiumLogger` becomes
//! a no-op. That is what lets firmware crates be `cargo check`ed without running
//! the build pipeline.
//!
//! The trade-off is that a real firmware image built without the pipeline logs
//! nothing, silently. Firmware that must not ship that way should assert
//! [`CONFIGURED`] at compile time:
//!
//! ```rust,ignore
//! const _: () = assert!(
//! consortium_dbg::config::CONFIGURED,
//! "debug logging requires `csti build` to inject CONSORTIUM_DBG_*",
//! );
//! ```
const
/// `true` when the builder injected the `[dbg]` shared-memory layout.
pub const CONFIGURED: bool = option_env!.is_some;
/// Physical base address of the debug region, as seen by the MCU (raw memory).
pub const BASE: u64 = parse!;
/// Length of the debug region in bytes.
pub const LENGTH: u64 = parse!;
/// Debug region base as a raw mutable pointer for the MCU side.
pub const BASE_PTR: *mut u8 = BASE as *mut u8;
/// Debug region length truncated to the descriptor's `u16` size field.
pub const SIZE: u16 = LENGTH as u16;