@@ -19,6 +19,9 @@ use hifive1::{hal::core::plic::Priority, hal::prelude::*, hal::DeviceResources,
1919use riscv:: register:: mstatus;
2020use 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