{"action":"created","issue":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/845","repository_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/845/labels{/name}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/845/comments","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/845/events","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/845","id":121888188,"number":845,"title":"gpio.trig doesn't play well with interpreter and can cause a panic","user":{"login":"pjsg","id":1508813,"avatar_url":"https://avatars.githubusercontent.com/u/1508813?v=3","gravatar_id":"","url":"https://api.github.com/users/pjsg","html_url":"https://github.com/pjsg","followers_url":"https://api.github.com/users/pjsg/followers","following_url":"https://api.github.com/users/pjsg/following{/other_user}","gists_url":"https://api.github.com/users/pjsg/gists{/gist_id}","starred_url":"https://api.github.com/users/pjsg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjsg/subscriptions","organizations_url":"https://api.github.com/users/pjsg/orgs","repos_url":"https://api.github.com/users/pjsg/repos","events_url":"https://api.github.com/users/pjsg/events{/privacy}","received_events_url":"https://api.github.com/users/pjsg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"TerryE","id":690173,"avatar_url":"https://avatars.githubusercontent.com/u/690173?v=3","gravatar_id":"","url":"https://api.github.com/users/TerryE","html_url":"https://github.com/TerryE","followers_url":"https://api.github.com/users/TerryE/followers","following_url":"https://api.github.com/users/TerryE/following{/other_user}","gists_url":"https://api.github.com/users/TerryE/gists{/gist_id}","starred_url":"https://api.github.com/users/TerryE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TerryE/subscriptions","organizations_url":"https://api.github.com/users/TerryE/orgs","repos_url":"https://api.github.com/users/TerryE/repos","events_url":"https://api.github.com/users/TerryE/events{/privacy}","received_events_url":"https://api.github.com/users/TerryE/received_events","type":"User","site_admin":false},"milestone":null,"comments":18,"created_at":"2015-12-12T23:58:40Z","updated_at":"2016-02-07T17:47:22Z","closed_at":null,"body":"The gpio module has support for callbacks which will be triggered when the specified condition happens on the selected pin. The code is called at interrupt level (I think) by the SDK. It can thus interrupt what is going on in the main line code. If you enable the asserts, and then run the following code, you can demonstrate the problem (with a bit of luck):\r\n\r\n```\r\nfunction gp()\r\n    p1 = 0\r\n    du = 0\r\n    gpio.mode(1,gpio.INT)\r\n    function pin1cb(level)\r\n       du = (tmr.now() - p1)\r\n       print(du)\r\n       p1 = tmr.now()\r\n       if level == 1 then gpio.trig(1, \"down\") else gpio.trig(1, \"up\") end\r\n    end\r\n    gpio.trig(1, \"down\",pin1cb)\r\nend\r\n\r\ngpio.mode(0, gpio.OUTPUT)\r\nbit = gpio.HIGH\r\ntmr.alarm(0, 100, 1, function() gpio.write(0, bit) bit = gpio.HIGH + gpio.LOW - bit end)\r\ngp()\r\n```\r\n\r\nOnce running this code, use a screwdriver (or something similar) to make a noisy connection from D0 to D1. Wiggle the screwdriver around, making and breaking the connection. I find that I can trigger assert failures within 10 to 15 seconds, sometimes with panics as here. For example:\r\n\r\n```\r\n2718\r\nlapi.c:607: L->top < L->ci->top\r\nlapi.c:447: L->top < L->ci->top\r\nlapi.c:830: (nresults) == (-1) || (L->ci->top - L->top >= (nresults) - (nargs))\r\nPANIC: unprotected error in call to Lua API (stdin:1: attempt to perform arithmetic on field 'HIGH' (a nil value))\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments/181060088","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/845#issuecomment-181060088","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/845","id":181060088,"user":{"login":"TerryE","id":690173,"avatar_url":"https://avatars.githubusercontent.com/u/690173?v=3","gravatar_id":"","url":"https://api.github.com/users/TerryE","html_url":"https://github.com/TerryE","followers_url":"https://api.github.com/users/TerryE/followers","following_url":"https://api.github.com/users/TerryE/following{/other_user}","gists_url":"https://api.github.com/users/TerryE/gists{/gist_id}","starred_url":"https://api.github.com/users/TerryE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TerryE/subscriptions","organizations_url":"https://api.github.com/users/TerryE/orgs","repos_url":"https://api.github.com/users/TerryE/repos","events_url":"https://api.github.com/users/TerryE/events{/privacy}","received_events_url":"https://api.github.com/users/TerryE/received_events","type":"User","site_admin":false},"created_at":"2016-02-07T17:47:22Z","updated_at":"2016-02-07T17:47:22Z","body":"@nickandrew, No this stuff is definitely Lua-land.  I apply a sort of \"Render unto Caesar\" argument: some things are better done in C and some in Lua.  This code is just a test harness which allows you to play with the interrupts.  What really surprises me is the electrical characteristics of simple brush contacts which some form of RC or more active deadbanding.  I could really do with having a look at these signals with a scope.  \r\n\r\nI've got the latest iteration of the gpio code working stably and integrated with the task interface.  I just need to finish some of the documentation before doing the PR.."}}