{"action":"opened","issue":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/4893","repository_url":"https://api.github.com/repos/ARMmbed/mbed-os","labels_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/4893/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/4893/comments","events_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/4893/events","html_url":"https://github.com/ARMmbed/mbed-os/issues/4893","id":249710158,"number":4893,"title":"Ticker issues with NRF52 platform, especially while using event queue call_every timer function.","user":{"login":"yogeshk19","id":21161918,"avatar_url":"https://avatars2.githubusercontent.com/u/21161918?v=4","gravatar_id":"","url":"https://api.github.com/users/yogeshk19","html_url":"https://github.com/yogeshk19","followers_url":"https://api.github.com/users/yogeshk19/followers","following_url":"https://api.github.com/users/yogeshk19/following{/other_user}","gists_url":"https://api.github.com/users/yogeshk19/gists{/gist_id}","starred_url":"https://api.github.com/users/yogeshk19/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yogeshk19/subscriptions","organizations_url":"https://api.github.com/users/yogeshk19/orgs","repos_url":"https://api.github.com/users/yogeshk19/repos","events_url":"https://api.github.com/users/yogeshk19/events{/privacy}","received_events_url":"https://api.github.com/users/yogeshk19/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-11T18:17:00Z","updated_at":"2017-08-11T18:17:00Z","closed_at":null,"body":"\r\n### Description\r\n- Type: Bug\r\n- Related issue: #3509, #3857 \r\n- Priority:  Major\r\n---------------------------------------------------------------\r\n**Target**\r\nNRF52_DK\r\n\r\n**Toolchain:**\r\nGCC_ARM\r\n\r\nMBED_OS version 5.4.4, 5.5\r\n\r\n**Expected behavior**\r\nEvent Queue's call_every method should invoke the call back method based on the interval passed to the call_every API. for ex: The application I have written expects to read a sensor every 30 seconds and transmit data to any Bluetooth Central device connected to it. \r\n**Actual behavior**\r\n\r\nIn **mbed os 5.4.4** the call back method takes forever to be invoked and it is pretty random. Sometimes its takes several minutes and sometimes it takes a few seconds. \r\n\r\nIn **mbed os 5.5** the application just gets into stack underflow error.\r\n\r\nHowever **in mbed os 5.3.3**, the call_every function works as expected. There was fix made in the issue #3857 and that was incorporated part of the mbed-os 5.4.4 which was supposed to address the ticker issue, however it seems to have made it worse. \r\n\r\n**Steps to reproduce**\r\n\r\n1) Take any of the example MBED BLE applications that is a BLE peripheral application and add the following code to ensure the device operates in low power mode and modify the application such that a sensor is read via the event queue call_every method.\r\n\r\n```\r\n#include <limits.h>\r\n#include <mbed.h>\r\n\r\n// import the time duration between two ticks (in us).\r\nextern const uint32_t os_clockrate;\r\n\r\n//initialize an event queue loop.\r\nstatic EventQueue eventQueue(16*32);\r\n\r\nvoid dummy_cb() { }\r\n\r\nvoid os_idle_demon (void) {\r\n    // use int rather than timestamp_t because units are not coherent \r\n    // between Timer and Timeout ...\r\n    const int max_us_sleep = (INT_MAX / os_clockrate) * os_clockrate; \r\n    Timer stopwatch;      // keep track of the time asleep\r\n    Timeout alarm_clock;  // will awake the uc if no interrupts does it before\r\n\r\n    // never ends, the rtos will suspend this thread when there is something to do\r\n    // either before os_suspend actually suspend the system (and is not in svc) \r\n    // or immediately after os_resume  \r\n    while (true) {\r\n        // suspend the system \r\n        uint32_t ticks_to_sleep = os_suspend();\r\n        uint32_t elapsed_ticks = 0;\r\n\r\n        if (ticks_to_sleep) { \r\n            uint64_t us_to_sleep = ticks_to_sleep * os_clockrate; \r\n\r\n            if (us_to_sleep > (uint32_t) max_us_sleep) { \r\n                us_to_sleep = max_us_sleep;\r\n            }\r\n\r\n            // start the stopwatch and setup the alarm_clock to wakeup the uc in us_to_sleep\r\n            stopwatch.start();\r\n            alarm_clock.attach_us(dummy_cb, us_to_sleep);\r\n\r\n            // go to sleep, most of the work is done by the softdevice \r\n            sleep();\r\n\r\n            // after sleep, unknown wake up source, can be the stopwatch or another IRQ\r\n            int us_asleep = stopwatch.read_us();\r\n\r\n            // stopwatch and alarm_clock cleanup\r\n            stopwatch.stop();\r\n            stopwatch.reset();\r\n            alarm_clock.detach();\r\n\r\n            // translate us asleep into ticks \r\n            elapsed_ticks = us_asleep / os_clockrate;\r\n        }\r\n\r\n        // resume the system \r\n        os_resume(elapsed_ticks);\r\n    }\r\n}\r\n```\r\n\r\nPlease let me know if I can add any more details, that would help us get un-blocked.\r\n\r\nThanks,\r\nYogesh\r\n\r\n"}}
{"actor":{"display_login":"yogeshk19"}}