|
| 1 | +/* |
| 2 | + * PicoSoC - A simple example SoC using PicoRV32 |
| 3 | + * |
| 4 | + * Copyright (C) 2017 Claire Xenia Wolf <claire@yosyshq.com> |
| 5 | + * Copyright (C) 2025 Myrtle Shah <gatecat@ds0.me> |
| 6 | + * |
| 7 | + * Permission to use, copy, modify, and/or distribute this software for any |
| 8 | + * purpose with or without fee is hereby granted, provided that the above |
| 9 | + * copyright notice and this permission notice appear in all copies. |
| 10 | + * |
| 11 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 12 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 13 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 14 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 15 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 16 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +`define PICOSOC_MEM picosoc_asic_mem |
| 22 | + |
| 23 | +module picosoc_asic_top ( |
| 24 | + input clk, |
| 25 | + input resetn, |
| 26 | + |
| 27 | + output ser_tx, |
| 28 | + input ser_rx, |
| 29 | + |
| 30 | + output [7:0] leds, |
| 31 | + |
| 32 | + output flash_csb, |
| 33 | + output flash_clk, |
| 34 | + |
| 35 | + output flash_io0_oe, |
| 36 | + output flash_io1_oe, |
| 37 | + output flash_io2_oe, |
| 38 | + output flash_io3_oe, |
| 39 | + |
| 40 | + output flash_io0_do, |
| 41 | + output flash_io1_do, |
| 42 | + output flash_io2_do, |
| 43 | + output flash_io3_do, |
| 44 | + |
| 45 | + input flash_io0_di, |
| 46 | + input flash_io1_di, |
| 47 | + input flash_io2_di, |
| 48 | + input flash_io3_di |
| 49 | +); |
| 50 | + |
| 51 | + wire iomem_valid; |
| 52 | + reg iomem_ready; |
| 53 | + wire [3:0] iomem_wstrb; |
| 54 | + wire [31:0] iomem_addr; |
| 55 | + wire [31:0] iomem_wdata; |
| 56 | + reg [31:0] iomem_rdata; |
| 57 | + |
| 58 | + reg [31:0] gpio; |
| 59 | + assign leds = gpio; |
| 60 | + |
| 61 | + always @(posedge clk) begin |
| 62 | + if (!resetn) begin |
| 63 | + gpio <= 0; |
| 64 | + end else begin |
| 65 | + iomem_ready <= 0; |
| 66 | + if (iomem_valid && !iomem_ready && iomem_addr[31:24] == 8'h 03) begin |
| 67 | + iomem_ready <= 1; |
| 68 | + iomem_rdata <= gpio; |
| 69 | + if (iomem_wstrb[0]) gpio[ 7: 0] <= iomem_wdata[ 7: 0]; |
| 70 | + if (iomem_wstrb[1]) gpio[15: 8] <= iomem_wdata[15: 8]; |
| 71 | + if (iomem_wstrb[2]) gpio[23:16] <= iomem_wdata[23:16]; |
| 72 | + if (iomem_wstrb[3]) gpio[31:24] <= iomem_wdata[31:24]; |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + picosoc soc ( |
| 78 | + .clk (clk ), |
| 79 | + .resetn (resetn ), |
| 80 | + |
| 81 | + .ser_tx (ser_tx ), |
| 82 | + .ser_rx (ser_rx ), |
| 83 | + |
| 84 | + .flash_csb (flash_csb ), |
| 85 | + .flash_clk (flash_clk ), |
| 86 | + |
| 87 | + .flash_io0_oe (flash_io0_oe), |
| 88 | + .flash_io1_oe (flash_io1_oe), |
| 89 | + .flash_io2_oe (flash_io2_oe), |
| 90 | + .flash_io3_oe (flash_io3_oe), |
| 91 | + |
| 92 | + .flash_io0_do (flash_io0_do), |
| 93 | + .flash_io1_do (flash_io1_do), |
| 94 | + .flash_io2_do (flash_io2_do), |
| 95 | + .flash_io3_do (flash_io3_do), |
| 96 | + |
| 97 | + .flash_io0_di (flash_io0_di), |
| 98 | + .flash_io1_di (flash_io1_di), |
| 99 | + .flash_io2_di (flash_io2_di), |
| 100 | + .flash_io3_di (flash_io3_di), |
| 101 | + |
| 102 | + .irq_5 (1'b0 ), |
| 103 | + .irq_6 (1'b0 ), |
| 104 | + .irq_7 (1'b0 ), |
| 105 | + |
| 106 | + .iomem_valid (iomem_valid ), |
| 107 | + .iomem_ready (iomem_ready ), |
| 108 | + .iomem_wstrb (iomem_wstrb ), |
| 109 | + .iomem_addr (iomem_addr ), |
| 110 | + .iomem_wdata (iomem_wdata ), |
| 111 | + .iomem_rdata (iomem_rdata ) |
| 112 | + ); |
| 113 | +endmodule |
| 114 | + |
| 115 | +module picosoc_asic_mem #( |
| 116 | + parameter integer WORDS = 256 |
| 117 | +) ( |
| 118 | + input clk, |
| 119 | + input [3:0] wen, |
| 120 | + input [21:0] addr, |
| 121 | + input [31:0] wdata, |
| 122 | + output reg [31:0] rdata |
| 123 | +); |
| 124 | + reg [31:0] mem [0:WORDS-1]; |
| 125 | + |
| 126 | + always @(posedge clk) begin |
| 127 | + if (wen == 4'b0) |
| 128 | + rdata <= mem[addr]; |
| 129 | + if (wen[0]) mem[addr][ 7: 0] <= wdata[ 7: 0]; |
| 130 | + if (wen[1]) mem[addr][15: 8] <= wdata[15: 8]; |
| 131 | + if (wen[2]) mem[addr][23:16] <= wdata[23:16]; |
| 132 | + if (wen[3]) mem[addr][31:24] <= wdata[31:24]; |
| 133 | + end |
| 134 | +endmodule |
| 135 | + |
0 commit comments