-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
615c802
commit d1bfdb0
Showing
14 changed files
with
224 additions
and
180 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[target.'cfg(all(target_arch = "riscv32", target_os = "none"))'] | ||
runner = "qemu-system-riscv32 -machine sifive_e,revb=true -nographic -kernel" | ||
# runner = "riscv64-unknown-elf-gdb -q -x gdb_init" | ||
rustflags = [ | ||
"-C", "link-arg=-Thifive1-link.x", | ||
] | ||
|
||
[build] | ||
target = "riscv32imac-unknown-none-elf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"cortex-debug.variableUseNaturalFormat": true | ||
} | ||
"cortex-debug.variableUseNaturalFormat": true, | ||
"rust-analyzer.cargo.features": ["board-redv"], | ||
"rust-analyzer.check.allTargets": false, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! Demonstration on how to configure the GPIO4 interrupt on HiFive boards. | ||
//! You must connect a button to pin 12 (GPIO4) and ground to test this example. | ||
|
||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate panic_halt; | ||
|
||
use hifive1::hal::e310x::PLIC; | ||
use hifive1::{hal::prelude::*, hal::DeviceResources, pin, sprintln}; | ||
|
||
use riscv::register::mstatus; | ||
use riscv_rt::entry; | ||
|
||
/* Handler for the GPIO0 interrupt */ | ||
#[riscv_rt::external_interrupt(ExternalInterrupt::GPIO4)] | ||
fn gpio4_handler() { | ||
sprintln!("We reached the GPIO4 interrupt!"); | ||
/* Clear the GPIO pending interrupt */ | ||
let gpio_block = unsafe { hifive1::hal::e310x::Gpio0::steal() }; | ||
gpio_block.fall_ip().write(|w| w.pin4().set_bit()); | ||
} | ||
|
||
/* Code adapted from https://github.com/riscv-rust/riscv-rust-quickstart/blob/interrupt-test/examples/interrupt.rs*/ | ||
#[entry] | ||
fn main() -> ! { | ||
/* Get the ownership of the device resources singleton */ | ||
let resources = DeviceResources::take().unwrap(); | ||
let peripherals = resources.peripherals; | ||
|
||
/* Configure system clock */ | ||
let sysclock = hifive1::configure_clocks(peripherals.PRCI, peripherals.AONCLK, 64.mhz().into()); | ||
/* Get the board pins */ | ||
let gpio = resources.pins; | ||
|
||
/* Configure stdout for debugging */ | ||
hifive1::stdout::configure( | ||
peripherals.UART0, | ||
pin!(gpio, uart0_tx), | ||
pin!(gpio, uart0_rx), | ||
115_200.bps(), | ||
sysclock, | ||
); | ||
|
||
sprintln!("Configuring GPIO..."); | ||
/* Set GPIO4 (pin 12) as input */ | ||
// let gpio4 = pin!(gpio, dig12); | ||
gpio.pin4.into_pull_up_input(); | ||
//let input = gpio4.into_pull_up_input(); | ||
|
||
sprintln!("Configuring priorities..."); | ||
/* Set interrupt source priority */ | ||
let priorities = PLIC::priorities(); | ||
unsafe { priorities.set_priority(ExternalInterrupt::GPIO4, Priority::P7) }; | ||
|
||
let gpio_block = unsafe { hifive1::hal::e310x::Gpio0::steal() }; | ||
unsafe { | ||
/* Clear pending interrupts from previous states */ | ||
gpio_block.fall_ie().write(|w| w.bits(0x00000000)); | ||
gpio_block.rise_ie().write(|w| w.bits(0x00000000)); | ||
gpio_block.fall_ip().write(|w| w.bits(0xffffffff)); | ||
gpio_block.rise_ip().write(|w| w.bits(0xffffffff)); | ||
} | ||
gpio_block.fall_ie().write(|w| w.pin4().set_bit()); | ||
gpio_block.rise_ie().write(|w| w.pin4().clear_bit()); | ||
|
||
/* Activate global interrupts (mie bit) */ | ||
let ctx = PLIC::ctx0(); | ||
unsafe { | ||
ctx.threshold().set_threshold(Priority::P1); | ||
ctx.enables().enable(ExternalInterrupt::GPIO4); | ||
mstatus::set_mie(); | ||
PLIC::enable(); | ||
} | ||
loop { | ||
riscv::asm::wfi(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//! This example demonstrates how to configure the CLINT to generate | ||
//! periodic interrupts using the machine timer. | ||
|
||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate panic_halt; | ||
|
||
use hifive1::{ | ||
configure_clocks, | ||
hal::{e310x::CLINT, prelude::*, DeviceResources}, | ||
pin, sprintln, | ||
}; | ||
|
||
const PERIOD_MS: u64 = 1000; | ||
const FREQUENCY_HZ: u64 = 32768; | ||
const CLINT_TICKS_PER_MS: u64 = PERIOD_MS * FREQUENCY_HZ / 1000; | ||
|
||
/// Handler for the machine timer interrupt (handled by the CLINT) | ||
#[riscv_rt::core_interrupt(CoreInterrupt::MachineTimer)] | ||
fn mtimer_handler() { | ||
sprintln!("MTIMER interrupt!"); | ||
CLINT::mtimecmp0().modify(|f| *f += CLINT_TICKS_PER_MS); | ||
} | ||
|
||
#[riscv_rt::entry] | ||
fn main() -> ! { | ||
/* Get the ownership of the device resources singleton */ | ||
let resources = DeviceResources::take().unwrap(); | ||
let peripherals = resources.peripherals; | ||
|
||
/* Configure system clock */ | ||
let sysclock = configure_clocks(peripherals.PRCI, peripherals.AONCLK, 64.mhz().into()); | ||
|
||
/* Configure stdout for printing via UART */ | ||
let gpio = resources.pins; | ||
hifive1::stdout::configure( | ||
peripherals.UART0, | ||
pin!(gpio, uart0_tx), | ||
pin!(gpio, uart0_rx), | ||
115_200.bps(), | ||
sysclock, | ||
); | ||
|
||
sprintln!("Configuring CLINT..."); | ||
CLINT::mtimer_disable(); | ||
let mtimer = CLINT::mtimer(); | ||
let (mtimecmp, mtime) = (mtimer.mtimecmp0, mtimer.mtime); | ||
mtime.write(0); | ||
mtimecmp.write(CLINT_TICKS_PER_MS); | ||
|
||
sprintln!("Enabling interrupts..."); | ||
unsafe { | ||
riscv::interrupt::enable(); | ||
CLINT::mtimer_enable(); | ||
} | ||
loop { | ||
sprintln!("Sleeping..."); | ||
riscv::asm::wfi(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.