Created
July 18, 2016 18:13
-
-
Save thiagopnts/ef717d8612b92f0d8618fd19e734fb66 to your computer and use it in GitHub Desktop.
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
#![feature(no_std, lang_items, start, core_intrinsics, asm)] | |
#![crate_type = "staticlib"] | |
#![no_std] | |
const GPIO_BASE: u32 = 0x20200000; | |
const TIMER_BASE: u32 = 0x20003000; | |
const LED_GPFSEL: isize = 4; | |
const LED_GPFBIT: isize = 21; | |
const LED_GPSET: isize = 8; | |
const LED_GPCLR: isize = 11; | |
const LED_GPIO_BIT: isize = 15; | |
#[no_mangle] | |
pub fn main() { | |
let gpio = GPIO_BASE as *const u32; | |
let counter_lo = (TIMER_BASE + 0x4) as *mut u32; | |
loop { | |
let ts = unsafe { *(counter_lo) as u32 }; | |
while (unsafe { *(counter_lo) as u32 } - ts) < 500000 { | |
unsafe { asm!("") } | |
} | |
unsafe { | |
*(gpio.offset(LED_GPCLR) as *mut _) = 1 << LED_GPIO_BIT; | |
} | |
let ts = unsafe { *(counter_lo) as u32 }; | |
while (unsafe { *(counter_lo) as u32 } - ts) < 500000 { | |
unsafe { asm!("") } | |
} | |
unsafe { | |
*(gpio.offset(LED_GPSET) as *mut _) = 1 << LED_GPIO_BIT; | |
} | |
} | |
} | |
#[lang = "rust_begin_unwind"] extern fn rust_begin_unwind() {} | |
#[lang = "eh_personality"] extern fn eh_personality() {} | |
#[lang = "panic_fmt"] extern fn panic_fmt() -> ! { loop {} } | |
#[no_mangle] | |
pub unsafe fn __aeabi_unwind_cpp_pr0() -> () { | |
loop {} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment