added v2.0

This commit is contained in:
Michael Schröder
2023-01-11 11:13:09 +01:00
parent 2a5a64ca91
commit 971b323822
584 changed files with 159319 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
[*]
[*] GTKWave Analyzer v3.3.104 (w)1999-2020 BSI
[*] Thu Dec 29 18:09:36 2022
[*]
[dumpfile] "/home/micha/gitlab/nand2tetris-fpga/06_IO_Devices/05_GO/GO_tb.vcd"
[dumpfile_mtime] "Thu Dec 29 18:09:26 2022"
[dumpfile_size] 80439
[savefile] "/home/micha/gitlab/nand2tetris-fpga/06_IO_Devices/05_GO/GO_tb.gtkw"
[timestart] 0
[size] 1440 713
[pos] 34 87
*-17.000000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
[sst_width] 281
[signals_width] 240
[sst_expanded] 1
[sst_vpaned_height] 172
@200
-IN
@28
GO_tb.clk
GO_tb.load
@22
GO_tb.pc[15:0]
GO_tb.sram_addr[15:0]
GO_tb.ROM_data[15:0]
GO_tb.sram_data[15:0]
@200
-OUT
@22
GO_tb.SRAM_ADDR[15:0]
GO_tb.instruction[15:0]
@200
-CMP
@22
GO_tb.SRAM_ADDR_cmp[15:0]
GO_tb.instruction_cmp[15:0]
@200
-Test
@28
GO_tb.fail
[pattern_trace] 1
[pattern_trace] 0

View File

@@ -0,0 +1,73 @@
`timescale 10ns/1ns
`default_nettype none
module GO_tb();
// IN,OUT
reg clk = 0;
reg load = 0;
reg [15:0] sram_addr=0;
reg [15:0] pc=0;
wire [15:0] SRAM_ADDR;
reg [15:0] ROM_data=0;
reg [15:0] sram_data=0;
wire [15:0] instruction;
// Part
GO GO(
.clk(clk),
.load(load),
.sram_addr(sram_addr),
.pc(pc),
.SRAM_ADDR(SRAM_ADDR),
.ROM_data(ROM_data),
.sram_data(sram_data),
.instruction(instruction)
);
// Simulate
always #2 clk=~clk;
wire trigger;
reg write;
assign trigger = (n==10);
always @(posedge clk) begin
sram_addr <= $random;
pc <= $random;
ROM_data <= $random;
sram_data <= $random;
load <= trigger;
end
// Compare
reg fail = 0;
reg [31:0] n = 0;
reg run=0;
always @(posedge clk)
if (load) run <=1;
wire [15:0] SRAM_ADDR_cmp=run?pc:sram_addr;
wire [15:0] instruction_cmp=run?sram_data:ROM_data;
task check;
#4
if ((SRAM_ADDR!=SRAM_ADDR_cmp) || (instruction!=instruction_cmp))
begin
$display("FAIL: clk=%1b, load=%1b",clk,load);
fail=1;
end
endtask
initial begin
$dumpfile("GO_tb.vcd");
$dumpvars(0, GO_tb);
$display("------------------------");
$display("Testbench: GO");
for (n=0; n<20;n=n+1)
check();
if (fail==0) $display("passed");
$display("------------------------");
$finish;
end
endmodule

View File

@@ -0,0 +1,40 @@
`include "../../01_Boolean_Logic/Nand.v"
`include "../../01_Boolean_Logic/Not.v"
`include "../../01_Boolean_Logic/Buffer.v"
`include "../../01_Boolean_Logic/And.v"
`include "../../01_Boolean_Logic/Or.v"
`include "../../01_Boolean_Logic/Xor.v"
`include "../../01_Boolean_Logic/Mux.v"
`include "../../01_Boolean_Logic/DMux.v"
`include "../../01_Boolean_Logic/Not16.v"
`include "../../01_Boolean_Logic/Buffer16.v"
`include "../../01_Boolean_Logic/And16.v"
`include "../../01_Boolean_Logic/Or16.v"
`include "../../01_Boolean_Logic/Mux16.v"
`include "../../01_Boolean_Logic/Or8Way.v"
`include "../../01_Boolean_Logic/Mux4Way16.v"
`include "../../01_Boolean_Logic/Mux8Way16.v"
`include "../../01_Boolean_Logic/DMux4Way.v"
`include "../../01_Boolean_Logic/DMux8Way.v"
`include "../../02_Boolean_Arithmetic/HalfAdder.v"
`include "../../02_Boolean_Arithmetic/FullAdder.v"
`include "../../02_Boolean_Arithmetic/Add16.v"
`include "../../02_Boolean_Arithmetic/Inc16.v"
`include "../../02_Boolean_Arithmetic/ALU.v"
`include "../../03_Sequential_Logic/DFF.v"
`include "../../03_Sequential_Logic/Bit.v"
`include "../../03_Sequential_Logic/Register.v"
`include "../../03_Sequential_Logic/PC.v"
`include "../../03_Sequential_Logic/BitShift9R.v"
`include "../../03_Sequential_Logic/BitShift8L.v"
`include "../../06_IO_Devices/UartTX.v"
`include "../../06_IO_Devices/UartRX.v"
`include "../../06_IO_Devices/SPI.v"
`include "../../06_IO_Devices/InOut.v"
`include "../../06_IO_Devices/SRAM_D.v"
`include "../../06_IO_Devices/GO.v"
`include "../../06_IO_Devices/LCD.v"
`include "../../06_IO_Devices/RTP.v"

View File

@@ -0,0 +1,12 @@
NAME = boot
all: asm install
asm:
../../tools/Assembler/assembler.pyc $(NAME).asm
install:
cp $(NAME).hack ../00_HACK/ROM.hack
clean:
rm -f *.hack *~
.PHONY: all clean

View File

@@ -0,0 +1,82 @@
## 05 GO
The instrucition memory ROM of HACK is limited to 256 words. In order to run bigger programs written in JACK (e.g. tetris) we will store the program to SRAM and use the SRAM memory chip as instruction memory. For this we need:
1. A bootloader program written in assembler (which is stored in the 256 words of ROM), that reads a (bigger) hack binary program previously stored on SPI memory chip starting at address 0x010000 and stores it to SRAM.
2. A multiplexer, that switches instruction memory from ROM to SRAM.
### Chip specification
When load=1 `GO` switches HACK operation from boot mode to run mode. In boot mode instruction=ROM_data and SRAM_ADDR=sram_a. In run mode instruction=sram_data and SRAM_ADDR=pc.
### Memory map
The special function register `GO` is memory mapped to address 4103
| addr | R/W | function |
| ---- | --- | ----------------------------------------------------------------------------------------------------------- |
| 4103 | W | a write resets the HACK CPU and switches instrucion memory from ROM (bootloader) to SRAM (JACK application) |
### boot.asm
bootloader that reads 64k words from SPI flash memory starting from address 0x010000 and writes them to SRAM. FInally it resets the CPU and starts program execution from SRAM.
To run the testbench it's sufficient to read only the first 6 words. The SPI in the testbench is preloaded with the following 6 assembler instructions of the program `leds.asm` translated into HACK machine language:
```
@BUT
D=M
@LED
M=D
@0
0;JMP
```
***
### Project
* Implement `boot.asm` (read only the first 6 words) and run the testbench:
```
$ cd 05_GO
$ make
$ cd ../00_HACK
$ apio
$ apio sim
```
![](go.png)
* Check, if HACK reads 6 instrucions from SPI and writes them to SRAM.
* Check, if HACK can switch from instruction memory ROM (bootloader= to instruction memory SRAM (application) when loadGO=1.
* Check, if HACK runs `leds.asm` after switching from boot to run.
### Run in real hardware
* preload SPI flash rom with the hack programm `leds.asm.`
```
$ cd ../../04_Machine_Language
$ make leds
$ make upload
```
* upload HACK with bootloader to iCE40HX1K-EVB
```
$ cd 05_GO
$ make
$ cd ../00HACK
$ apio clean
$ apio upload
```
* Check if iCE40HX1K-EVB runs the bootloader, which loads `leds.asm` from SPI and starts execution of leds.asm.
If `leds.asm` is working, you are ready to start implementing the operating system JACK-OS. Proceed to project `07_Operating_System` and come back later to implement the last to IO-Devices `LCD` and `RTP` to connect the screen with resitive touch panel MOD-LCD2.8RTP.

View File

@@ -0,0 +1,3 @@
[env]
board = iCE40-HX1K-EVB

View File

@@ -0,0 +1,5 @@
//*****************************************************************************
// Boot loader. Load HACK code from SPI address 0x010000 (64k) into SRAM and GO
//*****************************************************************************
//
// Put your code here:

BIN
06_IO_Devices/05_GO/go.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB