diff options
Diffstat (limited to 'atk16_fpga')
| -rw-r--r-- | atk16_fpga/flash.v | 60 | ||||
| -rw-r--r-- | atk16_fpga/flash_to_ram.v | 27 | ||||
| -rw-r--r-- | atk16_fpga/top.v | 5 |
3 files changed, 92 insertions, 0 deletions
diff --git a/atk16_fpga/flash.v b/atk16_fpga/flash.v new file mode 100644 index 0000000..908ecf0 --- /dev/null +++ b/atk16_fpga/flash.v @@ -0,0 +1,60 @@ +`timescale 1ns / 1ps + +// This is a memory model of the flash memory chip on the iCE40HX8K-EVB. +// Relevant specs: +// - 2MB space (not implemented entirely in simulation) +// - An SPI interface +module flash( + input wire cs, // Chip select, active low + input wire clk, // SPI clock + input wire mosi, // Master Out Slave In + output reg miso, // Master In Slave Out + input wire rst_n // Active low reset +); + + reg [7:0] memory [0:2047]; // A smaller memory space for simplicity + reg [7:0] command; + reg [10:0] address; + reg [7:0] temp_data; + reg [3:0] bit_count; + reg write_enable; + + always @(posedge clk or negedge rst_n) begin + if (!rst_n) begin + miso <= 1'b0; + command <= 8'b0; + address <= 11'b0; + temp_data <= 8'b0; + bit_count <= 4'b0; + write_enable <= 1'b0; + end else if (!cs) begin + if (bit_count < 8) begin + // First byte is the command + command[7 - bit_count] <= mosi; + end else if (bit_count < 19) begin + // Next 11 bits are the address + address[18 - bit_count] <= mosi; + end else if (command == 8'h02 && write_enable) begin + // Handle write command + if (bit_count < 28) begin + temp_data[27 - bit_count] <= mosi; + if (bit_count == 27) begin + memory[address] <= temp_data; + end + end + end else if (command == 8'h03) begin + // Handle read command + if (bit_count == 19) begin + temp_data <= memory[address]; + end + if (bit_count >= 20) begin + miso <= temp_data[27 - bit_count]; + end + end + bit_count <= bit_count + 1'b1; + end else begin + bit_count <= 0; + miso <= 1'bz; // Tristate when not active + end + end +endmodule diff --git a/atk16_fpga/flash_to_ram.v b/atk16_fpga/flash_to_ram.v new file mode 100644 index 0000000..2e0f7b6 --- /dev/null +++ b/atk16_fpga/flash_to_ram.v @@ -0,0 +1,27 @@ +module flash_to_ram( + // SRAM interface + output sram_cs_n, + output sram_rd_n, + output sram_wr_n, + output [17:0] sram_addr, + output [15:0] sram_in, + input [15:0] sram_out, + + // SPI master interface + output wire spi_cs_n, // Chip select, active low + output wire spi_clk, // SPI clock + output wire spi_mosi, // Master Out Slave In + input wire spi_miso, // Master In Slave Out + output wire spi_rst_n // Active low reset +); + + // Copy 128KB from flash address 2^20 onwards to SRAM address 0 + // 1. Send a read message to the flash + // 2. Wait for the flash to respond + // 3. Write the data to SRAM + // 4. Repeat until 128KB has been copied + + + + +endmodule diff --git a/atk16_fpga/top.v b/atk16_fpga/top.v index 975a7f5..065d034 100644 --- a/atk16_fpga/top.v +++ b/atk16_fpga/top.v @@ -1,5 +1,8 @@ `default_nettype none +`define PH_COPY_IMG 1'b0 +`define PH_RUN_IMG 1'b1 + module top( input wire SYSCLK, input wire BUT1, @@ -13,6 +16,8 @@ module top( input [3:0] INT ); + reg phase = `PH_COPY_IMG; + cu cu_inst( .clk(SYSCLK), .rst(BUT1), |
