{"action":"created","comment":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/46267530","id":46267530,"diff_hunk":"@@ -27,132 +29,384 @@\n \n #define ENABLE_DEBUG (0)\n #include \"debug.h\"\n+\n /* guard file in case no timers are defined */\n-#if TIMER_0_EN\n+#if TIMER_NUMOF\n \n /**\n  * @brief Struct holding the configuration data\n  * @{\n  */\n typedef struct {\n-    void (*cb)(int);            /**< timeout callback */\n+    void (*cb)(int);        /**< timeout callback */\n+    unsigned int diviser;    /**< software clock diviser */\n } timer_conf_t;\n \n static timer_conf_t config[TIMER_NUMOF];\n /**@}*/\n \n+#include \"hw_timer.h\"\n+\n+/* Missing from driverlib */\n+static inline unsigned long\n+PRIV_TimerPrescaleSnapshotGet(unsigned long ulBase, unsigned long ulTimer) {\n+    return((ulTimer == TIMER_A) ? HWREG(ulBase + TIMER_O_TAPS) :\n+           HWREG(ulBase + TIMER_O_TBPS));\n+}\n+\n+static inline unsigned long long _scaled_to_ll_value(unsigned int uncorrected, unsigned int diviser)\n+{\n+    const unsigned long long scaledv = (unsigned long long) uncorrected * diviser;\n+    return scaledv;\n+}\n+\n+static inline unsigned int _llvalue_to_scaled_value(unsigned long long corrected, unsigned int diviser)\n+{\n+    const unsigned long long scaledv = corrected / diviser;\n+    return scaledv;\n+}\n+\n int timer_init(tim_t dev, unsigned int us_per_tick, void (*callback)(int))\n {\n-    if (dev == TIMER_0) {\n-        config[dev].cb = callback;                          /* User Function */\n-        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);  /* Activate Timer0 */\n-        WTIMER0_CTL_R &= ~0x00000001;                       /* Disable timer0A during setup */\n-        WTIMER0_CFG_R  = TIMER_CFG_16_BIT;\n-        WTIMER0_TAMR_R = TIMER_TAMR_TAMR_PERIOD;            /* Configure for periodic mode */\n-        WTIMER0_TAPR_R = TIMER_0_PRESCALER;                 /* 1us timer0A */\n-        WTIMER0_ICR_R  = 0x00000001;                        /* clear timer0A timeout flag */\n-        WTIMER0_IMR_R |= 0x00000001;                        /* arm timeout interrupt */\n-        ROM_IntPrioritySet(INT_WTIMER0A, 32);\n-        timer_irq_enable(dev);\n-        timer_start(dev);\n-        DEBUG(\"startTimeout Value=0x%lx\\n\", ROM_TimerValueGet(WTIMER0_BASE, TIMER_A));\n-        return 1;\n-    }\n-    return -1;\n+    if (dev >= TIMER_NUMOF){\n+        return -1;\n+    }\n+\n+    config[dev].cb = callback;                          /* User Function */\n+    config[dev].diviser = us_per_tick * ROM_SysCtlClockGet()/1000000;\n+\n+    unsigned int sysctl_timer;\n+    unsigned int timer_base;\n+    unsigned int timer_side = TIMER_A;\n+    unsigned int timer_cfg = TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC_UP;\n+    unsigned int timer_max_val;\n+    unsigned int timer_intbit = TIMER_TIMA_TIMEOUT | TIMER_TIMA_MATCH;\n+\n+    switch(dev){\n+#if TIMER_0_EN\n+    case TIMER_0:\n+        sysctl_timer = SYSCTL_PERIPH_WTIMER0;\n+        timer_base = WTIMER0_BASE;\n+        timer_max_val = TIMER_0_MAX_VALUE;\n+        break;\n+#endif\n+#if TIMER_1_EN\n+    case TIMER_1:\n+        sysctl_timer = SYSCTL_PERIPH_WTIMER1;\n+        timer_base = WTIMER1_BASE;\n+        timer_max_val = TIMER_1_MAX_VALUE;\n+        break;\n+#endif\n+    default:\n+        return -1; /* unreachable */\n+    }\n+\n+    if (timer_side == TIMER_A) {\n+        timer_cfg |= TIMER_TAMR_TAMIE;\n+    }\n+    else if (timer_side == TIMER_B) {\n+        timer_cfg |= TIMER_TBMR_TBMIE;\n+    }\n+\n+    ROM_SysCtlPeripheralEnable(sysctl_timer);\n+\n+    ROM_TimerDisable(timer_base, timer_side);\n+    ROM_TimerConfigure(timer_base, timer_cfg);\n+\n+    unsigned long long lltimer_val_max = _scaled_to_ll_value(timer_max_val, config[dev].diviser);\n+\n+    ROM_TimerPrescaleSet(timer_base, timer_side, lltimer_val_max >> 32);\n+    ROM_TimerLoadSet(timer_base, timer_side, lltimer_val_max & 0xFFFFFFFF);\n+    ROM_TimerIntClear(timer_base, timer_intbit);\n+\n+    ROM_TimerIntEnable(timer_base, timer_intbit);\n+\n+    timer_irq_enable(dev);\n+    timer_start(dev);\n+\n+    return 1;","path":"cpu/lm4f120/periph/timer.c","position":132,"original_position":132,"commit_id":"792de85fb78790443add704a710a637caa95990c","original_commit_id":"792de85fb78790443add704a710a637caa95990c","user":{"login":"dkm","id":87603,"avatar_url":"https://avatars.githubusercontent.com/u/87603?v=3","gravatar_id":"","url":"https://api.github.com/users/dkm","html_url":"https://github.com/dkm","followers_url":"https://api.github.com/users/dkm/followers","following_url":"https://api.github.com/users/dkm/following{/other_user}","gists_url":"https://api.github.com/users/dkm/gists{/gist_id}","starred_url":"https://api.github.com/users/dkm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkm/subscriptions","organizations_url":"https://api.github.com/users/dkm/orgs","repos_url":"https://api.github.com/users/dkm/repos","events_url":"https://api.github.com/users/dkm/events{/privacy}","received_events_url":"https://api.github.com/users/dkm/received_events","type":"User","site_admin":false},"body":"API states differently : http://riot-os.org/api/group__drivers__periph__timer.html#ga3ef6a48915b57707513ff17c0463a277","created_at":"2015-12-01T11:32:29Z","updated_at":"2015-12-01T11:32:29Z","html_url":"https://github.com/RIOT-OS/RIOT/pull/4089#discussion_r46267530","pull_request_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4089","_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/46267530"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/4089#discussion_r46267530"},"pull_request":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4089"}}},"pull_request":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4089","id":47586313,"html_url":"https://github.com/RIOT-OS/RIOT/pull/4089","diff_url":"https://github.com/RIOT-OS/RIOT/pull/4089.diff","patch_url":"https://github.com/RIOT-OS/RIOT/pull/4089.patch","issue_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4089","number":4089,"state":"open","locked":false,"title":"Reworking timer in lm4f120, fix #4077","user":{"login":"dkm","id":87603,"avatar_url":"https://avatars.githubusercontent.com/u/87603?v=3","gravatar_id":"","url":"https://api.github.com/users/dkm","html_url":"https://github.com/dkm","followers_url":"https://api.github.com/users/dkm/followers","following_url":"https://api.github.com/users/dkm/following{/other_user}","gists_url":"https://api.github.com/users/dkm/gists{/gist_id}","starred_url":"https://api.github.com/users/dkm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkm/subscriptions","organizations_url":"https://api.github.com/users/dkm/orgs","repos_url":"https://api.github.com/users/dkm/repos","events_url":"https://api.github.com/users/dkm/events{/privacy}","received_events_url":"https://api.github.com/users/dkm/received_events","type":"User","site_admin":false},"body":"Timer handling rewritten.\r\nAll xtimer tests are OK, except shift_change that does not compile.\r\nThere are still ways to improve the code (eg. Counting down instead of up could save a division), but at least now it works :)\r\n\r\nAs timer can't run at anything but system freq, I was forced to to some software scaling to be able to implement RIOT interface (and use xtimer...).\r\n","created_at":"2015-10-13T20:48:32Z","updated_at":"2015-12-01T11:32:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"26653641cf952ab7f2e700c4490433298988282a","assignee":{"login":"thomaseichinger","id":56618,"avatar_url":"https://avatars.githubusercontent.com/u/56618?v=3","gravatar_id":"","url":"https://api.github.com/users/thomaseichinger","html_url":"https://github.com/thomaseichinger","followers_url":"https://api.github.com/users/thomaseichinger/followers","following_url":"https://api.github.com/users/thomaseichinger/following{/other_user}","gists_url":"https://api.github.com/users/thomaseichinger/gists{/gist_id}","starred_url":"https://api.github.com/users/thomaseichinger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomaseichinger/subscriptions","organizations_url":"https://api.github.com/users/thomaseichinger/orgs","repos_url":"https://api.github.com/users/thomaseichinger/repos","events_url":"https://api.github.com/users/thomaseichinger/events{/privacy}","received_events_url":"https://api.github.com/users/thomaseichinger/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4089/commits","review_comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4089/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/4089/comments","statuses_url":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/792de85fb78790443add704a710a637caa95990c","head":{"label":"dkm:pr/timer","ref":"pr/timer","sha":"792de85fb78790443add704a710a637caa95990c","user":{"login":"dkm","id":87603,"avatar_url":"https://avatars.githubusercontent.com/u/87603?v=3","gravatar_id":"","url":"https://api.github.com/users/dkm","html_url":"https://github.com/dkm","followers_url":"https://api.github.com/users/dkm/followers","following_url":"https://api.github.com/users/dkm/following{/other_user}","gists_url":"https://api.github.com/users/dkm/gists{/gist_id}","starred_url":"https://api.github.com/users/dkm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkm/subscriptions","organizations_url":"https://api.github.com/users/dkm/orgs","repos_url":"https://api.github.com/users/dkm/repos","events_url":"https://api.github.com/users/dkm/events{/privacy}","received_events_url":"https://api.github.com/users/dkm/received_events","type":"User","site_admin":false},"repo":{"id":38816073,"name":"RIOT","full_name":"dkm/RIOT","owner":{"login":"dkm","id":87603,"avatar_url":"https://avatars.githubusercontent.com/u/87603?v=3","gravatar_id":"","url":"https://api.github.com/users/dkm","html_url":"https://github.com/dkm","followers_url":"https://api.github.com/users/dkm/followers","following_url":"https://api.github.com/users/dkm/following{/other_user}","gists_url":"https://api.github.com/users/dkm/gists{/gist_id}","starred_url":"https://api.github.com/users/dkm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkm/subscriptions","organizations_url":"https://api.github.com/users/dkm/orgs","repos_url":"https://api.github.com/users/dkm/repos","events_url":"https://api.github.com/users/dkm/events{/privacy}","received_events_url":"https://api.github.com/users/dkm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dkm/RIOT","description":"RIOT -  The friendly OS for IoT","fork":true,"url":"https://api.github.com/repos/dkm/RIOT","forks_url":"https://api.github.com/repos/dkm/RIOT/forks","keys_url":"https://api.github.com/repos/dkm/RIOT/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dkm/RIOT/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dkm/RIOT/teams","hooks_url":"https://api.github.com/repos/dkm/RIOT/hooks","issue_events_url":"https://api.github.com/repos/dkm/RIOT/issues/events{/number}","events_url":"https://api.github.com/repos/dkm/RIOT/events","assignees_url":"https://api.github.com/repos/dkm/RIOT/assignees{/user}","branches_url":"https://api.github.com/repos/dkm/RIOT/branches{/branch}","tags_url":"https://api.github.com/repos/dkm/RIOT/tags","blobs_url":"https://api.github.com/repos/dkm/RIOT/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dkm/RIOT/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dkm/RIOT/git/refs{/sha}","trees_url":"https://api.github.com/repos/dkm/RIOT/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dkm/RIOT/statuses/{sha}","languages_url":"https://api.github.com/repos/dkm/RIOT/languages","stargazers_url":"https://api.github.com/repos/dkm/RIOT/stargazers","contributors_url":"https://api.github.com/repos/dkm/RIOT/contributors","subscribers_url":"https://api.github.com/repos/dkm/RIOT/subscribers","subscription_url":"https://api.github.com/repos/dkm/RIOT/subscription","commits_url":"https://api.github.com/repos/dkm/RIOT/commits{/sha}","git_commits_url":"https://api.github.com/repos/dkm/RIOT/git/commits{/sha}","comments_url":"https://api.github.com/repos/dkm/RIOT/comments{/number}","issue_comment_url":"https://api.github.com/repos/dkm/RIOT/issues/comments{/number}","contents_url":"https://api.github.com/repos/dkm/RIOT/contents/{+path}","compare_url":"https://api.github.com/repos/dkm/RIOT/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dkm/RIOT/merges","archive_url":"https://api.github.com/repos/dkm/RIOT/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dkm/RIOT/downloads","issues_url":"https://api.github.com/repos/dkm/RIOT/issues{/number}","pulls_url":"https://api.github.com/repos/dkm/RIOT/pulls{/number}","milestones_url":"https://api.github.com/repos/dkm/RIOT/milestones{/number}","notifications_url":"https://api.github.com/repos/dkm/RIOT/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dkm/RIOT/labels{/name}","releases_url":"https://api.github.com/repos/dkm/RIOT/releases{/id}","created_at":"2015-07-09T11:21:00Z","updated_at":"2015-07-09T11:21:11Z","pushed_at":"2015-11-29T16:10:45Z","git_url":"git://github.com/dkm/RIOT.git","ssh_url":"git@github.com:dkm/RIOT.git","clone_url":"https://github.com/dkm/RIOT.git","svn_url":"https://github.com/dkm/RIOT","homepage":"https://github.com/RIOT-OS/RIOT/wiki","size":22256,"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":"febf71967c7d73184e7e05cd63e40c8b79e72e9b","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}","created_at":"2012-12-29T20:38:40Z","updated_at":"2015-12-01T08:49:38Z","pushed_at":"2015-12-01T10:01:21Z","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":78200,"stargazers_count":568,"watchers_count":568,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":439,"mirror_url":null,"open_issues_count":405,"forks":439,"open_issues":405,"watchers":568,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4089"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/4089"},"issue":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4089"},"comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4089/comments"},"review_comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/4089/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/4089/commits"},"statuses":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/792de85fb78790443add704a710a637caa95990c"}}}}