{"action":"created","issue":{"url":"https://api.github.com/repos/contiki-ng/contiki-ng/issues/186","repository_url":"https://api.github.com/repos/contiki-ng/contiki-ng","labels_url":"https://api.github.com/repos/contiki-ng/contiki-ng/issues/186/labels{/name}","comments_url":"https://api.github.com/repos/contiki-ng/contiki-ng/issues/186/comments","events_url":"https://api.github.com/repos/contiki-ng/contiki-ng/issues/186/events","html_url":"https://github.com/contiki-ng/contiki-ng/issues/186","id":275616628,"node_id":"MDU6SXNzdWUyNzU2MTY2Mjg=","number":186,"title":"cc2538 timer issue","user":{"login":"yoyo890121","id":22190904,"node_id":"MDQ6VXNlcjIyMTkwOTA0","avatar_url":"https://avatars0.githubusercontent.com/u/22190904?v=4","gravatar_id":"","url":"https://api.github.com/users/yoyo890121","html_url":"https://github.com/yoyo890121","followers_url":"https://api.github.com/users/yoyo890121/followers","following_url":"https://api.github.com/users/yoyo890121/following{/other_user}","gists_url":"https://api.github.com/users/yoyo890121/gists{/gist_id}","starred_url":"https://api.github.com/users/yoyo890121/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yoyo890121/subscriptions","organizations_url":"https://api.github.com/users/yoyo890121/orgs","repos_url":"https://api.github.com/users/yoyo890121/repos","events_url":"https://api.github.com/users/yoyo890121/events{/privacy}","received_events_url":"https://api.github.com/users/yoyo890121/received_events","type":"User","site_admin":false},"labels":[{"id":761650121,"node_id":"MDU6TGFiZWw3NjE2NTAxMjE=","url":"https://api.github.com/repos/contiki-ng/contiki-ng/labels/bug","name":"bug","color":"fbca04","default":true},{"id":604452909,"node_id":"MDU6TGFiZWw2MDQ0NTI5MDk=","url":"https://api.github.com/repos/contiki-ng/contiki-ng/labels/bug/medium","name":"bug/medium","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2017-11-21T07:54:07Z","updated_at":"2018-11-09T12:59:36Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\nI try to add a process with timer to do something periodically in `border-router-embedded.c` and `coap-example-server.c`.\r\nI use TSCH MAC layer and my device is cc2538dk.\r\nI tried contiki and timer trigger insanely in beginning, and I set `LPM_CONF_ENABLE` to 0 it still occurred sometime, so I wanted to try contiki-ng.\r\nIt seemed to work well in beginning, but sometimes this situation occurred after 3 days in my test.\r\n\r\nThanks.\r\n\r\n```\r\nPROCESS(node_process, \"Node Timer\");\r\n\r\nPROCESS_THREAD(node_process, ev, data)\r\n{\r\n  static struct etimer etaa;\r\n  PROCESS_BEGIN();\r\n  static int i=0;  \r\n  etimer_set(&etaa, CLOCK_SECOND * 10);  \r\n  while(1) {\r\n    printf(\"10 seconds. \\t i=%d \\n\", i);\r\n    PROCESS_YIELD_UNTIL(etimer_expired(&etaa));\r\n    etimer_reset(&etaa);\r\n    i++;    \r\n  }\r\n  PROCESS_END();\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/contiki-ng/contiki-ng/issues/comments/437352484","html_url":"https://github.com/contiki-ng/contiki-ng/issues/186#issuecomment-437352484","issue_url":"https://api.github.com/repos/contiki-ng/contiki-ng/issues/186","id":437352484,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNzM1MjQ4NA==","user":{"login":"lukasostendorf","id":44869119,"node_id":"MDQ6VXNlcjQ0ODY5MTE5","avatar_url":"https://avatars0.githubusercontent.com/u/44869119?v=4","gravatar_id":"","url":"https://api.github.com/users/lukasostendorf","html_url":"https://github.com/lukasostendorf","followers_url":"https://api.github.com/users/lukasostendorf/followers","following_url":"https://api.github.com/users/lukasostendorf/following{/other_user}","gists_url":"https://api.github.com/users/lukasostendorf/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasostendorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasostendorf/subscriptions","organizations_url":"https://api.github.com/users/lukasostendorf/orgs","repos_url":"https://api.github.com/users/lukasostendorf/repos","events_url":"https://api.github.com/users/lukasostendorf/events{/privacy}","received_events_url":"https://api.github.com/users/lukasostendorf/received_events","type":"User","site_admin":false},"created_at":"2018-11-09T12:59:36Z","updated_at":"2018-11-09T12:59:36Z","author_association":"NONE","body":"Hey,\r\n\r\nI think I am encountering the same issue, it is just as @g-oikonomou concluded.\r\nI am running a test in which I send a constant data-stream over multiple hops using tsch-mac and nullnet.\r\nThe tests last multiple hours, every 2 hours I change some parameters using an etimer.\r\n\r\nA slight difference is that in my app, the difference between the `now` and `prev_rt_ticks_startup` variable is not just 1 or 2 ticks, it is in the range of 50-200.\r\n\r\nHave a look at at the [beginning of update_ticks()](https://github.com/contiki-ng/contiki-ng/blob/develop/arch/cpu/cc2538/clock.c#L193):\r\n```c\r\nnow = RTIMER_NOW();\r\nprev_rt_ticks_startup = rt_ticks_startup;\r\n```\r\n\r\nCould the reason why `now` is a little bit smaller than `prev_rt_ticks ` be that the function is interrupted immediately after the `now` variable is set and the interrupt then changes `rt_ticks_startup`?\r\nTherefore after the interrupt, `prev_rt_ticks_startup` is set to the updated (and therefore larger than `now`) `rt_ticks_startup`.\r\n\r\nAs suggested, I logged the caller function when update_ticks behaves strangely. It is `clock_adjust()`, so it looks like the error happens on device wakeup.\r\nIs it possible that while `clock_adjust()` is executing update_ticks(), `clock_isr()` interrupts update_ticks?\r\n\r\nDisabling interrupts while setting the two variables seems to fix the issue:\r\n```c\r\nINTERRUPT_DISABLE();\r\nnow = RTIMER_NOW();\r\nprev_rt_ticks_startup = rt_ticks_startup;\r\nINTERRUPT_ENABLE();\r\n```\r\n\r\nI ran this changed code for 15h on two devices by now and the problem did not occur again.\r\n\r\nAnother possible fix should be setting the `prev_rt_ticks` variable first, so an interrupt between the operations will have no effect:\r\n```c\r\nprev_rt_ticks_startup = rt_ticks_startup;\r\nnow = RTIMER_NOW();\r\n```\r\n\r\nAny thoughts on this, or something else I could test to identify the cause of this behavior?"}}
{"actor":{"display_login":"lukasostendorf"}}