diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 33 | ||||
| -rw-r--r-- | altera/clocks.sdc | 3 | ||||
| -rw-r--r-- | altera/jtag.cdf | 12 | ||||
| -rw-r--r-- | hdl/top.sv | 193 | ||||
| -rw-r--r-- | tcl/clean.tcl | 3 | ||||
| -rw-r--r-- | tcl/init.tcl | 104 |
7 files changed, 351 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44c81fc --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | /db | ||
| 2 | /incremental_db | ||
| 3 | /memctrl.* | ||
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3467cfb --- /dev/null +++ b/Makefile | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | SOURCES := $(wildcard hdl/**.sv) | ||
| 2 | QUARTUS := $(shell find altera tcl -name \*.cdf -o -name \*.sdc -o -name \*.tcl) | ||
| 3 | |||
| 4 | fpga: memctrl.sof | ||
| 5 | quartus_pgm -c 1 -m JTAG -o "P;$<@1" | ||
| 6 | nios2-terminal | ||
| 7 | .PHONY: fpga | ||
| 8 | |||
| 9 | build/p8bin2hex: tool/p8bin2hex.c | ||
| 10 | @mkdir -p build | ||
| 11 | gcc -Wall -Werror -o $@ $< | ||
| 12 | |||
| 13 | build/%.hex: build/%.bin build/p8bin2hex | ||
| 14 | build/p8bin2hex $< > $@ | ||
| 15 | |||
| 16 | build/%.hex: %.bin build/p8bin2hex | ||
| 17 | build/p8bin2hex $< > $@ | ||
| 18 | |||
| 19 | build/%.bin: %.pal | ||
| 20 | @mkdir -p $(dir $@) | ||
| 21 | palbart $< | ||
| 22 | mv -f $*.bin $*.lst $(dir $@) | ||
| 23 | |||
| 24 | memctrl.sof: $(SOURCES) $(QUARTUS) | ||
| 25 | [ ! -e memctrl.qpf ] || quartus_sh -t tcl/clean.tcl | ||
| 26 | quartus_sh -t tcl/init.tcl | ||
| 27 | quartus_sh --flow compile memctrl.qpf | ||
| 28 | |||
| 29 | clean: | ||
| 30 | git clean -dfX | ||
| 31 | .PHONY: clean | ||
| 32 | |||
| 33 | .SECONDARY: | ||
diff --git a/altera/clocks.sdc b/altera/clocks.sdc new file mode 100644 index 0000000..c08f897 --- /dev/null +++ b/altera/clocks.sdc | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | # This is the clock for timing analysis, not timing-driven synthesis. | ||
| 2 | # See init.tcl for the other clock. | ||
| 3 | create_clock -period "50 MHz" clock | ||
diff --git a/altera/jtag.cdf b/altera/jtag.cdf new file mode 100644 index 0000000..ac80090 --- /dev/null +++ b/altera/jtag.cdf | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | JedecChain; | ||
| 2 | FileRevision(JESD32A); | ||
| 3 | DefaultMfr(6E); | ||
| 4 | |||
| 5 | P ActionCode(Ign) | ||
| 6 | Device PartName(10CL025Y) MfrSpec(OpMask(0)); | ||
| 7 | |||
| 8 | ChainEnd; | ||
| 9 | |||
| 10 | AlteraBegin; | ||
| 11 | ChainType(JTAG); | ||
| 12 | AlteraEnd; | ||
diff --git a/hdl/top.sv b/hdl/top.sv new file mode 100644 index 0000000..babdc95 --- /dev/null +++ b/hdl/top.sv | |||
| @@ -0,0 +1,193 @@ | |||
| 1 | module top | ||
| 2 | ( input bit clock | ||
| 3 | , input bit resetn | ||
| 4 | |||
| 5 | , output bit ramresetn | ||
| 6 | , output bit [1:0] ramcsn | ||
| 7 | , output bit ramclkp | ||
| 8 | , output bit ramclkn | ||
| 9 | , input bit ramrwds | ||
| 10 | , inout bit [7:0] ramdata | ||
| 11 | ); | ||
| 12 | |||
| 13 | assign ramresetn = resetn; | ||
| 14 | assign ramclkn = !ramclkp; | ||
| 15 | |||
| 16 | bit ram_data_oe; | ||
| 17 | bit [7:0] ram_send_data; | ||
| 18 | |||
| 19 | assign ramdata = ram_data_oe ? ram_send_data : 8'bZ; | ||
| 20 | |||
| 21 | bit rx_ready; | ||
| 22 | bit rx_valid; | ||
| 23 | bit [7:0] rx_data; | ||
| 24 | |||
| 25 | bit tx_ready; | ||
| 26 | bit tx_valid; | ||
| 27 | bit [7:0] tx_data; | ||
| 28 | |||
| 29 | alt_jtag_atlantic | ||
| 30 | #( .INSTANCE_ID(0) | ||
| 31 | , .LOG2_RXFIFO_DEPTH(6) | ||
| 32 | , .LOG2_TXFIFO_DEPTH(6) | ||
| 33 | , .SLD_AUTO_INSTANCE_INDEX("NO") | ||
| 34 | ) jtag | ||
| 35 | ( .clk(clock) | ||
| 36 | , .rst_n(resetn) | ||
| 37 | , .r_dat(tx_data) | ||
| 38 | , .r_val(tx_valid) | ||
| 39 | , .r_ena(tx_ready) | ||
| 40 | , .t_dat(rx_data) | ||
| 41 | , .t_dav(rx_ready) | ||
| 42 | , .t_ena(rx_valid) | ||
| 43 | ); | ||
| 44 | |||
| 45 | bit input_byte_valid; | ||
| 46 | bit [7:0] input_byte; | ||
| 47 | |||
| 48 | bit [22:0] address; | ||
| 49 | bit [7:0] data; | ||
| 50 | bit write; | ||
| 51 | |||
| 52 | bit [47:0] command; | ||
| 53 | |||
| 54 | enum | ||
| 55 | { UART_READ_ADDRESS_OR_COMMAND | ||
| 56 | , UART_READ_DATA_1 | ||
| 57 | , UART_READ_DATA_0 | ||
| 58 | , RAM_WAIT_READY | ||
| 59 | , RAM_SEND_COMMAND_5 | ||
| 60 | , RAM_SEND_COMMAND_4 | ||
| 61 | , RAM_SEND_COMMAND_3 | ||
| 62 | , RAM_SEND_COMMAND_2 | ||
| 63 | , RAM_SEND_COMMAND_1 | ||
| 64 | , RAM_SEND_COMMAND_0 | ||
| 65 | , RAM_INIT_WAIT_DATA | ||
| 66 | , RAM_WAIT_DATA | ||
| 67 | , RAM_SENDRECV_DATA | ||
| 68 | , UART_WRITE_DATA_1 | ||
| 69 | , UART_WRITE_DATA_0 | ||
| 70 | } state; | ||
| 71 | |||
| 72 | always @(posedge clock) begin | ||
| 73 | if (!resetn) begin | ||
| 74 | ramcsn[0] = 1; | ||
| 75 | ramcsn[1] = 1; | ||
| 76 | ramclkp = 0; | ||
| 77 | ram_data_oe = 0; | ||
| 78 | rx_ready = 0; | ||
| 79 | tx_valid = 0; | ||
| 80 | input_byte_valid = 0; | ||
| 81 | address = 0; | ||
| 82 | state = state.first; | ||
| 83 | end else begin | ||
| 84 | if (tx_ready) tx_valid = 0; | ||
| 85 | if (rx_valid && !input_byte_valid && !tx_valid) begin | ||
| 86 | tx_valid = 1; | ||
| 87 | tx_data = rx_data; | ||
| 88 | input_byte_valid = 1; | ||
| 89 | input_byte = rx_data; | ||
| 90 | end | ||
| 91 | case (state) | ||
| 92 | UART_READ_ADDRESS_OR_COMMAND: | ||
| 93 | if (input_byte_valid) begin | ||
| 94 | if (input_byte >= "0" && input_byte <= "9") begin | ||
| 95 | address = address << 4; | ||
| 96 | address[3:0] = input_byte - "0"; | ||
| 97 | end else if (input_byte >= "a" && input_byte <= "f") begin | ||
| 98 | address = address << 4; | ||
| 99 | address[3:0] = input_byte - "a" + 10; | ||
| 100 | end else if (input_byte >= "A" && input_byte <= "F") begin | ||
| 101 | address = address << 4; | ||
| 102 | address[3:0] = input_byte - "A" + 10; | ||
| 103 | end else if (input_byte == "?") begin | ||
| 104 | write = 0; | ||
| 105 | command = {12'b100000000000, address[22:3], 13'b0, address[2:0]}; | ||
| 106 | address = 0; | ||
| 107 | data = 0; | ||
| 108 | state = RAM_SEND_COMMAND_5; | ||
| 109 | end else if (input_byte == "=") begin | ||
| 110 | write = 1; | ||
| 111 | command = {12'b000000000000, address[22:3], 13'b0, address[2:0]}; | ||
| 112 | address = 0; | ||
| 113 | data = 0; | ||
| 114 | state = UART_READ_DATA_1; | ||
| 115 | end | ||
| 116 | input_byte_valid = 0; | ||
| 117 | end | ||
| 118 | UART_READ_DATA_1, UART_READ_DATA_0: | ||
| 119 | if (input_byte_valid) begin | ||
| 120 | if (input_byte >= "0" && input_byte <= "9") begin | ||
| 121 | data = data << 4; | ||
| 122 | data[3:0] = input_byte - "0"; | ||
| 123 | state = state.next; | ||
| 124 | end else if (input_byte >= "a" && input_byte <= "f") begin | ||
| 125 | data = data << 4; | ||
| 126 | data[3:0] = input_byte - "a" + 10; | ||
| 127 | state = state.next; | ||
| 128 | end else if (input_byte >= "A" && input_byte <= "F") begin | ||
| 129 | data = data << 4; | ||
| 130 | data[3:0] = input_byte - "A" + 10; | ||
| 131 | state = state.next; | ||
| 132 | end | ||
| 133 | input_byte_valid = 0; | ||
| 134 | end | ||
| 135 | RAM_WAIT_READY: | ||
| 136 | begin | ||
| 137 | ramcsn[0] = 0; | ||
| 138 | if (ramrwds) state = state.next; | ||
| 139 | end | ||
| 140 | RAM_SEND_COMMAND_5, RAM_SEND_COMMAND_4, RAM_SEND_COMMAND_3, RAM_SEND_COMMAND_2, RAM_SEND_COMMAND_1, RAM_SEND_COMMAND_0: | ||
| 141 | begin | ||
| 142 | ramclkp = ~ramclkp; | ||
| 143 | ram_data_oe = 1; | ||
| 144 | ram_send_data = command[47:40]; | ||
| 145 | command = command << 8; | ||
| 146 | state = state.next; | ||
| 147 | end | ||
| 148 | RAM_INIT_WAIT_DATA: | ||
| 149 | begin | ||
| 150 | ramclkp = ~ramclkp; | ||
| 151 | ram_data_oe = 0; | ||
| 152 | state = state.next; | ||
| 153 | end | ||
| 154 | RAM_WAIT_DATA: | ||
| 155 | begin | ||
| 156 | ramclkp = ~ramclkp; | ||
| 157 | if (ramrwds) begin | ||
| 158 | if (write) begin | ||
| 159 | ram_data_oe = 1; | ||
| 160 | ram_send_data = data; | ||
| 161 | end | ||
| 162 | state = state.next; | ||
| 163 | end | ||
| 164 | end | ||
| 165 | RAM_SENDRECV_DATA: | ||
| 166 | begin | ||
| 167 | ramclkp = ~ramclkp; | ||
| 168 | ramcsn[0] = 1; | ||
| 169 | ram_data_oe = 0; | ||
| 170 | if (write) begin | ||
| 171 | state = state.first; | ||
| 172 | end else begin | ||
| 173 | data = ramdata; | ||
| 174 | state = UART_WRITE_DATA_1; | ||
| 175 | end | ||
| 176 | end | ||
| 177 | UART_WRITE_DATA_1, UART_WRITE_DATA_0: | ||
| 178 | if (!tx_valid) begin | ||
| 179 | tx_valid = 1; | ||
| 180 | if (data[7:4] < 10) begin | ||
| 181 | tx_data = data[7:4] + "0"; | ||
| 182 | end else begin | ||
| 183 | tx_data = data[7:4] + "A" - 10; | ||
| 184 | end | ||
| 185 | data = data << 4; | ||
| 186 | state = state.next; | ||
| 187 | end | ||
| 188 | endcase | ||
| 189 | rx_ready = !input_byte_valid && !tx_valid; | ||
| 190 | end | ||
| 191 | end | ||
| 192 | |||
| 193 | endmodule | ||
diff --git a/tcl/clean.tcl b/tcl/clean.tcl new file mode 100644 index 0000000..17de924 --- /dev/null +++ b/tcl/clean.tcl | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | project_open memctrl -revision memctrl | ||
| 2 | |||
| 3 | project_clean -revision memctrl | ||
diff --git a/tcl/init.tcl b/tcl/init.tcl new file mode 100644 index 0000000..13c08ec --- /dev/null +++ b/tcl/init.tcl | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | project_new memctrl -revision memctrl -overwrite | ||
| 2 | |||
| 3 | set_global_assignment -name DEVICE 10CL025YU256I7G | ||
| 4 | |||
| 5 | set_global_assignment -name TOP_LEVEL_ENTITY top | ||
| 6 | set_global_assignment -name VERILOG_INPUT_VERSION SYSTEMVERILOG_2005 | ||
| 7 | set_global_assignment -name VERILOG_MACRO "SYNTHESIS=1" | ||
| 8 | |||
| 9 | proc pin {net loc} { | ||
| 10 | set_location_assignment -to $net "PIN_$loc" | ||
| 11 | set_instance_assignment -name IO_STANDARD "3.3V LVTTL" -to $net | ||
| 12 | } | ||
| 13 | |||
| 14 | proc iopin {net loc} { | ||
| 15 | pin $net $loc | ||
| 16 | set_instance_assignment -name WEAK_PULL_UP_RESISTOR ON -to $net | ||
| 17 | } | ||
| 18 | |||
| 19 | proc rampin {net loc} { | ||
| 20 | set_location_assignment -to $net "PIN_$loc" | ||
| 21 | set_instance_assignment -name IO_STANDARD "1.8V" -to $net | ||
| 22 | } | ||
| 23 | |||
| 24 | pin clock E1 | ||
| 25 | |||
| 26 | iopin resetn J15 | ||
| 27 | |||
| 28 | iopin gpioa[1] L13 | ||
| 29 | iopin gpioa[2] L16 | ||
| 30 | iopin gpioa[3] L15 | ||
| 31 | iopin gpioa[4] K16 | ||
| 32 | iopin gpioa[5] P16 | ||
| 33 | iopin gpioa[6] R16 | ||
| 34 | iopin gpioa[7] N16 | ||
| 35 | iopin gpioa[8] N15 | ||
| 36 | iopin gpioa[9] N14 | ||
| 37 | iopin gpioa[10] P15 | ||
| 38 | iopin gpiob[13] N8 | ||
| 39 | iopin gpiob[14] P8 | ||
| 40 | iopin gpiob[15] M8 | ||
| 41 | iopin gpiob[16] L8 | ||
| 42 | iopin gpiob[17] R7 | ||
| 43 | iopin gpiob[18] T7 | ||
| 44 | iopin gpiob[19] L7 | ||
| 45 | iopin gpiob[20] M7 | ||
| 46 | iopin gpiob[21] R6 | ||
| 47 | iopin gpiob[22] T6 | ||
| 48 | iopin gpiob[23] T2 | ||
| 49 | iopin gpiob[24] M6 | ||
| 50 | iopin gpiob[25] R5 | ||
| 51 | iopin gpiob[26] T5 | ||
| 52 | iopin gpiob[27] N5 | ||
| 53 | iopin gpiob[28] N6 | ||
| 54 | iopin gpioc[31] R4 | ||
| 55 | iopin gpioc[32] T4 | ||
| 56 | iopin gpioc[33] N3 | ||
| 57 | iopin gpioc[34] P3 | ||
| 58 | iopin gpioc[35] R3 | ||
| 59 | iopin gpioc[36] T3 | ||
| 60 | iopin gpioc[37] P6 | ||
| 61 | iopin gpioc[38] P2 | ||
| 62 | iopin gpioc[39] P1 | ||
| 63 | iopin gpioc[40] R1 | ||
| 64 | |||
| 65 | rampin ramdata[0] T12 | ||
| 66 | rampin ramdata[1] T13 | ||
| 67 | rampin ramdata[2] T11 | ||
| 68 | rampin ramdata[3] R10 | ||
| 69 | rampin ramdata[4] T10 | ||
| 70 | rampin ramdata[5] R11 | ||
| 71 | rampin ramdata[6] R12 | ||
| 72 | rampin ramdata[7] R13 | ||
| 73 | rampin ramcsn[0] N12 | ||
| 74 | rampin ramcsn[1] P9 | ||
| 75 | rampin ramrwds T14 | ||
| 76 | rampin ramclkp P14 | ||
| 77 | rampin ramclkn R14 | ||
| 78 | rampin ramresetn N9 | ||
| 79 | |||
| 80 | # This is the clock for timing-driven synthesis, not timing analysis. | ||
| 81 | # See clocks.sdf for the other clock. | ||
| 82 | create_base_clock -fmax "50 MHz" clk | ||
| 83 | |||
| 84 | proc add_files {typ ext dir} { | ||
| 85 | foreach name [glob -nocomplain -directory $dir -type f "*.$ext"] { | ||
| 86 | set_global_assignment -name "${typ}_FILE" $name | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | proc add_dir {dir} { | ||
| 91 | add_files CDF cdf $dir | ||
| 92 | add_files HEX hex $dir | ||
| 93 | add_files SDC sdc $dir | ||
| 94 | add_files VERILOG sv $dir | ||
| 95 | add_files VERILOG svh $dir | ||
| 96 | |||
| 97 | foreach subdir [glob -nocomplain -directory $dir -type d *] { | ||
| 98 | add_dir $subdir | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | add_dir . | ||
| 103 | |||
| 104 | project_close | ||
