{"action":"created","comment":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/56735749","id":56735749,"diff_hunk":"@@ -14,32 +15,92 @@\n  * @brief       Implementation of the kernel's lpm interface\n  *\n  * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>\n+ * @author      Laksh Bhatia <bhatialaksh3@gmail.com>\n  *\n  * @}\n  */\n \n+#include \"cpu.h\"\n #include \"arch/lpm_arch.h\"\n \n+static enum lpm_mode current_mode = LPM_UNKNOWN;\n+\n void lpm_arch_init(void)\n {\n-    /* TODO */\n+    current_mode = LPM_ON;\n }\n \n enum lpm_mode lpm_arch_set(enum lpm_mode target)\n {\n-    /* TODO */\n-    return 0;\n+    enum lpm_mode last_mode = current_mode;\n+    switch (target) {\n+        case LPM_ON:                    /* STM Run mode */\n+            current_mode = LPM_ON;\n+            break;\n+        case LPM_IDLE:                  /* STM Low power run mode */\n+            current_mode = LPM_IDLE;\n+            PWR->CR |= (PWR_CR_LPSDSR | PWR_CR_LPRUN);\n+            /* Enter low power run mode */\n+            __WFE();\n+            break;\n+        case LPM_SLEEP:                 /* STM Low power sleep mode */\n+            current_mode = LPM_SLEEP;\n+            PWR->CR |= (PWR_CR_LPSDSR);\n+            /* Enter low power sleep mode */\n+            __WFI();  /* Option between WFI and WFE*/\n+            // __WFE();\n+            break;\n+        case LPM_POWERDOWN:             /* STM Standby mode */\n+            current_mode = LPM_POWERDOWN;\n+            /* Set PDDS to enter standby mode on deepsleep and clear flags */\n+            PWR->CR |= (PWR_CR_PDDS | PWR_CR_CSBF | PWR_CR_CWUF);\n+            /* Enable WKUP pin to use for wakeup from standby mode in pin1 */\n+            //PWR->CSR |= PWR_CSR_EWUP1;\n+            /* Set SLEEPDEEP bit of system control block */\n+            SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\n+    #if defined ( __CC_ARM   )\n+            /* Ensure that store operations are completed */\n+            __force_stores();\n+    #endif\n+            /* Enter standby mode */\n+            __WFI();\n+            __WFE();\n+            break;\n+        case LPM_OFF:                   /* STM Stop mode */\n+            current_mode = LPM_OFF;\n+            /* Set PDDS to enter standby mode on deepsleep and clear flags */\n+            PWR->CR |= (PWR_CR_PDDS | PWR_CR_LPSDSR | PWR_CR_CWUF );\n+            /* Enable WKUP pin to use for wakeup from standby mode in pin1 */\n+            //PWR->CSR |= PWR_CSR_EWUP1;\n+            /* Set SLEEPDEEP bit of system control block */\n+            SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\n+    #if defined ( __CC_ARM   )\n+            /* Ensure that store operations are completed */\n+            __force_stores();\n+    #endif\n+            /* Enter standby mode */\n+            __WFI();\n+            __WFE();","path":"cpu/stm32l1/lpm_arch.c","position":79,"original_position":79,"commit_id":"53cd02d093cd40458780ff9b8bd9c1c412af64a4","original_commit_id":"53cd02d093cd40458780ff9b8bd9c1c412af64a4","user":{"login":"shady33","id":5087761,"avatar_url":"https://avatars.githubusercontent.com/u/5087761?v=3","gravatar_id":"","url":"https://api.github.com/users/shady33","html_url":"https://github.com/shady33","followers_url":"https://api.github.com/users/shady33/followers","following_url":"https://api.github.com/users/shady33/following{/other_user}","gists_url":"https://api.github.com/users/shady33/gists{/gist_id}","starred_url":"https://api.github.com/users/shady33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shady33/subscriptions","organizations_url":"https://api.github.com/users/shady33/orgs","repos_url":"https://api.github.com/users/shady33/repos","events_url":"https://api.github.com/users/shady33/events{/privacy}","received_events_url":"https://api.github.com/users/shady33/received_events","type":"User","site_admin":false},"body":"Sleep and standby modes can be exited either with WFI or WFE.\r\nSo the option is to add both or define a macro to decide wakeup from Interrupts or events","created_at":"2016-03-18T23:25:32Z","updated_at":"2016-03-18T23:25:32Z","html_url":"https://github.com/RIOT-OS/RIOT/pull/4980#discussion_r56735749","pull_request_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980","_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/56735749"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/4980#discussion_r56735749"},"pull_request":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980"}}},"pull_request":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980","id":61918694,"html_url":"https://github.com/RIOT-OS/RIOT/pull/4980","diff_url":"https://github.com/RIOT-OS/RIOT/pull/4980.diff","patch_url":"https://github.com/RIOT-OS/RIOT/pull/4980.patch","issue_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4980","number":4980,"state":"open","locked":false,"title":"stm32l1/lpm: low power implementation for stm32l1","user":{"login":"shady33","id":5087761,"avatar_url":"https://avatars.githubusercontent.com/u/5087761?v=3","gravatar_id":"","url":"https://api.github.com/users/shady33","html_url":"https://github.com/shady33","followers_url":"https://api.github.com/users/shady33/followers","following_url":"https://api.github.com/users/shady33/following{/other_user}","gists_url":"https://api.github.com/users/shady33/gists{/gist_id}","starred_url":"https://api.github.com/users/shady33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shady33/subscriptions","organizations_url":"https://api.github.com/users/shady33/orgs","repos_url":"https://api.github.com/users/shady33/repos","events_url":"https://api.github.com/users/shady33/events{/privacy}","received_events_url":"https://api.github.com/users/shady33/received_events","type":"User","site_admin":false},"body":"The Low power modes implementation for the STM32L1 series.\r\n","created_at":"2016-03-07T13:46:16Z","updated_at":"2016-03-18T23:25:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"37633006e66d7169480eb04a01ef3440ed9ad963","assignee":{"login":"DipSwitch","id":476484,"avatar_url":"https://avatars.githubusercontent.com/u/476484?v=3","gravatar_id":"","url":"https://api.github.com/users/DipSwitch","html_url":"https://github.com/DipSwitch","followers_url":"https://api.github.com/users/DipSwitch/followers","following_url":"https://api.github.com/users/DipSwitch/following{/other_user}","gists_url":"https://api.github.com/users/DipSwitch/gists{/gist_id}","starred_url":"https://api.github.com/users/DipSwitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DipSwitch/subscriptions","organizations_url":"https://api.github.com/users/DipSwitch/orgs","repos_url":"https://api.github.com/users/DipSwitch/repos","events_url":"https://api.github.com/users/DipSwitch/events{/privacy}","received_events_url":"https://api.github.com/users/DipSwitch/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980/commits","review_comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980/comments","review_comment_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4980/comments","statuses_url":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/53cd02d093cd40458780ff9b8bd9c1c412af64a4","head":{"label":"shady33:stm32l1-lpm","ref":"stm32l1-lpm","sha":"53cd02d093cd40458780ff9b8bd9c1c412af64a4","user":{"login":"shady33","id":5087761,"avatar_url":"https://avatars.githubusercontent.com/u/5087761?v=3","gravatar_id":"","url":"https://api.github.com/users/shady33","html_url":"https://github.com/shady33","followers_url":"https://api.github.com/users/shady33/followers","following_url":"https://api.github.com/users/shady33/following{/other_user}","gists_url":"https://api.github.com/users/shady33/gists{/gist_id}","starred_url":"https://api.github.com/users/shady33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shady33/subscriptions","organizations_url":"https://api.github.com/users/shady33/orgs","repos_url":"https://api.github.com/users/shady33/repos","events_url":"https://api.github.com/users/shady33/events{/privacy}","received_events_url":"https://api.github.com/users/shady33/received_events","type":"User","site_admin":false},"repo":{"id":51260123,"name":"RIOT","full_name":"shady33/RIOT","owner":{"login":"shady33","id":5087761,"avatar_url":"https://avatars.githubusercontent.com/u/5087761?v=3","gravatar_id":"","url":"https://api.github.com/users/shady33","html_url":"https://github.com/shady33","followers_url":"https://api.github.com/users/shady33/followers","following_url":"https://api.github.com/users/shady33/following{/other_user}","gists_url":"https://api.github.com/users/shady33/gists{/gist_id}","starred_url":"https://api.github.com/users/shady33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shady33/subscriptions","organizations_url":"https://api.github.com/users/shady33/orgs","repos_url":"https://api.github.com/users/shady33/repos","events_url":"https://api.github.com/users/shady33/events{/privacy}","received_events_url":"https://api.github.com/users/shady33/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shady33/RIOT","description":"RIOT -  The friendly OS for IoT","fork":true,"url":"https://api.github.com/repos/shady33/RIOT","forks_url":"https://api.github.com/repos/shady33/RIOT/forks","keys_url":"https://api.github.com/repos/shady33/RIOT/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shady33/RIOT/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shady33/RIOT/teams","hooks_url":"https://api.github.com/repos/shady33/RIOT/hooks","issue_events_url":"https://api.github.com/repos/shady33/RIOT/issues/events{/number}","events_url":"https://api.github.com/repos/shady33/RIOT/events","assignees_url":"https://api.github.com/repos/shady33/RIOT/assignees{/user}","branches_url":"https://api.github.com/repos/shady33/RIOT/branches{/branch}","tags_url":"https://api.github.com/repos/shady33/RIOT/tags","blobs_url":"https://api.github.com/repos/shady33/RIOT/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shady33/RIOT/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shady33/RIOT/git/refs{/sha}","trees_url":"https://api.github.com/repos/shady33/RIOT/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shady33/RIOT/statuses/{sha}","languages_url":"https://api.github.com/repos/shady33/RIOT/languages","stargazers_url":"https://api.github.com/repos/shady33/RIOT/stargazers","contributors_url":"https://api.github.com/repos/shady33/RIOT/contributors","subscribers_url":"https://api.github.com/repos/shady33/RIOT/subscribers","subscription_url":"https://api.github.com/repos/shady33/RIOT/subscription","commits_url":"https://api.github.com/repos/shady33/RIOT/commits{/sha}","git_commits_url":"https://api.github.com/repos/shady33/RIOT/git/commits{/sha}","comments_url":"https://api.github.com/repos/shady33/RIOT/comments{/number}","issue_comment_url":"https://api.github.com/repos/shady33/RIOT/issues/comments{/number}","contents_url":"https://api.github.com/repos/shady33/RIOT/contents/{+path}","compare_url":"https://api.github.com/repos/shady33/RIOT/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shady33/RIOT/merges","archive_url":"https://api.github.com/repos/shady33/RIOT/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shady33/RIOT/downloads","issues_url":"https://api.github.com/repos/shady33/RIOT/issues{/number}","pulls_url":"https://api.github.com/repos/shady33/RIOT/pulls{/number}","milestones_url":"https://api.github.com/repos/shady33/RIOT/milestones{/number}","notifications_url":"https://api.github.com/repos/shady33/RIOT/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shady33/RIOT/labels{/name}","releases_url":"https://api.github.com/repos/shady33/RIOT/releases{/id}","deployments_url":"https://api.github.com/repos/shady33/RIOT/deployments","created_at":"2016-02-07T18:45:24Z","updated_at":"2016-02-07T18:45:38Z","pushed_at":"2016-03-12T20:15:07Z","git_url":"git://github.com/shady33/RIOT.git","ssh_url":"git@github.com:shady33/RIOT.git","clone_url":"https://github.com/shady33/RIOT.git","svn_url":"https://github.com/shady33/RIOT","homepage":"https://github.com/RIOT-OS/RIOT/wiki","size":24812,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"RIOT-OS:master","ref":"master","sha":"2f0b4c20bfea63d35c4a3ca1bb6b29c8a305918b","user":{"login":"RIOT-OS","id":3079480,"avatar_url":"https://avatars.githubusercontent.com/u/3079480?v=3","gravatar_id":"","url":"https://api.github.com/users/RIOT-OS","html_url":"https://github.com/RIOT-OS","followers_url":"https://api.github.com/users/RIOT-OS/followers","following_url":"https://api.github.com/users/RIOT-OS/following{/other_user}","gists_url":"https://api.github.com/users/RIOT-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RIOT-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RIOT-OS/subscriptions","organizations_url":"https://api.github.com/users/RIOT-OS/orgs","repos_url":"https://api.github.com/users/RIOT-OS/repos","events_url":"https://api.github.com/users/RIOT-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RIOT-OS/received_events","type":"Organization","site_admin":false},"repo":{"id":7370241,"name":"RIOT","full_name":"RIOT-OS/RIOT","owner":{"login":"RIOT-OS","id":3079480,"avatar_url":"https://avatars.githubusercontent.com/u/3079480?v=3","gravatar_id":"","url":"https://api.github.com/users/RIOT-OS","html_url":"https://github.com/RIOT-OS","followers_url":"https://api.github.com/users/RIOT-OS/followers","following_url":"https://api.github.com/users/RIOT-OS/following{/other_user}","gists_url":"https://api.github.com/users/RIOT-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RIOT-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RIOT-OS/subscriptions","organizations_url":"https://api.github.com/users/RIOT-OS/orgs","repos_url":"https://api.github.com/users/RIOT-OS/repos","events_url":"https://api.github.com/users/RIOT-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RIOT-OS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RIOT-OS/RIOT","description":"RIOT -  The friendly OS for IoT","fork":false,"url":"https://api.github.com/repos/RIOT-OS/RIOT","forks_url":"https://api.github.com/repos/RIOT-OS/RIOT/forks","keys_url":"https://api.github.com/repos/RIOT-OS/RIOT/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RIOT-OS/RIOT/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RIOT-OS/RIOT/teams","hooks_url":"https://api.github.com/repos/RIOT-OS/RIOT/hooks","issue_events_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/events{/number}","events_url":"https://api.github.com/repos/RIOT-OS/RIOT/events","assignees_url":"https://api.github.com/repos/RIOT-OS/RIOT/assignees{/user}","branches_url":"https://api.github.com/repos/RIOT-OS/RIOT/branches{/branch}","tags_url":"https://api.github.com/repos/RIOT-OS/RIOT/tags","blobs_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/refs{/sha}","trees_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/{sha}","languages_url":"https://api.github.com/repos/RIOT-OS/RIOT/languages","stargazers_url":"https://api.github.com/repos/RIOT-OS/RIOT/stargazers","contributors_url":"https://api.github.com/repos/RIOT-OS/RIOT/contributors","subscribers_url":"https://api.github.com/repos/RIOT-OS/RIOT/subscribers","subscription_url":"https://api.github.com/repos/RIOT-OS/RIOT/subscription","commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/commits{/sha}","git_commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/commits{/sha}","comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/comments{/number}","issue_comment_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/comments{/number}","contents_url":"https://api.github.com/repos/RIOT-OS/RIOT/contents/{+path}","compare_url":"https://api.github.com/repos/RIOT-OS/RIOT/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RIOT-OS/RIOT/merges","archive_url":"https://api.github.com/repos/RIOT-OS/RIOT/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RIOT-OS/RIOT/downloads","issues_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues{/number}","pulls_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls{/number}","milestones_url":"https://api.github.com/repos/RIOT-OS/RIOT/milestones{/number}","notifications_url":"https://api.github.com/repos/RIOT-OS/RIOT/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RIOT-OS/RIOT/labels{/name}","releases_url":"https://api.github.com/repos/RIOT-OS/RIOT/releases{/id}","deployments_url":"https://api.github.com/repos/RIOT-OS/RIOT/deployments","created_at":"2012-12-29T20:38:40Z","updated_at":"2016-03-18T17:05:07Z","pushed_at":"2016-03-18T23:16:46Z","git_url":"git://github.com/RIOT-OS/RIOT.git","ssh_url":"git@github.com:RIOT-OS/RIOT.git","clone_url":"https://github.com/RIOT-OS/RIOT.git","svn_url":"https://github.com/RIOT-OS/RIOT","homepage":"https://github.com/RIOT-OS/RIOT/wiki","size":86734,"stargazers_count":710,"watchers_count":710,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":523,"mirror_url":null,"open_issues_count":462,"forks":523,"open_issues":462,"watchers":710,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/4980"},"issue":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4980"},"comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4980/comments"},"review_comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980/comments"},"review_comment":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4980/commits"},"statuses":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/53cd02d093cd40458780ff9b8bd9c1c412af64a4"}}}}