extern crate prusst;
use prusst::{Pruss, IntcConfig, Evtout, Sysevt};
use std::fs::File;
use std::io::Write;
static LED_TRIGGER_PATH: &'static str = "/sys/class/leds/beaglebone:green:usr1/trigger";
static LED_DEFAULT_TRIGGER: &'static str = "mmc0";
fn echo(value: &str, path: &str) {
let mut file = File::create(path).unwrap();
file.write_all(value.as_bytes()).unwrap();
}
fn main() {
let mut pruss = match Pruss::new(&IntcConfig::new_populated()) {
Ok(p) => p,
Err(e) => match e {
prusst::Error::AlreadyInstantiated
=> panic!("You can't instantiate more than one `Pruss` object at a time."),
prusst::Error::PermissionDenied
=> panic!("You do not have permission to access the PRU subsystem: \
maybe you should run this program as root?"),
prusst::Error::DeviceNotFound
=> panic!("The PRU subsystem could not be found: are you sure the `uio_pruss` \
module is loaded and supported by your kernel?"),
prusst::Error::OtherDeviceError
=> panic!("An unidentified problem occured with the PRU subsystem: \
do you have a valid overlay loaded?")
}
};
let irq = pruss.intc.register_irq(Evtout::E0);
let mut pru_binary = File::open("examples/barebone_blink_pru0.bin").unwrap();
echo("none", LED_TRIGGER_PATH);
unsafe { pruss.pru0.load_code(&mut pru_binary).unwrap().run(); }
for i in 1..6 {
irq.wait();
println!("Blink {}", i);
pruss.intc.clear_sysevt(Sysevt::S19);
pruss.intc.enable_host(Evtout::E0);
}
irq.wait();
pruss.intc.clear_sysevt(Sysevt::S19);
println!("Goodbye!");
echo(LED_DEFAULT_TRIGGER, LED_TRIGGER_PATH);
}