Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ end
desc "Build all applications"
case ENV['PLATFORM']
when 'k20'
task :build_all => [:build_blink_k20]
task :build_all => [:build_blink_k20, :build_blink_k20_isr]
when 'stm32f4'
task :build_all => [:build_blink_stm32f4]
else
Expand Down
54 changes: 54 additions & 0 deletions apps/app_blink_k20_isr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#![feature(phase)]
#![feature(asm)]
#![crate_type="staticlib"]
#![no_std]

extern crate core;
extern crate zinc;

use core::intrinsics::volatile_load;

use core::option::Some;
use zinc::hal::k20::{pin, watchdog};
use zinc::hal::pin::GPIO;
use zinc::hal::cortex_m4::systick;
use zinc::util::support::wfi;

static mut i: u32 = 0;
static mut global_on: u32 = 0;

#[allow(dead_code)]
#[no_split_stack]
#[no_mangle]
pub unsafe extern fn isr_systick() {
i += 1;
if i > 100 {
i = 0;
global_on = !global_on;
}
}

#[no_mangle]
#[no_split_stack]
#[allow(dead_code)]
pub fn main() {
zinc::hal::mem_init::init_stack();
zinc::hal::mem_init::init_data();
watchdog::init(watchdog::Disabled);

// Pins for MC HCK (http://www.mchck.org/)
let led1 = pin::Pin::new(pin::PortB, 16, pin::GPIO, Some(zinc::hal::pin::Out));

systick::setup(systick::ten_ms().unwrap_or(480000));
systick::enable();
systick::enable_irq();

loop {
let on: bool = unsafe { volatile_load(&global_on as *const u32) == 0 };
match on {
true => led1.set_high(),
false => led1.set_low(),
}
wfi();
}
}
12 changes: 12 additions & 0 deletions src/zinc/util/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ pub fn nop() {
/// NOP instruction (mock)
pub fn nop() {
}

#[cfg(not(test))]
#[inline(always)]
/// WFI instruction
pub fn wfi() {
unsafe { asm!("wfi" :::: "volatile"); }
}

#[cfg(test)]
/// WFI instruction (mock)
pub fn wfi() {
}