Skip to content

Commit 4b749fb

Browse files
committed
itm: inline cortex-m structs for fast v0.8 release
Refer to #15.
1 parent 01c2cbb commit 4b749fb

File tree

5 files changed

+121
-9
lines changed

5 files changed

+121
-9
lines changed

itm/Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ git = "https://github.com/rtic-scope/nix.git"
2828
branch = "feat/termios-linux-arbitrary"
2929
optional = true
3030

31-
[dependencies.cortex-m]
32-
version = "0.7"
33-
git = "https://github.com/rtic-scope/cortex-m"
34-
branch = "rtic-scope"
35-
features = ["serde"]
36-
3731
[features]
3832
default = []
3933
serial = ["nix"]

itm/src/cortex_m.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#[cfg(feature = "serde")]
2+
use serde::{Deserialize, Serialize};
3+
4+
/// The possible local timestamp options.
5+
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
6+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7+
pub enum LocalTimestampOptions {
8+
/// Disable local timestamps.
9+
Disabled,
10+
/// Enable local timestamps and use no prescaling.
11+
Enabled,
12+
/// Enable local timestamps and set the prescaler to divide the
13+
/// reference clock by 4.
14+
EnabledDiv4,
15+
/// Enable local timestamps and set the prescaler to divide the
16+
/// reference clock by 16.
17+
EnabledDiv16,
18+
/// Enable local timestamps and set the prescaler to divide the
19+
/// reference clock by 64.
20+
EnabledDiv64,
21+
}
22+
23+
/// Active exception number
24+
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Hash)]
25+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26+
pub enum VectActive {
27+
/// Thread mode
28+
ThreadMode,
29+
30+
/// Processor core exception (internal interrupts)
31+
Exception(Exception),
32+
33+
/// Device specific exception (external interrupts)
34+
Interrupt {
35+
/// Interrupt number. This number is always within half open range `[0, 512)` (9 bit)
36+
irqn: u16,
37+
},
38+
}
39+
40+
impl VectActive {
41+
/// Converts a vector number into `VectActive`
42+
#[inline]
43+
pub fn from(vect_active: u16) -> Option<Self> {
44+
Some(match vect_active {
45+
0 => VectActive::ThreadMode,
46+
2 => VectActive::Exception(Exception::NonMaskableInt),
47+
3 => VectActive::Exception(Exception::HardFault),
48+
4 => VectActive::Exception(Exception::MemoryManagement),
49+
5 => VectActive::Exception(Exception::BusFault),
50+
6 => VectActive::Exception(Exception::UsageFault),
51+
7 => VectActive::Exception(Exception::SecureFault),
52+
11 => VectActive::Exception(Exception::SVCall),
53+
12 => VectActive::Exception(Exception::DebugMonitor),
54+
14 => VectActive::Exception(Exception::PendSV),
55+
15 => VectActive::Exception(Exception::SysTick),
56+
irqn if (16..512).contains(&irqn) => VectActive::Interrupt { irqn: irqn - 16 },
57+
_ => return None,
58+
})
59+
}
60+
}
61+
62+
/// Processor core exceptions (internal interrupts)
63+
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Hash)]
64+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
65+
pub enum Exception {
66+
/// Non maskable interrupt
67+
NonMaskableInt,
68+
69+
/// Hard fault interrupt
70+
HardFault,
71+
72+
/// Memory management interrupt (not present on Cortex-M0 variants)
73+
MemoryManagement,
74+
75+
/// Bus fault interrupt (not present on Cortex-M0 variants)
76+
BusFault,
77+
78+
/// Usage fault interrupt (not present on Cortex-M0 variants)
79+
UsageFault,
80+
81+
/// Secure fault interrupt (only on ARMv8-M)
82+
SecureFault,
83+
84+
/// SV call interrupt
85+
SVCall,
86+
87+
/// Debug monitor interrupt (not present on Cortex-M0 variants)
88+
DebugMonitor,
89+
90+
/// Pend SV interrupt
91+
PendSV,
92+
93+
/// System Tick interrupt
94+
SysTick,
95+
}
96+
97+
impl Exception {
98+
/// Returns the IRQ number of this `Exception`
99+
///
100+
/// The return value is always within the closed range `[-1, -14]`
101+
#[inline]
102+
pub fn irqn(self) -> i8 {
103+
match self {
104+
Exception::NonMaskableInt => -14,
105+
Exception::HardFault => -13,
106+
Exception::MemoryManagement => -12,
107+
Exception::BusFault => -11,
108+
Exception::UsageFault => -10,
109+
Exception::SecureFault => -9,
110+
Exception::SVCall => -5,
111+
Exception::DebugMonitor => -4,
112+
Exception::PendSV => -2,
113+
Exception::SysTick => -1,
114+
}
115+
}
116+
}

itm/src/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::{
55
use std::io::Read;
66
use std::time::Duration;
77

8-
pub use cortex_m::peripheral::itm::LocalTimestampOptions;
8+
pub use crate::cortex_m::LocalTimestampOptions;
99

1010
/// Iterator that yield [`TracePacket`](TracePacket).
1111
pub struct Singles<R>

itm/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ pub use iter::{
4141
#[cfg(feature = "serial")]
4242
pub mod serial;
4343

44+
pub mod cortex_m;
45+
use cortex_m::VectActive;
46+
4447
use std::convert::TryInto;
4548
use std::io::Read;
4649

4750
use bitmatch::bitmatch;
4851
use bitvec::prelude::*;
49-
pub use cortex_m::peripheral::scb::VectActive;
5052

5153
/// The set of valid packet types that can be decoded.
5254
#[derive(Debug, Clone, PartialEq)]

itm/tests/singles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn decode_exceptiontrace_packet() {
173173
assert_eq!(
174174
decoder.singles().next().unwrap().unwrap(),
175175
TracePacket::ExceptionTrace {
176-
exception: cortex_m::peripheral::scb::VectActive::Interrupt { irqn: 16 },
176+
exception: itm::cortex_m::VectActive::Interrupt { irqn: 16 },
177177
action: ExceptionAction::Returned,
178178
}
179179
);

0 commit comments

Comments
 (0)