Skip to content

Commit c19fded

Browse files
committed
Try #106:
2 parents dfd0349 + 131071a commit c19fded

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ volatile-register = "0.2.0"
2020
[features]
2121
cm7-r0p1 = []
2222
const-fn = ["bare-metal/const-fn"]
23-
inline-asm = []
23+
inline-asm = []

src/peripheral/dcb.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use volatile_register::{RW, WO};
44

5+
use peripheral::DCB;
6+
57
/// Register block
68
#[repr(C)]
79
pub struct RegisterBlock {
@@ -14,3 +16,10 @@ pub struct RegisterBlock {
1416
/// Debug Exception and Monitor Control
1517
pub demcr: RW<u32>,
1618
}
19+
20+
impl DCB {
21+
/// Is there a debugger attached?
22+
pub fn is_debugger_attached(&self) -> bool {
23+
self.dhcsr.read() & 0x1 == 1
24+
}
25+
}

src/peripheral/nvic.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Nested Vector Interrupt Controller
22
33
#[cfg(not(armv6m))]
4-
use volatile_register::RO;
4+
use volatile_register::{RO, WO};
55
use volatile_register::RW;
66

77
use interrupt::Nr;
@@ -65,9 +65,36 @@ pub struct RegisterBlock {
6565
/// so convenient byte-sized representation wouldn't work on that
6666
/// architecture.
6767
pub ipr: [RW<u32>; 8],
68+
69+
#[cfg(not(armv6m))]
70+
reserved5: [u32; 208],
71+
72+
#[cfg(armv6m)]
73+
reserved5: [u32; 696],
74+
75+
#[cfg(not(armv6m))]
76+
/// Software Trigger Interrupt
77+
pub stir: WO<u32>,
6878
}
6979

7080
impl NVIC {
81+
#[cfg(not(armv6m))]
82+
/// Request an IRQ in software
83+
///
84+
/// Writing a value to the INTID field is the same as manually pending an interrupt by setting
85+
/// the corresponding interrupt bit in an Interrupt Set Pending Register. This is similar to
86+
/// `set_pending`.
87+
pub fn request<I>(&mut self, interrupt: I)
88+
where
89+
I: Nr,
90+
{
91+
let nr = interrupt.nr();
92+
93+
unsafe {
94+
self.stir.write(nr as u32);
95+
}
96+
}
97+
7198
/// Clears `interrupt`'s pending state
7299
pub fn clear_pending<I>(&mut self, interrupt: I)
73100
where

src/peripheral/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ fn nvic() {
109109
assert_eq!(address(&nvic.icpr), 0xE000E280);
110110
assert_eq!(address(&nvic.iabr), 0xE000E300);
111111
assert_eq!(address(&nvic.ipr), 0xE000E400);
112+
assert_eq!(address(&nvic.stir), 0xE000EF00);
112113
}
113114

114115
#[test]

0 commit comments

Comments
 (0)