Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.

Commit f63f1e4

Browse files
committed
Merge pull request #162 from dpc/app_blink_k20_isr
k20: Introduce `app_blink_k20_isr`.
2 parents e2dfa9e + 1003723 commit f63f1e4

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ end
175175
desc "Build all applications"
176176
case ENV['PLATFORM']
177177
when 'k20'
178-
task :build_all => [:build_blink_k20]
178+
task :build_all => [:build_blink_k20, :build_blink_k20_isr]
179179
when 'stm32f4'
180180
task :build_all => [:build_blink_stm32f4]
181181
else

apps/app_blink_k20_isr.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#![feature(phase)]
2+
#![feature(asm)]
3+
#![crate_type="staticlib"]
4+
#![no_std]
5+
6+
extern crate core;
7+
extern crate zinc;
8+
9+
use core::intrinsics::volatile_load;
10+
11+
use core::option::Some;
12+
use zinc::hal::k20::{pin, watchdog};
13+
use zinc::hal::pin::GPIO;
14+
use zinc::hal::cortex_m4::systick;
15+
use zinc::util::support::wfi;
16+
17+
static mut i: u32 = 0;
18+
static mut global_on: u32 = 0;
19+
20+
#[allow(dead_code)]
21+
#[no_split_stack]
22+
#[no_mangle]
23+
pub unsafe extern fn isr_systick() {
24+
i += 1;
25+
if i > 100 {
26+
i = 0;
27+
global_on = !global_on;
28+
}
29+
}
30+
31+
#[no_mangle]
32+
#[no_split_stack]
33+
#[allow(dead_code)]
34+
pub fn main() {
35+
zinc::hal::mem_init::init_stack();
36+
zinc::hal::mem_init::init_data();
37+
watchdog::init(watchdog::Disabled);
38+
39+
// Pins for MC HCK (http://www.mchck.org/)
40+
let led1 = pin::Pin::new(pin::PortB, 16, pin::GPIO, Some(zinc::hal::pin::Out));
41+
42+
systick::setup(systick::ten_ms().unwrap_or(480000));
43+
systick::enable();
44+
systick::enable_irq();
45+
46+
loop {
47+
let on: bool = unsafe { volatile_load(&global_on as *const u32) == 0 };
48+
match on {
49+
true => led1.set_high(),
50+
false => led1.set_low(),
51+
}
52+
wfi();
53+
}
54+
}

src/zinc/util/support.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,15 @@ pub fn nop() {
6969
/// NOP instruction (mock)
7070
pub fn nop() {
7171
}
72+
73+
#[cfg(not(test))]
74+
#[inline(always)]
75+
/// WFI instruction
76+
pub fn wfi() {
77+
unsafe { asm!("wfi" :::: "volatile"); }
78+
}
79+
80+
#[cfg(test)]
81+
/// WFI instruction (mock)
82+
pub fn wfi() {
83+
}

0 commit comments

Comments
 (0)