[][src]Attribute Macro msp430_rt_macros::entry

#[entry]

Attribute to declare the entry point of the program

The specified function will be called by the reset handler after RAM has been initialized.

The type of the specified function must be [unsafe] fn([<name>: CriticalSection]) -> ! (never ending function), where the CriticalSection argument is optional.

Properties

The entry point will be called by the reset handler. The program can't reference to the entry point, much less invoke it.

static mut variables declared within the entry point are safe to access. The compiler can't prove this is safe so the attribute will help by making a transformation to the source code: for this reason a variable like static mut FOO: u32 will become let FOO: &'static mut u32;. Note that &'static mut references have move semantics.

Examples

  • Simple entry point
#[entry]
fn main() -> ! {
    loop {
        /* .. */
    }
}
  • static mut variables local to the entry point are safe to modify.
#[entry]
fn main(_cs: CriticalSection) -> ! {
    static mut FOO: u32 = 0;

    let foo: &'static mut u32 = FOO;
    assert_eq!(*foo, 0);
    *foo = 1;
    assert_eq!(*foo, 1);

    loop {
        /* .. */
    }
}