{"action":"created","issue":{"url":"https://api.github.com/repos/japaric/cu/issues/32","repository_url":"https://api.github.com/repos/japaric/cu","labels_url":"https://api.github.com/repos/japaric/cu/issues/32/labels{/name}","comments_url":"https://api.github.com/repos/japaric/cu/issues/32/comments","events_url":"https://api.github.com/repos/japaric/cu/issues/32/events","html_url":"https://github.com/japaric/cu/issues/32","id":164450185,"number":32,"title":"Don't expose registers as global static variables","user":{"login":"japaric","id":5018213,"avatar_url":"https://avatars.githubusercontent.com/u/5018213?v=3","gravatar_id":"","url":"https://api.github.com/users/japaric","html_url":"https://github.com/japaric","followers_url":"https://api.github.com/users/japaric/followers","following_url":"https://api.github.com/users/japaric/following{/other_user}","gists_url":"https://api.github.com/users/japaric/gists{/gist_id}","starred_url":"https://api.github.com/users/japaric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japaric/subscriptions","organizations_url":"https://api.github.com/users/japaric/orgs","repos_url":"https://api.github.com/users/japaric/repos","events_url":"https://api.github.com/users/japaric/events{/privacy}","received_events_url":"https://api.github.com/users/japaric/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2016-07-08T03:00:23Z","updated_at":"2016-07-13T01:59:19Z","closed_at":null,"body":"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.\r\n\r\nHere's one solution:\r\n\r\n``` rust\r\n// src/lib.rs\r\n#[no_mangle]\r\npub fn start() -> ! {\r\n    extern {\r\n        fn main(peripherals: Peripherals) -> !;\r\n    }\r\n\r\n    let peripherals = unsafe {\r\n        Peripherals { gpioa: &mut GPIOA, gpiob: &mut GPIOB, .. }\r\n    };\r\n\r\n    main(peripherals)\r\n}\r\n```\r\n\r\n``` rust\r\n// src/bin/foo.rs\r\n#[no_mangle]\r\npub fn main(p: Peripherals) -> ! {\r\n    do_something(p.gpioa, p.tim7);\r\n\r\n     loop {}\r\n}\r\n```\r\n\r\nUnresolved questions:\r\n- How can we make sure the library user uses the right signature for the `main` function?\r\n- With this it's unclear how to let interrupts access the registers."},"comment":{"url":"https://api.github.com/repos/japaric/cu/issues/comments/232233862","html_url":"https://github.com/japaric/cu/issues/32#issuecomment-232233862","issue_url":"https://api.github.com/repos/japaric/cu/issues/32","id":232233862,"user":{"login":"goandylok","id":9637710,"avatar_url":"https://avatars.githubusercontent.com/u/9637710?v=3","gravatar_id":"","url":"https://api.github.com/users/goandylok","html_url":"https://github.com/goandylok","followers_url":"https://api.github.com/users/goandylok/followers","following_url":"https://api.github.com/users/goandylok/following{/other_user}","gists_url":"https://api.github.com/users/goandylok/gists{/gist_id}","starred_url":"https://api.github.com/users/goandylok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goandylok/subscriptions","organizations_url":"https://api.github.com/users/goandylok/orgs","repos_url":"https://api.github.com/users/goandylok/repos","events_url":"https://api.github.com/users/goandylok/events{/privacy}","received_events_url":"https://api.github.com/users/goandylok/received_events","type":"User","site_admin":false},"created_at":"2016-07-13T01:59:19Z","updated_at":"2016-07-13T01:59:19Z","body":"I am not saying this pattern could make everything safe. We must make sure by ourselves, digging into its library,"}}
{"actor":{"display_login":"goandylok"}}