Skip to content
This repository was archived by the owner on Dec 9, 2018. It is now read-only.
This repository was archived by the owner on Dec 9, 2018. It is now read-only.

Don't expose registers as global static variables #32

@japaric

Description

@japaric

In the current state, registers are globals so it's easy to perform unsynchronized accesses to these registers from the main thread and from an interrupt.

Here's one solution:

// src/lib.rs
#[no_mangle]
pub fn start() -> ! {
    extern {
        fn main(peripherals: Peripherals) -> !;
    }

    let peripherals = unsafe {
        Peripherals { gpioa: &mut GPIOA, gpiob: &mut GPIOB, .. }
    };

    main(peripherals)
}
// src/bin/foo.rs
#[no_mangle]
pub fn main(p: Peripherals) -> ! {
    do_something(p.gpioa, p.tim7);

     loop {}
}

Unresolved questions:

  • How can we make sure the library user uses the right signature for the main function?
  • With this it's unclear how to let interrupts access the registers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions