Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit c84bed2

Browse files
committed
Change constant to bitshift
1 parent 04031d6 commit c84bed2

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

.cargo/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[target.riscv32imac-unknown-none-elf]
2-
runner = "../../../toolchains/sifive/bin/riscv64-unknown-elf-gdb -q -x gdb_init"
2+
runner = "../../Toolchains/sifive/bin/riscv64-unknown-elf-gdb -q -x gdb_init"
33
rustflags = [
44
"-C", "link-arg=-Thifive1-link.x",
55
]

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"interface": "jtag",
2121
"svdFile": "${workspaceRoot}/hifive.svd",
2222
// Set this to point to sifive risc-v gdb path
23-
"gdbPath": "${workspaceRoot}/../../../toolchains/sifive/bin/riscv64-unknown-elf-gdb",
23+
"gdbPath": "${workspaceRoot}/../../Toolchains/sifive/bin/riscv64-unknown-elf-gdb",
2424
"toolchainPrefix": "riscv64-unknown-elf",
2525
},
2626
]

examples/virq.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use hifive1::{hal::core::plic::Priority, hal::prelude::*, hal::DeviceResources,
1919
use riscv::register::mstatus;
2020
use riscv_rt::entry;
2121

22+
/* we have chosen the GPIO4 (a.k.a dig12) for this example */
23+
const GPIO_N : usize = 4;
24+
2225
/* Handler for the GPIO0 interrupt */
2326
#[no_mangle]
2427
#[allow(non_snake_case)]
@@ -27,7 +30,7 @@ fn GPIO4() {
2730
/* Clear the GPIO pending interrupt */
2831
unsafe {
2932
let gpio_block = &*hifive1::hal::e310x::GPIO0::ptr();
30-
gpio_block.fall_ip.write(|w| w.bits(0xffffffff));
33+
gpio_block.fall_ip.write(|w| w.bits(1<<GPIO_N));
3134
}
3235
}
3336

@@ -63,11 +66,11 @@ fn main() -> ! {
6366
unsafe {
6467
/* Get raw PLIC pointer */
6568
let rplic = &*hifive1::hal::e310x::PLIC::ptr();
66-
let gpio0_block_start = 7;
6769
/* Index 7 is the GPIO0 interrupt source start */
70+
let gpio0_block_start = 7;
6871
for (i, p) in rplic.priority.iter().enumerate() {
6972
/* set priority of our interrupt */
70-
if i == gpio0_block_start + 5 {
73+
if i == gpio0_block_start + (GPIO_N + 1) {
7174
p.write(|w| w.bits(0xffffffff));
7275
} else {
7376
/* Clear all other priorities */
@@ -76,11 +79,11 @@ fn main() -> ! {
7679
}
7780
let gpio_block = &*hifive1::hal::e310x::GPIO0::ptr();
7881
/* Enable GPIO fall interrupts */
79-
gpio_block.fall_ie.write(|w| w.bits(0xffffffff));
82+
gpio_block.fall_ie.write(|w| w.bits(1<<GPIO_N));
8083
gpio_block.rise_ie.write(|w| w.bits(0x0));
8184
/* Clear pending interrupts from previous states */
8285
gpio_block.fall_ip.write(|w| w.bits(0xffffffff));
83-
gpio_block.rise_ip.write(|w| w.bits(0x0));
86+
gpio_block.rise_ip.write(|w| w.bits(0x0fffffff));
8487

8588
/* Activate global interrupts (mie bit) */
8689
mstatus::set_mie();

0 commit comments

Comments
 (0)