{"action":"created","comment":{"url":"https://api.github.com/repos/helena-project/tock/pulls/comments/169409585","pull_request_review_id":97931777,"id":169409585,"diff_hunk":"@@ -0,0 +1,190 @@\n+use core::cell::Cell;\n+use core::ops::{Index, IndexMut};\n+use ioc;\n+use kernel::common::VolatileCell;\n+use kernel::hil;\n+\n+const NUM_PINS: usize = 32;\n+\n+#[repr(C)]\n+pub struct GpioRegisters {\n+    _reserved0: [u8; 0x90],\n+    pub dout_set: VolatileCell<u32>,\n+    _reserved1: [u8; 0xC],\n+    pub dout_clr: VolatileCell<u32>,\n+    _reserved2: [u8; 0xC],\n+    pub dout_tgl: VolatileCell<u32>,\n+    _reserved3: [u8; 0xC],\n+    pub din: VolatileCell<u32>,\n+    _reserved4: [u8; 0xC],\n+    pub doe: VolatileCell<u32>,\n+    _reserved5: [u8; 0xC],\n+    pub evflags: VolatileCell<u32>,\n+}\n+\n+pub const GPIO_BASE: *mut GpioRegisters = 0x4002_2000 as *mut GpioRegisters;\n+\n+pub struct GPIOPin {\n+    regs: *mut GpioRegisters,\n+    pin: usize,\n+    pin_mask: u32,\n+    client_data: Cell<usize>,\n+    client: Cell<Option<&'static hil::gpio::Client>>,\n+}\n+\n+impl GPIOPin {\n+    const fn new(pin: usize) -> GPIOPin {\n+        GPIOPin {\n+            regs: GPIO_BASE,\n+            pin: pin,\n+            pin_mask: 1 << (pin % NUM_PINS),\n+            client_data: Cell::new(0),\n+            client: Cell::new(None),\n+        }\n+    }\n+\n+    fn enable_gpio(&self) {\n+        ioc::IOCFG[self.pin].enable_gpio();\n+    }\n+\n+    pub fn set_client<C: hil::gpio::Client>(&self, client: &'static C) {\n+        self.client.set(Some(client));\n+    }\n+\n+    pub fn handle_interrupt(&self) {\n+        self.client.get().map(|client| {\n+            client.fired(self.client_data.get());\n+        });\n+    }\n+}\n+\n+impl hil::gpio::PinCtl for GPIOPin {\n+    fn set_input_mode(&self, mode: hil::gpio::InputMode) {\n+        ioc::IOCFG[self.pin].set_input_mode(mode);\n+    }\n+}\n+\n+impl hil::gpio::Pin for GPIOPin {\n+    fn make_output(&self) {\n+        self.enable_gpio();\n+        // Disable input in the io configuration\n+        ioc::IOCFG[self.pin].enable_output();\n+        // Enable data output\n+        let regs: &GpioRegisters = unsafe { &*self.regs };\n+        regs.doe.set(regs.doe.get() | self.pin_mask);\n+    }\n+\n+    fn make_input(&self) {\n+        self.enable_gpio();\n+        ioc::IOCFG[self.pin].enable_input();\n+    }\n+\n+    fn disable(&self) {\n+        hil::gpio::PinCtl::set_input_mode(self, hil::gpio::InputMode::PullNone);\n+    }\n+\n+    fn set(&self) {\n+        let regs: &GpioRegisters = unsafe { &*self.regs };\n+        regs.dout_set.set(self.pin_mask);\n+    }\n+\n+    fn clear(&self) {\n+        let regs: &GpioRegisters = unsafe { &*self.regs };\n+        regs.dout_clr.set(self.pin_mask);\n+    }\n+\n+    fn toggle(&self) {\n+        let regs: &GpioRegisters = unsafe { &*self.regs };\n+        regs.dout_tgl.set(self.pin_mask);\n+    }\n+\n+    fn read(&self) -> bool {\n+        let regs: &GpioRegisters = unsafe { &*self.regs };\n+        regs.din.get() & self.pin_mask != 0\n+    }\n+\n+    fn enable_interrupt(&self, client_data: usize, mode: hil::gpio::InterruptMode) {\n+        self.client_data.set(client_data);\n+        ioc::IOCFG[self.pin].enable_interrupt(mode);\n+    }\n+\n+    fn disable_interrupt(&self) {\n+        ioc::IOCFG[self.pin].disable_interrupt();\n+    }\n+}\n+\n+pub struct Port {\n+    pins: [GPIOPin; NUM_PINS],\n+}\n+\n+impl Index<usize> for Port {\n+    type Output = GPIOPin;\n+\n+    fn index(&self, index: usize) -> &GPIOPin {\n+        &self.pins[index]\n+    }\n+}\n+\n+impl IndexMut<usize> for Port {\n+    fn index_mut(&mut self, index: usize) -> &mut GPIOPin {\n+        &mut self.pins[index]\n+    }\n+}\n+\n+impl Port {\n+    pub fn handle_interrupt(&self) {\n+        let regs: &GpioRegisters = unsafe { &*GPIO_BASE };\n+        let evflags = regs.evflags.get();\n+        // Clear all interrupts by setting their bits to 1 in evflags\n+        regs.evflags.set(evflags);\n+\n+        // evflags indicate which pins has triggered an interrupt,\n+        // we need to call the respective handler for positive bit in evflags.\n+        let mut pin: usize = usize::max_value();\n+        while pin < self.pins.len() {\n+            pin = evflags.trailing_zeros() as usize;\n+            if pin >= self.pins.len() {\n+                break;\n+            }\n+\n+            self.pins[pin].handle_interrupt();","path":"chips/cc26xx/src/gpio.rs","position":149,"original_position":150,"commit_id":"442c06d0c9337db99ede96800ee5991b0f0ae982","original_commit_id":"016fd10e7329e5a283962d830c0b88de1e75a956","user":{"login":"alevy","id":4689,"avatar_url":"https://avatars1.githubusercontent.com/u/4689?v=4","gravatar_id":"","url":"https://api.github.com/users/alevy","html_url":"https://github.com/alevy","followers_url":"https://api.github.com/users/alevy/followers","following_url":"https://api.github.com/users/alevy/following{/other_user}","gists_url":"https://api.github.com/users/alevy/gists{/gist_id}","starred_url":"https://api.github.com/users/alevy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alevy/subscriptions","organizations_url":"https://api.github.com/users/alevy/orgs","repos_url":"https://api.github.com/users/alevy/repos","events_url":"https://api.github.com/users/alevy/events{/privacy}","received_events_url":"https://api.github.com/users/alevy/received_events","type":"User","site_admin":false},"body":"Yeah, this is totally reasonable. I think we might do something similar on the SAM4L. Basically it's a two level dispatch: the hardware/event-loop can trigger the interrupt for the port, which then figures out which pin it was actually for and routes the interrupt.","created_at":"2018-02-20T18:12:20Z","updated_at":"2018-02-20T18:12:21Z","html_url":"https://github.com/helena-project/tock/pull/747#discussion_r169409585","pull_request_url":"https://api.github.com/repos/helena-project/tock/pulls/747","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/helena-project/tock/pulls/comments/169409585"},"html":{"href":"https://github.com/helena-project/tock/pull/747#discussion_r169409585"},"pull_request":{"href":"https://api.github.com/repos/helena-project/tock/pulls/747"}},"in_reply_to_id":168955923},"pull_request":{"url":"https://api.github.com/repos/helena-project/tock/pulls/747","id":169100315,"html_url":"https://github.com/helena-project/tock/pull/747","diff_url":"https://github.com/helena-project/tock/pull/747.diff","patch_url":"https://github.com/helena-project/tock/pull/747.patch","issue_url":"https://api.github.com/repos/helena-project/tock/issues/747","number":747,"state":"open","locked":false,"title":"Support for launchxl-cc26x2","user":{"login":"cpluss","id":1315331,"avatar_url":"https://avatars0.githubusercontent.com/u/1315331?v=4","gravatar_id":"","url":"https://api.github.com/users/cpluss","html_url":"https://github.com/cpluss","followers_url":"https://api.github.com/users/cpluss/followers","following_url":"https://api.github.com/users/cpluss/following{/other_user}","gists_url":"https://api.github.com/users/cpluss/gists{/gist_id}","starred_url":"https://api.github.com/users/cpluss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpluss/subscriptions","organizations_url":"https://api.github.com/users/cpluss/orgs","repos_url":"https://api.github.com/users/cpluss/repos","events_url":"https://api.github.com/users/cpluss/events{/privacy}","received_events_url":"https://api.github.com/users/cpluss/received_events","type":"User","site_admin":false},"body":"### Pull Request Overview\r\nAdds support for the launchxl board, with an CC26x2 chip.\r\n\r\n* Separated chips into `cc26xx` and `cc26x2` in order to easier add support for other boards with chips in the same family.\r\n* Added launchxl to boards, with basic gpio support\r\n\r\nIncluded in the PR is also an update to `.gitignore`, in order to ignore IntelliJ Idea project folder - which is created once you open any folder using it.\r\n\r\nThe launchxl board runs on Cortex-M4, and thus has MPU support :)\r\n\r\n### Testing Strategy\r\nTest by running the blink app\r\n\r\n### Documentation Updated\r\nI've added instructions in the readme of the board describing how to get everything up and running.\r\n","created_at":"2018-02-14T12:44:17Z","updated_at":"2018-02-20T18:12:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65985a06bb35156c5d7088f4418736b7db04fefd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":820349457,"url":"https://api.github.com/repos/helena-project/tock/labels/P-Significant","name":"P-Significant","color":"a80a31","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/helena-project/tock/pulls/747/commits","review_comments_url":"https://api.github.com/repos/helena-project/tock/pulls/747/comments","review_comment_url":"https://api.github.com/repos/helena-project/tock/pulls/comments{/number}","comments_url":"https://api.github.com/repos/helena-project/tock/issues/747/comments","statuses_url":"https://api.github.com/repos/helena-project/tock/statuses/442c06d0c9337db99ede96800ee5991b0f0ae982","head":{"label":"cpluss:launchxl","ref":"launchxl","sha":"442c06d0c9337db99ede96800ee5991b0f0ae982","user":{"login":"cpluss","id":1315331,"avatar_url":"https://avatars0.githubusercontent.com/u/1315331?v=4","gravatar_id":"","url":"https://api.github.com/users/cpluss","html_url":"https://github.com/cpluss","followers_url":"https://api.github.com/users/cpluss/followers","following_url":"https://api.github.com/users/cpluss/following{/other_user}","gists_url":"https://api.github.com/users/cpluss/gists{/gist_id}","starred_url":"https://api.github.com/users/cpluss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpluss/subscriptions","organizations_url":"https://api.github.com/users/cpluss/orgs","repos_url":"https://api.github.com/users/cpluss/repos","events_url":"https://api.github.com/users/cpluss/events{/privacy}","received_events_url":"https://api.github.com/users/cpluss/received_events","type":"User","site_admin":false},"repo":{"id":117655440,"name":"tock","full_name":"cpluss/tock","owner":{"login":"cpluss","id":1315331,"avatar_url":"https://avatars0.githubusercontent.com/u/1315331?v=4","gravatar_id":"","url":"https://api.github.com/users/cpluss","html_url":"https://github.com/cpluss","followers_url":"https://api.github.com/users/cpluss/followers","following_url":"https://api.github.com/users/cpluss/following{/other_user}","gists_url":"https://api.github.com/users/cpluss/gists{/gist_id}","starred_url":"https://api.github.com/users/cpluss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpluss/subscriptions","organizations_url":"https://api.github.com/users/cpluss/orgs","repos_url":"https://api.github.com/users/cpluss/repos","events_url":"https://api.github.com/users/cpluss/events{/privacy}","received_events_url":"https://api.github.com/users/cpluss/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cpluss/tock","description":"A secure embedded operating system for Cortex-M based microcontrollers","fork":true,"url":"https://api.github.com/repos/cpluss/tock","forks_url":"https://api.github.com/repos/cpluss/tock/forks","keys_url":"https://api.github.com/repos/cpluss/tock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cpluss/tock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cpluss/tock/teams","hooks_url":"https://api.github.com/repos/cpluss/tock/hooks","issue_events_url":"https://api.github.com/repos/cpluss/tock/issues/events{/number}","events_url":"https://api.github.com/repos/cpluss/tock/events","assignees_url":"https://api.github.com/repos/cpluss/tock/assignees{/user}","branches_url":"https://api.github.com/repos/cpluss/tock/branches{/branch}","tags_url":"https://api.github.com/repos/cpluss/tock/tags","blobs_url":"https://api.github.com/repos/cpluss/tock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cpluss/tock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cpluss/tock/git/refs{/sha}","trees_url":"https://api.github.com/repos/cpluss/tock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cpluss/tock/statuses/{sha}","languages_url":"https://api.github.com/repos/cpluss/tock/languages","stargazers_url":"https://api.github.com/repos/cpluss/tock/stargazers","contributors_url":"https://api.github.com/repos/cpluss/tock/contributors","subscribers_url":"https://api.github.com/repos/cpluss/tock/subscribers","subscription_url":"https://api.github.com/repos/cpluss/tock/subscription","commits_url":"https://api.github.com/repos/cpluss/tock/commits{/sha}","git_commits_url":"https://api.github.com/repos/cpluss/tock/git/commits{/sha}","comments_url":"https://api.github.com/repos/cpluss/tock/comments{/number}","issue_comment_url":"https://api.github.com/repos/cpluss/tock/issues/comments{/number}","contents_url":"https://api.github.com/repos/cpluss/tock/contents/{+path}","compare_url":"https://api.github.com/repos/cpluss/tock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cpluss/tock/merges","archive_url":"https://api.github.com/repos/cpluss/tock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cpluss/tock/downloads","issues_url":"https://api.github.com/repos/cpluss/tock/issues{/number}","pulls_url":"https://api.github.com/repos/cpluss/tock/pulls{/number}","milestones_url":"https://api.github.com/repos/cpluss/tock/milestones{/number}","notifications_url":"https://api.github.com/repos/cpluss/tock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cpluss/tock/labels{/name}","releases_url":"https://api.github.com/repos/cpluss/tock/releases{/id}","deployments_url":"https://api.github.com/repos/cpluss/tock/deployments","created_at":"2018-01-16T08:26:43Z","updated_at":"2018-01-16T08:26:46Z","pushed_at":"2018-02-20T11:14:59Z","git_url":"git://github.com/cpluss/tock.git","ssh_url":"git@github.com:cpluss/tock.git","clone_url":"https://github.com/cpluss/tock.git","svn_url":"https://github.com/cpluss/tock","homepage":"https://www.tockos.org","size":131615,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"helena-project:master","ref":"master","sha":"d1f27827f0f9810667cdb63127ee1daf886b8633","user":{"login":"helena-project","id":8978731,"avatar_url":"https://avatars0.githubusercontent.com/u/8978731?v=4","gravatar_id":"","url":"https://api.github.com/users/helena-project","html_url":"https://github.com/helena-project","followers_url":"https://api.github.com/users/helena-project/followers","following_url":"https://api.github.com/users/helena-project/following{/other_user}","gists_url":"https://api.github.com/users/helena-project/gists{/gist_id}","starred_url":"https://api.github.com/users/helena-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helena-project/subscriptions","organizations_url":"https://api.github.com/users/helena-project/orgs","repos_url":"https://api.github.com/users/helena-project/repos","events_url":"https://api.github.com/users/helena-project/events{/privacy}","received_events_url":"https://api.github.com/users/helena-project/received_events","type":"Organization","site_admin":false},"repo":{"id":36428094,"name":"tock","full_name":"helena-project/tock","owner":{"login":"helena-project","id":8978731,"avatar_url":"https://avatars0.githubusercontent.com/u/8978731?v=4","gravatar_id":"","url":"https://api.github.com/users/helena-project","html_url":"https://github.com/helena-project","followers_url":"https://api.github.com/users/helena-project/followers","following_url":"https://api.github.com/users/helena-project/following{/other_user}","gists_url":"https://api.github.com/users/helena-project/gists{/gist_id}","starred_url":"https://api.github.com/users/helena-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helena-project/subscriptions","organizations_url":"https://api.github.com/users/helena-project/orgs","repos_url":"https://api.github.com/users/helena-project/repos","events_url":"https://api.github.com/users/helena-project/events{/privacy}","received_events_url":"https://api.github.com/users/helena-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/helena-project/tock","description":"A secure embedded operating system for Cortex-M based microcontrollers","fork":false,"url":"https://api.github.com/repos/helena-project/tock","forks_url":"https://api.github.com/repos/helena-project/tock/forks","keys_url":"https://api.github.com/repos/helena-project/tock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/helena-project/tock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/helena-project/tock/teams","hooks_url":"https://api.github.com/repos/helena-project/tock/hooks","issue_events_url":"https://api.github.com/repos/helena-project/tock/issues/events{/number}","events_url":"https://api.github.com/repos/helena-project/tock/events","assignees_url":"https://api.github.com/repos/helena-project/tock/assignees{/user}","branches_url":"https://api.github.com/repos/helena-project/tock/branches{/branch}","tags_url":"https://api.github.com/repos/helena-project/tock/tags","blobs_url":"https://api.github.com/repos/helena-project/tock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/helena-project/tock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/helena-project/tock/git/refs{/sha}","trees_url":"https://api.github.com/repos/helena-project/tock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/helena-project/tock/statuses/{sha}","languages_url":"https://api.github.com/repos/helena-project/tock/languages","stargazers_url":"https://api.github.com/repos/helena-project/tock/stargazers","contributors_url":"https://api.github.com/repos/helena-project/tock/contributors","subscribers_url":"https://api.github.com/repos/helena-project/tock/subscribers","subscription_url":"https://api.github.com/repos/helena-project/tock/subscription","commits_url":"https://api.github.com/repos/helena-project/tock/commits{/sha}","git_commits_url":"https://api.github.com/repos/helena-project/tock/git/commits{/sha}","comments_url":"https://api.github.com/repos/helena-project/tock/comments{/number}","issue_comment_url":"https://api.github.com/repos/helena-project/tock/issues/comments{/number}","contents_url":"https://api.github.com/repos/helena-project/tock/contents/{+path}","compare_url":"https://api.github.com/repos/helena-project/tock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/helena-project/tock/merges","archive_url":"https://api.github.com/repos/helena-project/tock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/helena-project/tock/downloads","issues_url":"https://api.github.com/repos/helena-project/tock/issues{/number}","pulls_url":"https://api.github.com/repos/helena-project/tock/pulls{/number}","milestones_url":"https://api.github.com/repos/helena-project/tock/milestones{/number}","notifications_url":"https://api.github.com/repos/helena-project/tock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/helena-project/tock/labels{/name}","releases_url":"https://api.github.com/repos/helena-project/tock/releases{/id}","deployments_url":"https://api.github.com/repos/helena-project/tock/deployments","created_at":"2015-05-28T09:26:47Z","updated_at":"2018-02-19T23:05:40Z","pushed_at":"2018-02-20T18:10:25Z","git_url":"git://github.com/helena-project/tock.git","ssh_url":"git@github.com:helena-project/tock.git","clone_url":"https://github.com/helena-project/tock.git","svn_url":"https://github.com/helena-project/tock","homepage":"https://www.tockos.org","size":131447,"stargazers_count":759,"watchers_count":759,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":96,"mirror_url":null,"archived":false,"open_issues_count":53,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":96,"open_issues":53,"watchers":759,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/helena-project/tock/pulls/747"},"html":{"href":"https://github.com/helena-project/tock/pull/747"},"issue":{"href":"https://api.github.com/repos/helena-project/tock/issues/747"},"comments":{"href":"https://api.github.com/repos/helena-project/tock/issues/747/comments"},"review_comments":{"href":"https://api.github.com/repos/helena-project/tock/pulls/747/comments"},"review_comment":{"href":"https://api.github.com/repos/helena-project/tock/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/helena-project/tock/pulls/747/commits"},"statuses":{"href":"https://api.github.com/repos/helena-project/tock/statuses/442c06d0c9337db99ede96800ee5991b0f0ae982"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"alevy"}}