<commit_before>#![allow(dead_code, non_camel_case_types)]

extern crate libc;

pub use self::os::{mdb_mode_t, mdb_filehandle_t};
use libc::{c_int, c_uint, c_void, c_char, size_t};

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "linux",
          target_os = "freebsd", target_os = "android"))]
mod os {
    use libc;

    #[stable]
    pub type mdb_mode_t = libc::mode_t;
    #[stable]
    pub type mdb_filehandle_t = libc::c_int;
}

#[cfg(target_os = "windows")]
mod os {
    use libc::{c_int, c_void};

    #[stable]
    pub type mdb_mode_t = c_int;
    #[stable]
    pub type mdb_filehandle_t = *const c_void;
}

pub type MDB_dbi = c_uint;

pub type MDB_rel_func = fn(*const MDB_val, *const c_void, *const c_void, *const c_void);
pub type MDB_msg_func = fn(*const c_char, *const c_void) -> c_int;
pub type MDB_cmp_func = fn(*const MDB_val, *const MDB_val) -> c_int;

#[deriving(Copy, Clone)]
#[allow(raw_pointer_deriving)]
#[repr(C)]
#[stable]
pub struct MDB_val {
    pub mv_size: size_t,
    pub mv_data: *const c_void,
}

#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct MDB_env;

#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct MDB_txn;

#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct MDB_cursor;

#[repr(C)]
#[stable]
#[deriving(Copy)]
pub struct MDB_stat {
    pub ms_psize: c_uint,
    pub ms_depth: c_uint,
    pub ms_branch_pages: size_t,
    pub ms_leaf_pages: size_t,
    pub ms_overflow_pages: size_t,
    pub ms_entries: size_t
}

#[repr(C)]
#[stable]
#[allow(missing_copy_implementations)]
pub struct MDB_envinfo {
    pub me_mapaddr: *const c_void,
    pub me_mapsize: size_t,
    pub me_last_pgno: size_t,
    pub me_last_txnid: size_t,
    pub me_maxreaders: c_uint,
    pub me_numreaders: c_uint
}

#[repr(C)]
#[deriving(Copy, Eq, PartialEq)]
pub enum MDB_cursor_op {
    MDB_FIRST,
    MDB_FIRST_DUP,
    MDB_GET_BOTH,
    MDB_GET_BOTH_RANGE,
    MDB_GET_CURRENT,
    MDB_GET_MULTIPLE,
    MDB_LAST,
    MDB_LAST_DUP,
    MDB_NEXT,
    MDB_NEXT_DUP,
    MDB_NEXT_MULTIPLE,
    MDB_NEXT_NODUP,
    MDB_PREV,
    MDB_PREV_DUP,
    MDB_PREV_NODUP,
    MDB_SET,
    MDB_SET_KEY,
    MDB_SET_RANGE
}

// Return codes
pub const MDB_SUCCESS: c_int = 0;
pub const MDB_KEYEXIST: c_int = -30799;
pub const MDB_NOTFOUND: c_int = -30798;
pub const MDB_PAGE_NOTFOUND: c_int = -30797;
pub const MDB_CORRUPTED: c_int = -30796;
pub const MDB_PANIC: c_int = -30795;
pub const MDB_VERSION_MISMATCH: c_int = -30794;
pub const MDB_INVALID: c_int = -30793;
pub const MDB_MAP_FULL: c_int = -30792;
pub const MDB_DBS_FULL: c_int = -30791;
pub const MDB_READERS_FULL: c_int = -30790;
pub const MDB_TLS_FULL: c_int = -30789;
pub const MDB_TXN_FULL: c_int = -30788;
pub const MDB_CURSOR_FULL: c_int = -30787;
pub const MDB_PAGE_FULL: c_int = -30786;
pub const MDB_MAP_RESIZED: c_int = -30785;
pub const MDB_INCOMPATIBLE: c_int = -30784;
pub const MDB_BAD_RSLOT: c_int = -30783;
pub const MDB_BAD_TXN: c_int = -30782;
pub const MDB_BAD_VALSIZE: c_int = -30781;

// Write flags
pub const MDB_NOOVERWRITE: c_uint = 0x10;
pub const MDB_NODUPDATA: c_uint = 0x20;
pub const MDB_CURRENT: c_uint = 0x40;
pub const MDB_RESERVE: c_uint = 0x10000;
pub const MDB_APPEND: c_uint = 0x20000;
pub const MDB_APPENDDUP: c_uint = 0x40000;
pub const MDB_MULTIPLE: c_uint = 0x80000;

// Database flags
pub const MDB_REVERSEKEY: c_uint = 0x02;
pub const MDB_DUPSORT: c_uint = 0x04;
pub const MDB_INTEGERKEY: c_uint = 0x08;
pub const MDB_DUPFIXED: c_uint = 0x10;
pub const MDB_INTEGERDUP: c_uint = 0x20;
pub const MDB_REVERSEDUP: c_uint =  0x40;
pub const MDB_CREATE: c_uint = 0x40000;

// Environment flags
pub const MDB_FIXEDMAP: c_uint =  0x01;
pub const MDB_NOSUBDIR: c_uint = 0x4000;
pub const MDB_NOSYNC: c_uint = 0x10000;
pub const MDB_RDONLY: c_uint = 0x20000;
pub const MDB_NOMETASYNC: c_uint = 0x40000;
pub const MDB_WRITEMAP: c_uint = 0x80000;
pub const MDB_MAPASYNC: c_uint = 0x100000;
pub const MDB_NOTLS: c_uint = 0x200000;
pub const MDB_NOLOCK: c_uint =  0x400000;
pub const MDB_NORDAHEAD: c_uint = 0x800000;
pub const MDB_NOMEMINIT: c_uint =  0x1000000;

// Embedding should work better for now
extern "C" {
    pub fn mdb_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int) -> *const c_char;
    pub fn mdb_strerror(err: c_int) -> *const c_char;
    pub fn mdb_env_create(env: *mut *mut MDB_env) -> c_int;
    pub fn mdb_env_open(env: *mut MDB_env, path: *const c_char, flags: c_uint, mode: mdb_mode_t) -> c_int;
    pub fn mdb_env_copy(env: *mut MDB_env, path: *const c_char) -> c_int;
    pub fn mdb_env_copyfd(env: *mut MDB_env, fd: mdb_filehandle_t) -> c_int;
    pub fn mdb_env_stat(env: *mut MDB_env, stat: *mut MDB_stat) -> c_int;
    pub fn mdb_env_info(env: *mut MDB_env, info: *mut MDB_envinfo) -> c_int;
    pub fn mdb_env_sync(env: *mut MDB_env, force: c_int) -> c_int;
    pub fn mdb_env_close(env: *mut MDB_env);
    pub fn mdb_env_set_flags(env: *mut MDB_env, flags: c_uint, onoff: c_int) -> c_int;
    pub fn mdb_env_get_flags(env: *mut MDB_env, flags: *mut c_uint) -> c_int;
    pub fn mdb_env_get_path(env: *mut MDB_env, path: *mut *mut c_char) -> c_int;
    pub fn mdb_env_get_fd(env: *mut MDB_env, fd: *mut mdb_filehandle_t) -> c_int;
    pub fn mdb_env_set_mapsize(env: *mut MDB_env, size: size_t) -> c_int;
    pub fn mdb_env_set_maxreaders(env: *mut MDB_env, readers: c_uint) -> c_int;
    pub fn mdb_env_get_maxreaders(env: *mut MDB_env, readers: *mut c_uint) -> c_int;
    pub fn mdb_env_set_maxdbs(env: *mut MDB_env, dbs: MDB_dbi) -> c_int;
    pub fn mdb_env_get_maxkeysize(env: *mut MDB_env) -> c_int;
    pub fn mdb_txn_begin(env: *mut MDB_env, parent: *mut MDB_txn, flags: c_uint, txn: *mut *mut MDB_txn) -> c_int;
    pub fn mdb_txn_env(txn: *mut MDB_txn) -> *mut MDB_env;
    pub fn mdb_txn_commit(txn: *mut MDB_txn) -> c_int;
    pub fn mdb_txn_abort(txn: *mut MDB_txn);
    pub fn mdb_txn_reset(txn: *mut MDB_txn);
    pub fn mdb_txn_renew(txn: *mut MDB_txn) -> c_int;
    pub fn mdb_dbi_open(txn: *mut MDB_txn, name: *const c_char, flags: c_uint, dbi: *mut MDB_dbi) -> c_int;
    pub fn mdb_stat(txn: *mut MDB_txn, dbi: MDB_dbi, stat: *mut MDB_stat) -> c_int;
    pub fn mdb_dbi_flags(txn: *mut MDB_txn, dbi: MDB_dbi, flags: *mut c_uint) -> c_int;
    pub fn mdb_dbi_close(txn: *mut MDB_env, dbi: MDB_dbi);
    pub fn mdb_drop(txn: *mut MDB_txn, dbi: MDB_dbi, del: c_int) -> c_int;
    pub fn mdb_set_compare(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> c_int;
    pub fn mdb_set_dupsort(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> c_int;
    pub fn mdb_set_relfunc(txn: *mut MDB_txn, dbi: MDB_dbi, rel: MDB_rel_func) -> c_int;
    pub fn mdb_set_relctx(txn: *mut MDB_txn, dbi: MDB_dbi, ctx: *const c_void) -> c_int;
    pub fn mdb_get(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val) -> c_int;
    pub fn mdb_put(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val, flags: c_uint) -> c_int;
    pub fn mdb_del(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val) -> c_int;
    pub fn mdb_cursor_open(txn: *mut MDB_txn, dbi: MDB_dbi, cursor: *mut *mut MDB_cursor) -> c_int;
    pub fn mdb_cursor_close(cursor: *mut MDB_cursor) -> c_int;
    pub fn mdb_cursor_renew(txn: *mut MDB_txn, cursor: *mut MDB_cursor) -> c_int;
    pub fn mdb_cursor_txn(cursor: *mut MDB_cursor) -> *mut MDB_txn;
    pub fn mdb_cursor_dbi(cursor: *mut MDB_cursor) -> *mut MDB_dbi;
    pub fn mdb_cursor_get(cursor: *mut MDB_cursor, key: *mut MDB_val, data: *mut MDB_val, op: MDB_cursor_op) -> c_int;
    pub fn mdb_cursor_put(cursor: *mut MDB_cursor, key: *mut MDB_val, data: *mut MDB_val, flags: c_uint) -> c_int;
    pub fn mdb_cursor_del(cursor: *mut MDB_cursor, flags: c_uint) -> c_int;
    pub fn mdb_cursor_count(cursor: *mut MDB_cursor, countp: *mut size_t) -> c_int;
    pub fn mdb_cmp(txn: *mut MDB_txn, dbi: MDB_dbi, a: *mut MDB_val, b: *mut MDB_val) -> c_int;
    pub fn mdb_dcmp(txn: *mut MDB_txn, dbi: MDB_dbi, a: *mut MDB_val, b: *mut MDB_val) -> c_int;
    pub fn mdb_reader_list(env: *mut MDB_env, func: MDB_msg_func, ctx: *const c_void) -> c_int;
    pub fn mdb_reader_check(env: *mut MDB_env, dead: *mut c_int) -> c_int;
}
<commit_msg>deriving -> derive<commit_after>#![allow(dead_code, non_camel_case_types)]

extern crate libc;

pub use self::os::{mdb_mode_t, mdb_filehandle_t};
use libc::{c_int, c_uint, c_void, c_char, size_t};

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "linux",
          target_os = "freebsd", target_os = "android"))]
mod os {
    use libc;

    #[stable]
    pub type mdb_mode_t = libc::mode_t;
    #[stable]
    pub type mdb_filehandle_t = libc::c_int;
}

#[cfg(target_os = "windows")]
mod os {
    use libc::{c_int, c_void};

    #[stable]
    pub type mdb_mode_t = c_int;
    #[stable]
    pub type mdb_filehandle_t = *const c_void;
}

pub type MDB_dbi = c_uint;

pub type MDB_rel_func = fn(*const MDB_val, *const c_void, *const c_void, *const c_void);
pub type MDB_msg_func = fn(*const c_char, *const c_void) -> c_int;
pub type MDB_cmp_func = fn(*const MDB_val, *const MDB_val) -> c_int;

#[derive(Copy, Clone)]
#[allow(raw_pointer_derive)]
#[repr(C)]
#[stable]
pub struct MDB_val {
    pub mv_size: size_t,
    pub mv_data: *const c_void,
}

#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct MDB_env;

#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct MDB_txn;

#[repr(C)]
#[allow(missing_copy_implementations)]
pub struct MDB_cursor;

#[repr(C)]
#[stable]
#[derive(Copy)]
pub struct MDB_stat {
    pub ms_psize: c_uint,
    pub ms_depth: c_uint,
    pub ms_branch_pages: size_t,
    pub ms_leaf_pages: size_t,
    pub ms_overflow_pages: size_t,
    pub ms_entries: size_t
}

#[repr(C)]
#[stable]
#[allow(missing_copy_implementations)]
pub struct MDB_envinfo {
    pub me_mapaddr: *const c_void,
    pub me_mapsize: size_t,
    pub me_last_pgno: size_t,
    pub me_last_txnid: size_t,
    pub me_maxreaders: c_uint,
    pub me_numreaders: c_uint
}

#[repr(C)]
#[derive(Copy, Eq, PartialEq)]
pub enum MDB_cursor_op {
    MDB_FIRST,
    MDB_FIRST_DUP,
    MDB_GET_BOTH,
    MDB_GET_BOTH_RANGE,
    MDB_GET_CURRENT,
    MDB_GET_MULTIPLE,
    MDB_LAST,
    MDB_LAST_DUP,
    MDB_NEXT,
    MDB_NEXT_DUP,
    MDB_NEXT_MULTIPLE,
    MDB_NEXT_NODUP,
    MDB_PREV,
    MDB_PREV_DUP,
    MDB_PREV_NODUP,
    MDB_SET,
    MDB_SET_KEY,
    MDB_SET_RANGE
}

// Return codes
pub const MDB_SUCCESS: c_int = 0;
pub const MDB_KEYEXIST: c_int = -30799;
pub const MDB_NOTFOUND: c_int = -30798;
pub const MDB_PAGE_NOTFOUND: c_int = -30797;
pub const MDB_CORRUPTED: c_int = -30796;
pub const MDB_PANIC: c_int = -30795;
pub const MDB_VERSION_MISMATCH: c_int = -30794;
pub const MDB_INVALID: c_int = -30793;
pub const MDB_MAP_FULL: c_int = -30792;
pub const MDB_DBS_FULL: c_int = -30791;
pub const MDB_READERS_FULL: c_int = -30790;
pub const MDB_TLS_FULL: c_int = -30789;
pub const MDB_TXN_FULL: c_int = -30788;
pub const MDB_CURSOR_FULL: c_int = -30787;
pub const MDB_PAGE_FULL: c_int = -30786;
pub const MDB_MAP_RESIZED: c_int = -30785;
pub const MDB_INCOMPATIBLE: c_int = -30784;
pub const MDB_BAD_RSLOT: c_int = -30783;
pub const MDB_BAD_TXN: c_int = -30782;
pub const MDB_BAD_VALSIZE: c_int = -30781;

// Write flags
pub const MDB_NOOVERWRITE: c_uint = 0x10;
pub const MDB_NODUPDATA: c_uint = 0x20;
pub const MDB_CURRENT: c_uint = 0x40;
pub const MDB_RESERVE: c_uint = 0x10000;
pub const MDB_APPEND: c_uint = 0x20000;
pub const MDB_APPENDDUP: c_uint = 0x40000;
pub const MDB_MULTIPLE: c_uint = 0x80000;

// Database flags
pub const MDB_REVERSEKEY: c_uint = 0x02;
pub const MDB_DUPSORT: c_uint = 0x04;
pub const MDB_INTEGERKEY: c_uint = 0x08;
pub const MDB_DUPFIXED: c_uint = 0x10;
pub const MDB_INTEGERDUP: c_uint = 0x20;
pub const MDB_REVERSEDUP: c_uint =  0x40;
pub const MDB_CREATE: c_uint = 0x40000;

// Environment flags
pub const MDB_FIXEDMAP: c_uint =  0x01;
pub const MDB_NOSUBDIR: c_uint = 0x4000;
pub const MDB_NOSYNC: c_uint = 0x10000;
pub const MDB_RDONLY: c_uint = 0x20000;
pub const MDB_NOMETASYNC: c_uint = 0x40000;
pub const MDB_WRITEMAP: c_uint = 0x80000;
pub const MDB_MAPASYNC: c_uint = 0x100000;
pub const MDB_NOTLS: c_uint = 0x200000;
pub const MDB_NOLOCK: c_uint =  0x400000;
pub const MDB_NORDAHEAD: c_uint = 0x800000;
pub const MDB_NOMEMINIT: c_uint =  0x1000000;

// Embedding should work better for now
extern "C" {
    pub fn mdb_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int) -> *const c_char;
    pub fn mdb_strerror(err: c_int) -> *const c_char;
    pub fn mdb_env_create(env: *mut *mut MDB_env) -> c_int;
    pub fn mdb_env_open(env: *mut MDB_env, path: *const c_char, flags: c_uint, mode: mdb_mode_t) -> c_int;
    pub fn mdb_env_copy(env: *mut MDB_env, path: *const c_char) -> c_int;
    pub fn mdb_env_copyfd(env: *mut MDB_env, fd: mdb_filehandle_t) -> c_int;
    pub fn mdb_env_stat(env: *mut MDB_env, stat: *mut MDB_stat) -> c_int;
    pub fn mdb_env_info(env: *mut MDB_env, info: *mut MDB_envinfo) -> c_int;
    pub fn mdb_env_sync(env: *mut MDB_env, force: c_int) -> c_int;
    pub fn mdb_env_close(env: *mut MDB_env);
    pub fn mdb_env_set_flags(env: *mut MDB_env, flags: c_uint, onoff: c_int) -> c_int;
    pub fn mdb_env_get_flags(env: *mut MDB_env, flags: *mut c_uint) -> c_int;
    pub fn mdb_env_get_path(env: *mut MDB_env, path: *mut *mut c_char) -> c_int;
    pub fn mdb_env_get_fd(env: *mut MDB_env, fd: *mut mdb_filehandle_t) -> c_int;
    pub fn mdb_env_set_mapsize(env: *mut MDB_env, size: size_t) -> c_int;
    pub fn mdb_env_set_maxreaders(env: *mut MDB_env, readers: c_uint) -> c_int;
    pub fn mdb_env_get_maxreaders(env: *mut MDB_env, readers: *mut c_uint) -> c_int;
    pub fn mdb_env_set_maxdbs(env: *mut MDB_env, dbs: MDB_dbi) -> c_int;
    pub fn mdb_env_get_maxkeysize(env: *mut MDB_env) -> c_int;
    pub fn mdb_txn_begin(env: *mut MDB_env, parent: *mut MDB_txn, flags: c_uint, txn: *mut *mut MDB_txn) -> c_int;
    pub fn mdb_txn_env(txn: *mut MDB_txn) -> *mut MDB_env;
    pub fn mdb_txn_commit(txn: *mut MDB_txn) -> c_int;
    pub fn mdb_txn_abort(txn: *mut MDB_txn);
    pub fn mdb_txn_reset(txn: *mut MDB_txn);
    pub fn mdb_txn_renew(txn: *mut MDB_txn) -> c_int;
    pub fn mdb_dbi_open(txn: *mut MDB_txn, name: *const c_char, flags: c_uint, dbi: *mut MDB_dbi) -> c_int;
    pub fn mdb_stat(txn: *mut MDB_txn, dbi: MDB_dbi, stat: *mut MDB_stat) -> c_int;
    pub fn mdb_dbi_flags(txn: *mut MDB_txn, dbi: MDB_dbi, flags: *mut c_uint) -> c_int;
    pub fn mdb_dbi_close(txn: *mut MDB_env, dbi: MDB_dbi);
    pub fn mdb_drop(txn: *mut MDB_txn, dbi: MDB_dbi, del: c_int) -> c_int;
    pub fn mdb_set_compare(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> c_int;
    pub fn mdb_set_dupsort(txn: *mut MDB_txn, dbi: MDB_dbi, cmp: MDB_cmp_func) -> c_int;
    pub fn mdb_set_relfunc(txn: *mut MDB_txn, dbi: MDB_dbi, rel: MDB_rel_func) -> c_int;
    pub fn mdb_set_relctx(txn: *mut MDB_txn, dbi: MDB_dbi, ctx: *const c_void) -> c_int;
    pub fn mdb_get(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val) -> c_int;
    pub fn mdb_put(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val, flags: c_uint) -> c_int;
    pub fn mdb_del(txn: *mut MDB_txn, dbi: MDB_dbi, key: *mut MDB_val, data: *mut MDB_val) -> c_int;
    pub fn mdb_cursor_open(txn: *mut MDB_txn, dbi: MDB_dbi, cursor: *mut *mut MDB_cursor) -> c_int;
    pub fn mdb_cursor_close(cursor: *mut MDB_cursor) -> c_int;
    pub fn mdb_cursor_renew(txn: *mut MDB_txn, cursor: *mut MDB_cursor) -> c_int;
    pub fn mdb_cursor_txn(cursor: *mut MDB_cursor) -> *mut MDB_txn;
    pub fn mdb_cursor_dbi(cursor: *mut MDB_cursor) -> *mut MDB_dbi;
    pub fn mdb_cursor_get(cursor: *mut MDB_cursor, key: *mut MDB_val, data: *mut MDB_val, op: MDB_cursor_op) -> c_int;
    pub fn mdb_cursor_put(cursor: *mut MDB_cursor, key: *mut MDB_val, data: *mut MDB_val, flags: c_uint) -> c_int;
    pub fn mdb_cursor_del(cursor: *mut MDB_cursor, flags: c_uint) -> c_int;
    pub fn mdb_cursor_count(cursor: *mut MDB_cursor, countp: *mut size_t) -> c_int;
    pub fn mdb_cmp(txn: *mut MDB_txn, dbi: MDB_dbi, a: *mut MDB_val, b: *mut MDB_val) -> c_int;
    pub fn mdb_dcmp(txn: *mut MDB_txn, dbi: MDB_dbi, a: *mut MDB_val, b: *mut MDB_val) -> c_int;
    pub fn mdb_reader_list(env: *mut MDB_env, func: MDB_msg_func, ctx: *const c_void) -> c_int;
    pub fn mdb_reader_check(env: *mut MDB_env, dead: *mut c_int) -> c_int;
}
<|endoftext|>


<commit_before>//! Modules specific to the TI LM4F120H5QR Cortex-M4F microcontroller

// ****************************************************************************
//
// Imports
//
// ****************************************************************************

pub mod gpio;
pub mod pll;
pub mod registers;
pub mod uart;
pub mod timer;
pub mod systick;

extern "C" {
    fn _stack_top();
}

use board::launchpad as board;

pub use cpu::cortex_m4f::fpu as fpu;

// ****************************************************************************
//
// Public Types
//
// ****************************************************************************

// None

// ****************************************************************************
//
// Private Types
//
// ****************************************************************************

// None

// ****************************************************************************
//
// Public Data
//
// ****************************************************************************

#[link_section=".nvic_table"]
#[no_mangle]
pub static ISR_VECTORS: [Option<unsafe extern "C" fn()>; 155] = [// Stack pointer
                                                                 Some(_stack_top),
                                                                 // Reset
                                                                 Some(::common::startup::startup),
                                                                 // NMI
                                                                 Some(isr_nmi),
                                                                 // Hard Fault
                                                                 Some(isr_hardfault),
                                                                 // CM3 Memory Management Fault
                                                                 Some(isr_mmfault),
                                                                 // CM3 Bus Fault
                                                                 Some(isr_busfault),
                                                                 // CM3 Usage Fault
                                                                 Some(isr_usagefault),
                                                                 // Reserved - Used as NXP Checksum
                                                                 None,
                                                                 // Reserved
                                                                 None,
                                                                 // Reserved
                                                                 None,
                                                                 // Reserved
                                                                 None,
                                                                 // SVCall
                                                                 Some(isr_svcall),
                                                                 // Reserved for debug
                                                                 Some(isr_debugmon),
                                                                 // Reserved
                                                                 None,
                                                                 // PendSV
                                                                 Some(isr_pendsv),
                                                                 // SysTick
                                                                 Some(isr_systick),
                                                                 // GPIO Port A                      16
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port B                      17
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port C                      18
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port D                      19
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port E                      20
                                                                 Some(isr_empty_def),
                                                                 // UART 0                           21
                                                                 Some(uart::uart0_isr),
                                                                 // UART 1                           22
                                                                 Some(isr_empty_def),
                                                                 // SSI 0                            23
                                                                 Some(isr_empty_def),
                                                                 // I2C 0                            24
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         25
                                                                 None,
                                                                 // Reserved                         26
                                                                 None,
                                                                 // Reserved                         27
                                                                 None,
                                                                 // Reserved                         28
                                                                 None,
                                                                 // Reserved                         29
                                                                 None,
                                                                 // ADC 0 Seq 0                      30
                                                                 Some(isr_empty_def),
                                                                 // ADC 0 Seq 1                      31
                                                                 Some(isr_empty_def),
                                                                 // ADC 0 Seq 2                      32
                                                                 Some(isr_empty_def),
                                                                 // ADC 0 Seq 3                      33
                                                                 Some(isr_empty_def),
                                                                 // WDT 0 and 1                      34
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 0 A              35
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 0 B              36
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 1 A              37
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 1 B              38
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 2 A              39
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 2 B              40
                                                                 Some(isr_empty_def),
                                                                 // Analog comparator 0              41
                                                                 Some(isr_empty_def),
                                                                 // Analog comparator 1              42
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         43
                                                                 None,
                                                                 // System control                   44
                                                                 Some(isr_empty_def),
                                                                 // Flash + EEPROM control           45
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port F                      46
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         47
                                                                 None,
                                                                 // Reserved                         48
                                                                 None,
                                                                 // UART 2                           49
                                                                 Some(isr_empty_def),
                                                                 // SSI 1                            50
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 3 A              51
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 3 B              52
                                                                 Some(isr_empty_def),
                                                                 // I2C 1                            53
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         54
                                                                 None,
                                                                 // CAN 0                            55
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         56
                                                                 None,
                                                                 // Reserved                         57
                                                                 None,
                                                                 // Reserved                         58
                                                                 None,
                                                                 // Hibernation module               59
                                                                 Some(isr_empty_def),
                                                                 // USB                              60
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         61
                                                                 None,
                                                                 // UDMA SW                          62
                                                                 Some(isr_empty_def),
                                                                 // UDMA Error                       63
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 0                      64
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 1                      65
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 2                      66
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 3                      67
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         68
                                                                 None,
                                                                 // Reserved                         69
                                                                 None,
                                                                 // Reserved                         70
                                                                 None,
                                                                 // Reserved                         71
                                                                 None,
                                                                 // Reserved                         72
                                                                 None,
                                                                 // SSI 2                            73
                                                                 Some(isr_empty_def),
                                                                 // SSI 2                            74
                                                                 Some(isr_empty_def),
                                                                 // UART 3                           75
                                                                 Some(isr_empty_def),
                                                                 // UART 4                           76
                                                                 Some(isr_empty_def),
                                                                 // UART 5                           77
                                                                 Some(isr_empty_def),
                                                                 // UART 6                           78
                                                                 Some(isr_empty_def),
                                                                 // UART 7                           79
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         80
                                                                 None,
                                                                 // Reserved                         81
                                                                 None,
                                                                 // Reserved                         82
                                                                 None,
                                                                 // Reserved                         83
                                                                 None,
                                                                 // I2C 2                            84
                                                                 Some(isr_empty_def),
                                                                 // I2C 4                            85
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 4 A              86
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 4 B              87
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         88
                                                                 None,
                                                                 // Reserved                         89
                                                                 None,
                                                                 // Reserved                         90
                                                                 None,
                                                                 // Reserved                         91
                                                                 None,
                                                                 // Reserved                         92
                                                                 None,
                                                                 // Reserved                         93
                                                                 None,
                                                                 // Reserved                         94
                                                                 None,
                                                                 // Reserved                         95
                                                                 None,
                                                                 // Reserved                         96
                                                                 None,
                                                                 // Reserved                         97
                                                                 None,
                                                                 // Reserved                         98
                                                                 None,
                                                                 // Reserved                         99
                                                                 None,
                                                                 // Reserved                         100
                                                                 None,
                                                                 // Reserved                         101
                                                                 None,
                                                                 // Reserved                         102
                                                                 None,
                                                                 // Reserved                         103
                                                                 None,
                                                                 // Reserved                         104
                                                                 None,
                                                                 // Reserved                         105
                                                                 None,
                                                                 // Reserved                         106
                                                                 None,
                                                                 // Reserved                         107
                                                                 None,
                                                                 // 16/32 bit timer 5 A              108
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 5 B              109
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 0 A              110
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 0 B              111
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 1 A              112
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 1 B              113
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 2 A              114
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 2 B              115
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 3 A              116
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 3 B              117
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 4 A              118
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 4 B              119
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 5 A              120
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 5 B              121
                                                                 Some(isr_empty_def),
                                                                 // System Exception                 122
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         123
                                                                 None,
                                                                 // Reserved                         124
                                                                 None,
                                                                 // Reserved                         125
                                                                 None,
                                                                 // Reserved                         126
                                                                 None,
                                                                 // Reserved                         127
                                                                 None,
                                                                 // Reserved                         128
                                                                 None,
                                                                 // Reserved                         129
                                                                 None,
                                                                 // Reserved                         130
                                                                 None,
                                                                 // Reserved                         131
                                                                 None,
                                                                 // Reserved                         132
                                                                 None,
                                                                 // Reserved                         133
                                                                 None,
                                                                 // Reserved                         134
                                                                 None,
                                                                 // Reserved                         135
                                                                 None,
                                                                 // Reserved                         136
                                                                 None,
                                                                 // Reserved                         137
                                                                 None,
                                                                 // Reserved                         138
                                                                 None,
                                                                 // Reserved                         139
                                                                 None,
                                                                 // Reserved                         140
                                                                 None,
                                                                 // Reserved                         141
                                                                 None,
                                                                 // Reserved                         142
                                                                 None,
                                                                 // Reserved                         143
                                                                 None,
                                                                 // Reserved                         144
                                                                 None,
                                                                 // Reserved                         145
                                                                 None,
                                                                 // Reserved                         146
                                                                 None,
                                                                 // Reserved                         147
                                                                 None,
                                                                 // Reserved                         148
                                                                 None,
                                                                 // Reserved                         149
                                                                 None,
                                                                 // Reserved                         150
                                                                 None,
                                                                 // Reserved                         151
                                                                 None,
                                                                 // Reserved                         152
                                                                 None,
                                                                 // Reserved                         153
                                                                 None,
                                                                 // Reserved                         154
                                                                 None];

// ****************************************************************************
//
// Public Functions
//
// ****************************************************************************

/// Busy-waits for the given period.
///
/// Currently this function spins with a empirical number
/// of NOPS per millisecond. It should really use a timer.
///
/// * `ms` - The period to wait, in milliseconds
pub fn delay(ms: i32) {
    for _ in 0..ms * 250 {
        unsafe {
            asm!("NOP");
        }
    }
}

// ****************************************************************************
//
// Private Functions
//
// ****************************************************************************

/// A Non Maskable Interrupt (NMI) can be signalled by a peripheral or
/// triggered by software. This is the highest priority exception other than
/// reset. It is permanently enabled and has a fixed priority of -2. NMIs
/// cannot be:
/// * masked or prevented from activation by any other exception
/// * preempted by any exception other than Reset.
#[no_mangle]
pub unsafe extern "C" fn isr_nmi() {
    // Do nothing
}

/// A HardFault is an exception that occurs because of an error during
/// exception processing, or because an exception cannot be managed by any
/// other exception mechanism. HardFaults have a fixed priority of -1, meaning
/// they have higher priority than any exception with configurable priority.
#[no_mangle]
pub unsafe extern "C" fn isr_hardfault() {

     // Todo see https://community.arm.com/servlet/JiveServlet/previewBody/7835-102-2-12371/Developing%20a%20Generic%20Hard%20Fault%20handler%20for%20ARM.pdf
     // Use ITM to emit serial chars and then bkpt into debugger
     asm!("bkpt");
     board::panic();
}

/// A MemManage fault is an exception that occurs because of a memory
/// protection related fault. The the fixed memory protection constraints
/// determines this fault, for both instruction and data memory transactions.
/// This fault is always used to abort instruction accesses to Execute Never
/// (XN) memory regions.
#[no_mangle]
pub unsafe extern "C" fn isr_mmfault() {
    board::panic();
}

/// A BusFault is an exception that occurs because of a memory related fault
/// for an instruction or data memory transaction. This might be from an error
/// detected on a bus in the memory system.
#[no_mangle]
pub unsafe extern "C" fn isr_busfault() {
    board::panic();
}

/// A UsageFault is an exception that occurs because of a fault related to instruction execution. This includes:
/// * an undefined instruction
/// * an illegal unaligned access
/// * invalid state on instruction execution
/// * an error on exception return.
/// The following can cause a UsageFault when the core is configured to report them:
/// * an unaligned address on word and halfword memory access
/// * division by zero.
#[no_mangle]
pub unsafe extern "C" fn isr_usagefault() {
    board::panic();
}

/// A supervisor call (SVC) is an exception that is triggered by the SVC
/// instruction. In an OS environment, applications can use SVC instructions
/// to access OS kernel functions and device drivers.
#[no_mangle]
pub unsafe extern "C" fn isr_svcall() {
    // Nothing
}

/// Debug monitor interrupt handler.
#[no_mangle]
pub unsafe extern "C" fn isr_debugmon() {
    // Nothing
}

/// PendSV is an interrupt-driven request for system-level service. In an OS
/// environment, use PendSV for context switching when no other exception is
/// active.
#[no_mangle]
pub unsafe extern "C" fn isr_pendsv() {
    // Nothing
}

/// A SysTick exception is an exception the system timer generates when it
/// reaches zero. Software can also generate a SysTick exception. In an OS
/// environment, the processor can use this exception as system tick.
#[no_mangle]
pub unsafe extern "C" fn isr_systick() {
    systick::isr();
}

/// A place-holder ISR used when we have nothing better to use.
#[no_mangle]
pub unsafe extern "C" fn isr_empty_def() {
    board::panic();
}

// ****************************************************************************
//
// End Of File
//
// ****************************************************************************
<commit_msg>Switch to compiler-builtins from rust-lang-nursery. Use bkpt macro from cortex-m crate.<commit_after>//! Modules specific to the TI LM4F120H5QR Cortex-M4F microcontroller

// ****************************************************************************
//
// Imports
//
// ****************************************************************************

pub mod gpio;
pub mod pll;
pub mod registers;
pub mod uart;
pub mod timer;
pub mod systick;

extern "C" {
    fn _stack_top();
}

use board::launchpad as board;

pub use cpu::cortex_m4f::fpu as fpu;

// ****************************************************************************
//
// Public Types
//
// ****************************************************************************

// None

// ****************************************************************************
//
// Private Types
//
// ****************************************************************************

// None

// ****************************************************************************
//
// Public Data
//
// ****************************************************************************

#[link_section=".nvic_table"]
#[no_mangle]
pub static ISR_VECTORS: [Option<unsafe extern "C" fn()>; 155] = [// Stack pointer
                                                                 Some(_stack_top),
                                                                 // Reset
                                                                 Some(::common::startup::startup),
                                                                 // NMI
                                                                 Some(isr_nmi),
                                                                 // Hard Fault
                                                                 Some(isr_hardfault),
                                                                 // CM3 Memory Management Fault
                                                                 Some(isr_mmfault),
                                                                 // CM3 Bus Fault
                                                                 Some(isr_busfault),
                                                                 // CM3 Usage Fault
                                                                 Some(isr_usagefault),
                                                                 // Reserved - Used as NXP Checksum
                                                                 None,
                                                                 // Reserved
                                                                 None,
                                                                 // Reserved
                                                                 None,
                                                                 // Reserved
                                                                 None,
                                                                 // SVCall
                                                                 Some(isr_svcall),
                                                                 // Reserved for debug
                                                                 Some(isr_debugmon),
                                                                 // Reserved
                                                                 None,
                                                                 // PendSV
                                                                 Some(isr_pendsv),
                                                                 // SysTick
                                                                 Some(isr_systick),
                                                                 // GPIO Port A                      16
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port B                      17
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port C                      18
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port D                      19
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port E                      20
                                                                 Some(isr_empty_def),
                                                                 // UART 0                           21
                                                                 Some(uart::uart0_isr),
                                                                 // UART 1                           22
                                                                 Some(isr_empty_def),
                                                                 // SSI 0                            23
                                                                 Some(isr_empty_def),
                                                                 // I2C 0                            24
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         25
                                                                 None,
                                                                 // Reserved                         26
                                                                 None,
                                                                 // Reserved                         27
                                                                 None,
                                                                 // Reserved                         28
                                                                 None,
                                                                 // Reserved                         29
                                                                 None,
                                                                 // ADC 0 Seq 0                      30
                                                                 Some(isr_empty_def),
                                                                 // ADC 0 Seq 1                      31
                                                                 Some(isr_empty_def),
                                                                 // ADC 0 Seq 2                      32
                                                                 Some(isr_empty_def),
                                                                 // ADC 0 Seq 3                      33
                                                                 Some(isr_empty_def),
                                                                 // WDT 0 and 1                      34
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 0 A              35
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 0 B              36
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 1 A              37
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 1 B              38
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 2 A              39
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 2 B              40
                                                                 Some(isr_empty_def),
                                                                 // Analog comparator 0              41
                                                                 Some(isr_empty_def),
                                                                 // Analog comparator 1              42
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         43
                                                                 None,
                                                                 // System control                   44
                                                                 Some(isr_empty_def),
                                                                 // Flash + EEPROM control           45
                                                                 Some(isr_empty_def),
                                                                 // GPIO Port F                      46
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         47
                                                                 None,
                                                                 // Reserved                         48
                                                                 None,
                                                                 // UART 2                           49
                                                                 Some(isr_empty_def),
                                                                 // SSI 1                            50
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 3 A              51
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 3 B              52
                                                                 Some(isr_empty_def),
                                                                 // I2C 1                            53
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         54
                                                                 None,
                                                                 // CAN 0                            55
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         56
                                                                 None,
                                                                 // Reserved                         57
                                                                 None,
                                                                 // Reserved                         58
                                                                 None,
                                                                 // Hibernation module               59
                                                                 Some(isr_empty_def),
                                                                 // USB                              60
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         61
                                                                 None,
                                                                 // UDMA SW                          62
                                                                 Some(isr_empty_def),
                                                                 // UDMA Error                       63
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 0                      64
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 1                      65
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 2                      66
                                                                 Some(isr_empty_def),
                                                                 // ADC 1 Seq 3                      67
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         68
                                                                 None,
                                                                 // Reserved                         69
                                                                 None,
                                                                 // Reserved                         70
                                                                 None,
                                                                 // Reserved                         71
                                                                 None,
                                                                 // Reserved                         72
                                                                 None,
                                                                 // SSI 2                            73
                                                                 Some(isr_empty_def),
                                                                 // SSI 2                            74
                                                                 Some(isr_empty_def),
                                                                 // UART 3                           75
                                                                 Some(isr_empty_def),
                                                                 // UART 4                           76
                                                                 Some(isr_empty_def),
                                                                 // UART 5                           77
                                                                 Some(isr_empty_def),
                                                                 // UART 6                           78
                                                                 Some(isr_empty_def),
                                                                 // UART 7                           79
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         80
                                                                 None,
                                                                 // Reserved                         81
                                                                 None,
                                                                 // Reserved                         82
                                                                 None,
                                                                 // Reserved                         83
                                                                 None,
                                                                 // I2C 2                            84
                                                                 Some(isr_empty_def),
                                                                 // I2C 4                            85
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 4 A              86
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 4 B              87
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         88
                                                                 None,
                                                                 // Reserved                         89
                                                                 None,
                                                                 // Reserved                         90
                                                                 None,
                                                                 // Reserved                         91
                                                                 None,
                                                                 // Reserved                         92
                                                                 None,
                                                                 // Reserved                         93
                                                                 None,
                                                                 // Reserved                         94
                                                                 None,
                                                                 // Reserved                         95
                                                                 None,
                                                                 // Reserved                         96
                                                                 None,
                                                                 // Reserved                         97
                                                                 None,
                                                                 // Reserved                         98
                                                                 None,
                                                                 // Reserved                         99
                                                                 None,
                                                                 // Reserved                         100
                                                                 None,
                                                                 // Reserved                         101
                                                                 None,
                                                                 // Reserved                         102
                                                                 None,
                                                                 // Reserved                         103
                                                                 None,
                                                                 // Reserved                         104
                                                                 None,
                                                                 // Reserved                         105
                                                                 None,
                                                                 // Reserved                         106
                                                                 None,
                                                                 // Reserved                         107
                                                                 None,
                                                                 // 16/32 bit timer 5 A              108
                                                                 Some(isr_empty_def),
                                                                 // 16/32 bit timer 5 B              109
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 0 A              110
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 0 B              111
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 1 A              112
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 1 B              113
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 2 A              114
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 2 B              115
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 3 A              116
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 3 B              117
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 4 A              118
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 4 B              119
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 5 A              120
                                                                 Some(isr_empty_def),
                                                                 // 32/64 bit timer 5 B              121
                                                                 Some(isr_empty_def),
                                                                 // System Exception                 122
                                                                 Some(isr_empty_def),
                                                                 // Reserved                         123
                                                                 None,
                                                                 // Reserved                         124
                                                                 None,
                                                                 // Reserved                         125
                                                                 None,
                                                                 // Reserved                         126
                                                                 None,
                                                                 // Reserved                         127
                                                                 None,
                                                                 // Reserved                         128
                                                                 None,
                                                                 // Reserved                         129
                                                                 None,
                                                                 // Reserved                         130
                                                                 None,
                                                                 // Reserved                         131
                                                                 None,
                                                                 // Reserved                         132
                                                                 None,
                                                                 // Reserved                         133
                                                                 None,
                                                                 // Reserved                         134
                                                                 None,
                                                                 // Reserved                         135
                                                                 None,
                                                                 // Reserved                         136
                                                                 None,
                                                                 // Reserved                         137
                                                                 None,
                                                                 // Reserved                         138
                                                                 None,
                                                                 // Reserved                         139
                                                                 None,
                                                                 // Reserved                         140
                                                                 None,
                                                                 // Reserved                         141
                                                                 None,
                                                                 // Reserved                         142
                                                                 None,
                                                                 // Reserved                         143
                                                                 None,
                                                                 // Reserved                         144
                                                                 None,
                                                                 // Reserved                         145
                                                                 None,
                                                                 // Reserved                         146
                                                                 None,
                                                                 // Reserved                         147
                                                                 None,
                                                                 // Reserved                         148
                                                                 None,
                                                                 // Reserved                         149
                                                                 None,
                                                                 // Reserved                         150
                                                                 None,
                                                                 // Reserved                         151
                                                                 None,
                                                                 // Reserved                         152
                                                                 None,
                                                                 // Reserved                         153
                                                                 None,
                                                                 // Reserved                         154
                                                                 None];

// ****************************************************************************
//
// Public Functions
//
// ****************************************************************************

/// Busy-waits for the given period.
///
/// Currently this function spins with a empirical number
/// of NOPS per millisecond. It should really use a timer.
///
/// * `ms` - The period to wait, in milliseconds
pub fn delay(ms: i32) {
    for _ in 0..ms * 250 {
        unsafe {
            asm!("NOP");
        }
    }
}

// ****************************************************************************
//
// Private Functions
//
// ****************************************************************************

/// A Non Maskable Interrupt (NMI) can be signalled by a peripheral or
/// triggered by software. This is the highest priority exception other than
/// reset. It is permanently enabled and has a fixed priority of -2. NMIs
/// cannot be:
/// * masked or prevented from activation by any other exception
/// * preempted by any exception other than Reset.
#[no_mangle]
pub unsafe extern "C" fn isr_nmi() {
    // Do nothing
}

/// A HardFault is an exception that occurs because of an error during
/// exception processing, or because an exception cannot be managed by any
/// other exception mechanism. HardFaults have a fixed priority of -1, meaning
/// they have higher priority than any exception with configurable priority.
#[no_mangle]
pub unsafe extern "C" fn isr_hardfault() {

     // Todo see https://community.arm.com/servlet/JiveServlet/previewBody/7835-102-2-12371/Developing%20a%20Generic%20Hard%20Fault%20handler%20for%20ARM.pdf
     // Use ITM to emit serial chars and then bkpt into debugger
     bkpt!();
     board::panic();
}

/// A MemManage fault is an exception that occurs because of a memory
/// protection related fault. The the fixed memory protection constraints
/// determines this fault, for both instruction and data memory transactions.
/// This fault is always used to abort instruction accesses to Execute Never
/// (XN) memory regions.
#[no_mangle]
pub unsafe extern "C" fn isr_mmfault() {
    board::panic();
}

/// A BusFault is an exception that occurs because of a memory related fault
/// for an instruction or data memory transaction. This might be from an error
/// detected on a bus in the memory system.
#[no_mangle]
pub unsafe extern "C" fn isr_busfault() {
    board::panic();
}

/// A UsageFault is an exception that occurs because of a fault related to instruction execution. This includes:
/// * an undefined instruction
/// * an illegal unaligned access
/// * invalid state on instruction execution
/// * an error on exception return.
/// The following can cause a UsageFault when the core is configured to report them:
/// * an unaligned address on word and halfword memory access
/// * division by zero.
#[no_mangle]
pub unsafe extern "C" fn isr_usagefault() {
    board::panic();
}

/// A supervisor call (SVC) is an exception that is triggered by the SVC
/// instruction. In an OS environment, applications can use SVC instructions
/// to access OS kernel functions and device drivers.
#[no_mangle]
pub unsafe extern "C" fn isr_svcall() {
    // Nothing
}

/// Debug monitor interrupt handler.
#[no_mangle]
pub unsafe extern "C" fn isr_debugmon() {
    // Nothing
}

/// PendSV is an interrupt-driven request for system-level service. In an OS
/// environment, use PendSV for context switching when no other exception is
/// active.
#[no_mangle]
pub unsafe extern "C" fn isr_pendsv() {
    // Nothing
}

/// A SysTick exception is an exception the system timer generates when it
/// reaches zero. Software can also generate a SysTick exception. In an OS
/// environment, the processor can use this exception as system tick.
#[no_mangle]
pub unsafe extern "C" fn isr_systick() {
    systick::isr();
}

/// A place-holder ISR used when we have nothing better to use.
#[no_mangle]
pub unsafe extern "C" fn isr_empty_def() {
    board::panic();
}

// ****************************************************************************
//
// End Of File
//
// ****************************************************************************
<|endoftext|>