{"action":"created","issue":{"url":"https://api.github.com/repos/phanrahan/magma/issues/228","repository_url":"https://api.github.com/repos/phanrahan/magma","labels_url":"https://api.github.com/repos/phanrahan/magma/issues/228/labels{/name}","comments_url":"https://api.github.com/repos/phanrahan/magma/issues/228/comments","events_url":"https://api.github.com/repos/phanrahan/magma/issues/228/events","html_url":"https://github.com/phanrahan/magma/issues/228","id":346263337,"node_id":"MDU6SXNzdWUzNDYyNjMzMzc=","number":228,"title":"Create example with @circuit.combinational that can emulate a verilog FSM","user":{"login":"rdaly525","id":14632648,"node_id":"MDQ6VXNlcjE0NjMyNjQ4","avatar_url":"https://avatars3.githubusercontent.com/u/14632648?v=4","gravatar_id":"","url":"https://api.github.com/users/rdaly525","html_url":"https://github.com/rdaly525","followers_url":"https://api.github.com/users/rdaly525/followers","following_url":"https://api.github.com/users/rdaly525/following{/other_user}","gists_url":"https://api.github.com/users/rdaly525/gists{/gist_id}","starred_url":"https://api.github.com/users/rdaly525/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdaly525/subscriptions","organizations_url":"https://api.github.com/users/rdaly525/orgs","repos_url":"https://api.github.com/users/rdaly525/repos","events_url":"https://api.github.com/users/rdaly525/events{/privacy}","received_events_url":"https://api.github.com/users/rdaly525/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"leonardt","id":3766436,"node_id":"MDQ6VXNlcjM3NjY0MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/3766436?v=4","gravatar_id":"","url":"https://api.github.com/users/leonardt","html_url":"https://github.com/leonardt","followers_url":"https://api.github.com/users/leonardt/followers","following_url":"https://api.github.com/users/leonardt/following{/other_user}","gists_url":"https://api.github.com/users/leonardt/gists{/gist_id}","starred_url":"https://api.github.com/users/leonardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonardt/subscriptions","organizations_url":"https://api.github.com/users/leonardt/orgs","repos_url":"https://api.github.com/users/leonardt/repos","events_url":"https://api.github.com/users/leonardt/events{/privacy}","received_events_url":"https://api.github.com/users/leonardt/received_events","type":"User","site_admin":false},"assignees":[{"login":"leonardt","id":3766436,"node_id":"MDQ6VXNlcjM3NjY0MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/3766436?v=4","gravatar_id":"","url":"https://api.github.com/users/leonardt","html_url":"https://github.com/leonardt","followers_url":"https://api.github.com/users/leonardt/followers","following_url":"https://api.github.com/users/leonardt/following{/other_user}","gists_url":"https://api.github.com/users/leonardt/gists{/gist_id}","starred_url":"https://api.github.com/users/leonardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonardt/subscriptions","organizations_url":"https://api.github.com/users/leonardt/orgs","repos_url":"https://api.github.com/users/leonardt/repos","events_url":"https://api.github.com/users/leonardt/events{/privacy}","received_events_url":"https://api.github.com/users/leonardt/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2018-07-31T16:26:11Z","updated_at":"2018-08-03T07:07:48Z","closed_at":"2018-08-03T07:07:48Z","author_association":"COLLABORATOR","body":"You should be able to nicely emulate something like the following Verilog FSM (which I wrote a long time ago for Rigel)\r\n```\r\n\r\n`define REG(clk, r, init, in) \\\r\n    always @(posedge clk or negedge rst_n) begin \\\r\n        if (!rst_n) r <= (init); \\\r\n        else r <= (in); \\\r\n    end\r\n\r\n    localparam IDLE=2'h0, HBLANK=2'h1, HACT=2'h2;\r\n    reg [10:0] pix_cnt_n;\r\n    reg [10:0] pix_cnt;\r\n\r\n    reg [1:0] pix_ns;\r\n    reg [1:0] pix_cs;\r\n\r\n    assign pixel_valid = (pix_cs == HACT);\r\n    always @(*) begin\r\n        case(pix_cs)\r\n            IDLE : begin\r\n                pix_ns = frameValid ? HBLANK : IDLE;\r\n                pix_cnt_n = 0;\r\n            end\r\n            HBLANK : begin\r\n                pix_ns = real_href ? HACT : HBLANK ;\r\n                pix_cnt_n = real_href ? `PIX_PER_LINE : 0;\r\n            end\r\n            HACT : begin\r\n                pix_ns = (pix_cnt == 1) ? HBLANK : HACT ;\r\n                pix_cnt_n = pix_cnt - 1'b1;\r\n            end\r\n            default : begin\r\n                pix_ns = IDLE ;\r\n                pix_cnt_n = 0;\r\n            end\r\n        endcase\r\n\r\n    end\r\n    `REG(pclk, pix_cs, IDLE, pix_ns)\r\n    `REG(pclk, pix_cnt, 0, pix_cnt_n)\r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/phanrahan/magma/issues/comments/410165297","html_url":"https://github.com/phanrahan/magma/issues/228#issuecomment-410165297","issue_url":"https://api.github.com/repos/phanrahan/magma/issues/228","id":410165297,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDE2NTI5Nw==","user":{"login":"leonardt","id":3766436,"node_id":"MDQ6VXNlcjM3NjY0MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/3766436?v=4","gravatar_id":"","url":"https://api.github.com/users/leonardt","html_url":"https://github.com/leonardt","followers_url":"https://api.github.com/users/leonardt/followers","following_url":"https://api.github.com/users/leonardt/following{/other_user}","gists_url":"https://api.github.com/users/leonardt/gists{/gist_id}","starred_url":"https://api.github.com/users/leonardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonardt/subscriptions","organizations_url":"https://api.github.com/users/leonardt/orgs","repos_url":"https://api.github.com/users/leonardt/repos","events_url":"https://api.github.com/users/leonardt/events{/privacy}","received_events_url":"https://api.github.com/users/leonardt/received_events","type":"User","site_admin":false},"created_at":"2018-08-03T07:07:48Z","updated_at":"2018-08-03T07:07:48Z","author_association":"COLLABORATOR","body":"I also agree that we should stick with python syntax, also there's an order of evaluation issue here\r\n```\r\n>>> def ite(cond, t, f):\r\n...     return t if cond else f\r\n...\r\n>>> ite(1, print(True), print(False))\r\nTrue\r\nFalse\r\n>>> print(True) if 1 else print(False)\r\nTrue\r\n>>>\r\n```\r\nBut I don't think that comes up with magma code since we just rewire the ast and all the hardware expressions get evaluated and the result is muxed based on select, so actually the `ite` version may actually more closely match the semantics.\r\n\r\nHowever, the `ternary` function is trivial to write, so if a user prefers it, they can add a definition in their code. We can revisit this if it there's enough demand from users for it being built in.\r\n\r\nI'm going to close this for now since the above example has been implemented and added. I'll plan to add a version to the magmathon repo as a notebook to be the \"high-profile\" example."}}
{"actor":{"display_login":"leonardt"}}