{"action":"created","issue":{"url":"https://api.github.com/repos/buserror/simavr/issues/304","repository_url":"https://api.github.com/repos/buserror/simavr","labels_url":"https://api.github.com/repos/buserror/simavr/issues/304/labels{/name}","comments_url":"https://api.github.com/repos/buserror/simavr/issues/304/comments","events_url":"https://api.github.com/repos/buserror/simavr/issues/304/events","html_url":"https://github.com/buserror/simavr/issues/304","id":356642638,"node_id":"MDU6SXNzdWUzNTY2NDI2Mzg=","number":304,"title":"Changing state with AVR_IOCTL_IOPORT_SET_EXTERNAL does not update reading PINx if you don't write to the port","user":{"login":"carangil","id":290308,"node_id":"MDQ6VXNlcjI5MDMwOA==","avatar_url":"https://avatars1.githubusercontent.com/u/290308?v=4","gravatar_id":"","url":"https://api.github.com/users/carangil","html_url":"https://github.com/carangil","followers_url":"https://api.github.com/users/carangil/followers","following_url":"https://api.github.com/users/carangil/following{/other_user}","gists_url":"https://api.github.com/users/carangil/gists{/gist_id}","starred_url":"https://api.github.com/users/carangil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carangil/subscriptions","organizations_url":"https://api.github.com/users/carangil/orgs","repos_url":"https://api.github.com/users/carangil/repos","events_url":"https://api.github.com/users/carangil/events{/privacy}","received_events_url":"https://api.github.com/users/carangil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-04T03:42:41Z","updated_at":"2018-09-25T08:51:10Z","closed_at":null,"author_association":"NONE","body":"This does not work as expected:\r\n\r\non the AVR:\r\n\r\n```\r\n \r\n char buf[10];\r\n DDRD=0x00;\r\n PORTD=0;\r\n prints(env->out, \"SET\\n\");\r\n \r\n while(1){\r\n \t\t\t\t\r\n \tprints(env->out, itoa(PIND, buf, 10));\r\n \tprints(env->out,\"\\n\");\r\n }\r\n``` \r\n\r\nThe sets the DDRD to all inputs, and prints 'SET' to the usart.  It then starts printing out on the USART the value of PIND.\r\n\r\n\r\nIn simavr application:\r\n```\r\n\r\n  for (;;) {\r\n \tvr_ioport_external_t p;\r\n \r\n \tint state = avr_run(avr);\r\n \tif (state == cpu_Done || state == cpu_Crashed)\r\n \t\tbreak;\r\n \r\n \tif (kbhit()) {\r\n \t\t//when key is pressed, change the pull up/down values\r\n \t\tgetch();\r\n \t\tp.mask = 0xff;\r\n \t\tp.value = 111;\r\n \t\tavr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('D'), &p);\r\n \t}\r\n \r\n  }\r\n \r\n```\r\n\r\nThe idea is after seeing 'SET' go out the usart, the simavr user presses a key.  This changes the pullup values.  The value read from PIND in the AVR loop should change.  It does not.\r\n\r\nChanging the AVR code to this does work:\r\n\r\n```\r\nchar buf[10];\r\nDDRD=0x00;\r\nPORTD=0;\r\nprints(env->out, \"SET\\n\");\r\n\r\nwhile(1){\r\n\tDDRD=0x00;\r\n\tPORTD=0;\t\r\n\tprints(env->out, itoa(PIND, buf, 10));\r\n\tprints(env->out,\"\\n\");\r\n}\r\n\r\n```\r\n\r\nIt seems the act of writing either DDR or PORT will update PIN properly taking into account the new external defaults.  But changing the external defaults does not update PIN by itself.  I think avr_ioport_read needs to look the updated value of .external.pull_value.  This logic ( if output, else if external pull, else if internal pull), is present in avr_ioport_update_irqs, but it seems like it needs to be in the direct read as well.\r\n\r\n\r\nPerhaps I am using simavr incorrectly?  In my application loop I do this: (pseudocode)\r\n\r\n```\r\nwhile(1){\r\n avr_run(avr)\r\n use avr_ioctl to read the all the port's status with AVR_IOCTL_IOPORT_GETSTATE\r\n emulate whatever computational logic and peripherals I have on the board\r\n use avr_ioctl to set the new inputs (PINx) with AVR_IOCTL_IOPORT_SET_EXTERNAL\r\n}\r\n```\r\n\r\nMost examples set up IRQs for each pin.  I am doing IRQs for the usart.  I am trying to emulate a physical board I have which uses a whole port (PORTB) as an 8-bit bus.  I don't see a way to get a callback that tells me all 8 pins of the port at once as a byte, or a way to set all 8 pin inputs at once as a byte, except thru the ioctl calls above.  If I set up an ioctl for each pin, when the AVR writes a byte on a port, I get 8 callbacks, each giving me 1 bit of the port.  This seems to be the way simavr is intended to be used, and also seems completely crazy to me.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/buserror/simavr/issues/comments/424259123","html_url":"https://github.com/buserror/simavr/issues/304#issuecomment-424259123","issue_url":"https://api.github.com/repos/buserror/simavr/issues/304","id":424259123,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDI1OTEyMw==","user":{"login":"buserror","id":157201,"node_id":"MDQ6VXNlcjE1NzIwMQ==","avatar_url":"https://avatars2.githubusercontent.com/u/157201?v=4","gravatar_id":"","url":"https://api.github.com/users/buserror","html_url":"https://github.com/buserror","followers_url":"https://api.github.com/users/buserror/followers","following_url":"https://api.github.com/users/buserror/following{/other_user}","gists_url":"https://api.github.com/users/buserror/gists{/gist_id}","starred_url":"https://api.github.com/users/buserror/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buserror/subscriptions","organizations_url":"https://api.github.com/users/buserror/orgs","repos_url":"https://api.github.com/users/buserror/repos","events_url":"https://api.github.com/users/buserror/events{/privacy}","received_events_url":"https://api.github.com/users/buserror/received_events","type":"User","site_admin":false},"created_at":"2018-09-25T08:51:10Z","updated_at":"2018-09-25T08:51:10Z","author_association":"OWNER","body":"Actually if you look at the code, you'll find there IS a IRQ that sends the whole port as a whole. IOPORT_IRQ_PIN_ALL is exactly what you want. Most examples don't need it, but it's there..."}}
{"actor":{"display_login":"buserror"}}