|
7 | 7 | else $error("Interface data width of %0d is incorrect. Shall be %0d bits", $bits({{cpuif.signal("wdata")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH); |
8 | 8 | end |
9 | 9 | `endif |
10 | | -{% endif -%} |
11 | | - |
12 | | -// OBI Interface Implementation |
13 | | -// This register block acts as an OBI subordinate |
14 | 10 |
|
15 | | -localparam int unsigned DATA_WIDTH = {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH; |
16 | | -localparam int unsigned BYTES = DATA_WIDTH/8; |
| 11 | +{% endif -%} |
17 | 12 |
|
18 | 13 | // State & holding regs |
19 | | -logic is_active; // A request is being served (not yet fully responded) |
20 | | -logic gnt_q; // one-cycle grant for A-channel |
21 | | -logic rsp_pending; // response ready but not yet accepted by manager |
22 | | -logic [DATA_WIDTH-1:0] rsp_rdata_q; |
23 | | -logic rsp_err_q; |
24 | | -logic [$bits({{cpuif.signal("aid")}})-1:0] rid_q; |
| 14 | +logic is_active; // A request is being served (not yet fully responded) |
| 15 | +logic gnt_q; // one-cycle grant for A-channel |
| 16 | +logic rsp_pending; // response ready but not yet accepted by manager |
| 17 | +logic [{{cpuif.data_width-1}}:0] rsp_rdata_q; |
| 18 | +logic rsp_err_q; |
| 19 | +logic [$bits({{cpuif.signal("rid")}})-1:0] rid_q; |
25 | 20 |
|
26 | 21 | // Latch AID on accept to echo back the response |
27 | 22 | always_ff {{get_always_ff_event(cpuif.reset)}} begin |
28 | | - if ({{get_resetsignal(cpuif.reset)}}) begin |
29 | | - is_active <= 1'b0; |
30 | | - gnt_q <= 1'b0; |
31 | | - rsp_pending <= 1'b0; |
32 | | - rsp_rdata_q <= '0; |
33 | | - rsp_err_q <= 1'b0; |
34 | | - rid_q <= '0; |
| 23 | + if ({{get_resetsignal(cpuif.reset)}}) begin |
| 24 | + is_active <= 1'b0; |
| 25 | + gnt_q <= 1'b0; |
| 26 | + rsp_pending <= 1'b0; |
| 27 | + rsp_rdata_q <= '0; |
| 28 | + rsp_err_q <= 1'b0; |
| 29 | + rid_q <= '0; |
35 | 30 |
|
36 | | - cpuif_req <= '0; |
37 | | - cpuif_req_is_wr <= '0; |
38 | | - cpuif_addr <= '0; |
39 | | - cpuif_wr_data <= '0; |
40 | | - cpuif_wr_biten <= '0; |
41 | | - end else begin |
42 | | - // defaults |
43 | | - cpuif_req <= 1'b0; |
44 | | - gnt_q <= {{cpuif.signal("req")}} & ~is_active; |
| 31 | + cpuif_req <= '0; |
| 32 | + cpuif_req_is_wr <= '0; |
| 33 | + cpuif_addr <= '0; |
| 34 | + cpuif_wr_data <= '0; |
| 35 | + cpuif_wr_biten <= '0; |
| 36 | + end else begin |
| 37 | + // defaults |
| 38 | + cpuif_req <= 1'b0; |
| 39 | + gnt_q <= {{cpuif.signal("req")}} & ~is_active; |
45 | 40 |
|
46 | | - // Accept new request when idle |
47 | | - if (~is_active) begin |
48 | | - if ({{cpuif.signal("req")}}) begin |
49 | | - is_active <= 1'b1; |
50 | | - cpuif_req <= 1'b1; |
51 | | - cpuif_req_is_wr <= {{cpuif.signal("we")}}; |
52 | | - cpuif_addr <= {{cpuif.signal("addr")}}; |
53 | | - cpuif_wr_data <= {{cpuif.signal("wdata")}}; |
54 | | - rid_q <= {{cpuif.signal("aid")}}; |
55 | | - for (int i = 0; i < BYTES; i++) begin |
56 | | - cpuif_wr_biten[i*8 +: 8] <= {8{ {{cpuif.signal("be")}}[i] }}; |
| 41 | + // Accept new request when idle |
| 42 | + if (~is_active) begin |
| 43 | + if ({{cpuif.signal("req")}}) begin |
| 44 | + is_active <= 1'b1; |
| 45 | + cpuif_req <= 1'b1; |
| 46 | + cpuif_req_is_wr <= {{cpuif.signal("we")}}; |
| 47 | + cpuif_addr <= {{cpuif.signal("addr")}}; |
| 48 | + cpuif_wr_data <= {{cpuif.signal("wdata")}}; |
| 49 | + rid_q <= {{cpuif.signal("aid")}}; |
| 50 | + for (int i = 0; i < {{cpuif.data_width_bytes}}; i++) begin |
| 51 | + cpuif_wr_biten[i*8 +: 8] <= {8{ {{cpuif.signal("be")}}[i] }}; |
| 52 | + end |
| 53 | + end |
57 | 54 | end |
58 | | - end |
59 | | - end |
60 | 55 |
|
61 | | - // Capture response |
62 | | - if (is_active && (cpuif_rd_ack || cpuif_wr_ack)) begin |
63 | | - rsp_pending <= 1'b1; |
64 | | - rsp_rdata_q <= cpuif_rd_data; |
65 | | - rsp_err_q <= cpuif_rd_err | cpuif_wr_err; |
66 | | - // NOTE: Keep 'is_active' asserted until the external R handshake completes |
67 | | - end |
| 56 | + // Capture response |
| 57 | + if (is_active && (cpuif_rd_ack || cpuif_wr_ack)) begin |
| 58 | + rsp_pending <= 1'b1; |
| 59 | + rsp_rdata_q <= cpuif_rd_data; |
| 60 | + rsp_err_q <= cpuif_rd_err | cpuif_wr_err; |
| 61 | + // NOTE: Keep 'is_active' asserted until the external R handshake completes |
| 62 | + end |
68 | 63 |
|
69 | | - // Complete external R-channel handshake only if manager ready |
70 | | - if (rsp_pending && {{cpuif.signal("rvalid")}} && {{cpuif.signal("rready")}}) begin |
71 | | - rsp_pending <= 1'b0; |
72 | | - is_active <= 1'b0; // free to accept the next request |
| 64 | + // Complete external R-channel handshake only if manager ready |
| 65 | + if (rsp_pending && {{cpuif.signal("rvalid")}} && {{cpuif.signal("rready")}}) begin |
| 66 | + rsp_pending <= 1'b0; |
| 67 | + is_active <= 1'b0; // free to accept the next request |
| 68 | + end |
73 | 69 | end |
74 | | - end |
75 | 70 | end |
76 | 71 |
|
77 | 72 | // R-channel outputs (held stable while rsp_pending=1) |
78 | 73 | assign {{cpuif.signal("rvalid")}} = rsp_pending; |
79 | | -assign {{cpuif.signal("rdata")}} = rsp_rdata_q; |
80 | | -assign {{cpuif.signal("err")}} = rsp_err_q; |
81 | | -assign {{cpuif.signal("rid")}} = rid_q; |
| 74 | +assign {{cpuif.signal("rdata")}} = rsp_rdata_q; |
| 75 | +assign {{cpuif.signal("err")}} = rsp_err_q; |
| 76 | +assign {{cpuif.signal("rid")}} = rid_q; |
82 | 77 |
|
83 | 78 | // A-channel grant (registered one-cycle pulse when we accept a request) |
84 | 79 | assign {{cpuif.signal("gnt")}} = gnt_q; |
85 | | - |
86 | | -// If OBI config RReady is disabled, tie it high in the top-level/TB. |
87 | | -// `ifndef SYNTHESIS |
88 | | -// initial begin |
89 | | -// if (0) $display("RReady supported; tie high if unused."); |
90 | | -// end |
91 | | -// `endif |
0 commit comments