Commit Graph

169 Commits

Author SHA1 Message Date
Byron Lathi
3a59de2947 Change data count to have proper width (9)
This was probably an off-by-one mistage, with the width set to 10
instead of 9. The width should be 9 since the buffer is 512 bytes.
2022-04-14 11:19:08 -05:00
Byron Lathi
c9269b2fb8 Fix some warnings
Adds some missing cases, length specifiers.
2022-04-11 16:13:38 -05:00
Byron Lathi
68a422d5e3 Disable signal tap 2022-04-11 16:03:50 -05:00
Byron Lathi
87d1457d94 Add logic to store and readback data from SD card
After a data read (e.g. CMD17) the data received from the SD card is
stored into a buffer which can be read back one byte at a time by the
CPU through address 5.

There is also a flag which is set when data is received. This can be
checked by reading the CMD register, which doubles as the status
register.
2022-04-11 13:57:56 -05:00
Byron Lathi
51c348bc7c Increase sd card addr width by 1
Adds a new memory location for data accesses.
2022-04-11 13:57:07 -05:00
Byron Lathi
f5f1d7ccc6 Add read flag to sd controller
Read flag is set when the sd controller reads response data in from the
sd card. When the cpu reads from the controller, the flag is reset.

This flag does not trigger an interrupt, it mmust be polled.
2022-04-10 23:16:10 -05:00
Byron Lathi
cd11670fb1 Add sd controller to top level
Also adds the logic required for the bidirectional sd lines and attaches
the controller to the cpu.
2022-04-10 17:54:08 -05:00
Byron Lathi
1128b986eb Fix state transitions with regard to clock
The SD card expects data to transition on falling edges and be stable on
rising edges.

Additionally, writes from the CPU were not handled with correct timing.

Now, there is an extra state when writing to the command register so
that the command is properly latched before the CRC is calculated.
2022-04-10 17:52:07 -05:00
Byron Lathi
50b0860137 Update testbench with more realistic timings
Updates the testbench to simulate writes with more correct timings.
Writes take two clock cycles since the cpu runs at half speed.
2022-04-10 17:50:49 -05:00
Byron Lathi
09428c8875 Add sd card cs 2022-04-10 16:15:55 -05:00
Byron Lathi
31a4656cac Reduce sd_controller addr width from 4 to 3 2022-04-09 17:31:25 -05:00
Byron Lathi
38566f7b4a add testbench for SD command tx
Sends a few commands which we know the proper checksum for and makes
sure that the bits on the output are correct.
2022-04-08 12:29:15 -05:00
Byron Lathi
f89ecfa038 Add SD Card controller for sending commands
Adds the start of the SD card controller which is capable of sending
commands using the SD protocol.

It is accessed by writing the arguments first and triggered by writing
the command number.
2022-04-08 12:28:17 -05:00
Byron Lathi
552fe8b6f8 Have valid crc when valid signal is present
Previously the crc would be reset after 1 clock cycle while the valid
signal was still high. Now the data is preserved in the valid state
until the load signal is asserted.
2022-04-08 12:25:17 -05:00
Byron Lathi
3e69109474 Add tests for crc7
These are just some values that I found from an example program. This
does not test every possible value.
2022-04-08 00:56:14 -05:00
Byron Lathi
e828df0807 Add crc7 module
This module takes in a 40 bit word and generates the 7 bit crc7
appropriate for an SD card.

It does not use any fancy parallel algorithm, it does it 1 bit at a
time.
2022-04-08 00:50:28 -05:00
Byron Lathi
f276c5469e Fix indentation 2022-04-08 00:49:59 -05:00
Byron Lathi
2f79a00000 Decode physical addresses instead of virtual.
address decoding is now performed on the translated address which comes
from the memory mapper, instead of the address coming directly from the
cpu.

This means that you can access the full amount of ram at any address
that it is mapped to.
2022-04-07 12:32:51 -05:00
Byron Lathi
5548f9d02a Update mm_testbench 2022-04-07 10:48:10 -05:00
Byron Lathi
7434621209 Update cs_testbench.sv 2022-04-07 10:40:11 -05:00
Byron Lathi
be497ecaa9 Add reset input to memory mapper
Upon reset the memory mapper is automatically disabled, but the mappings
are not cleared.
2022-04-07 10:35:16 -05:00
Byron Lathi
a15dde0e89 Add memory mapper software interface
Adds functions to read and write mappings, as well as enable and disable
the memory mapper.

This also moves increases the io space by 16 bytes.
2022-04-07 10:33:50 -05:00
Byron Lathi
d9474df523 Update cs_testbench.sv 2022-04-05 17:27:28 -05:00
Byron Lathi
2600a23e59 Add memory_mapper testbench
This testbench simply creates the memory mapper, adds a mapping to the
first entry, and then makes sure the addresses are correct after
enabling and disabling the memory mapper.
2022-04-05 17:20:23 -05:00
Byron Lathi
194c4b456f Add memory mapper.
Based on the 74ls610 but with some slight changes.

The memory mapper works by having a 16x12 ram array. The top 4 bits of
the address are used to index into this array, and the resulting word
replaces those top 4 bits. In this way, a 16 bit address is replaced
with a 24 bit address.

As of now there is no way to write 12 bit values though, so currently
we are using 20 bit addresses.

There is a chip select line that allows you to write into the ram array,
and another chip select that allows you to write to the control word.
Currently the control word is just a single bit, the enable bit.

When not enabled, the 4 index bits are passed straight through, and the higher
bits of the address are replaced with 0, a sort of identity map. Once
enabled, it operates as described above.

Since the bottom 12 bits are left unchanged, the page size is 4kb.

There are no protections so far, but might be added later, as well as
the ability to actually use all 12 bits.
2022-04-05 17:10:42 -05:00
Byron Lathi
e7defb717a Add board_io.sv to project 2022-03-21 14:20:07 -05:00
Byron Lathi
74210f57f7 Remove fpga RAM
This removes the ram from inside the FPGA. All RAM is now located in the
external SDRAM instead.

The ROM is still in the FPGA to allow easier programming.
2022-03-21 14:01:16 -05:00
Byron Lathi
5c32fe808e Add board-io, replace sevenseg in sw 2022-03-18 01:27:55 +00:00
Byron Lathi
42a718408d Move SDRAM and state machine into its own file
Cleans up the top level module a bit
2022-03-17 17:49:20 -05:00
Byron Lathi
7cb3183f85 Add sdram to address decode test 2022-03-17 17:12:43 -05:00
Byron Lathi
2d49fe22a7 ignore .sopcinfo
This will be generated automatically when built.
2022-03-17 13:53:07 -05:00
Byron Lathi
15e3ae9688 Add SDRAM controller (controller)
Turns out there are some issues with holding the chip select for the
SDRAM controller high for too long, so there is a simple 2-state fsm
which ensures that the chip select is only held for 1 clock cycle for
writes and for as long as it takes to read the data from sdram for
reads.
2022-03-17 13:31:56 -05:00
Byron Lathi
aa337c61d5 Create sdram platform 2022-03-15 23:45:57 -05:00
Byron Lathi
a627d38778 Ignore all output files 2022-03-14 16:58:44 -05:00
Byron Lathi
59d2d4f601 Add receive logic to UART
The UART has a receive buffer which will fill up when it receives bytes.
Once the buffer is full, it raises the RX flag until the value is read
by the cpu.
2022-03-14 16:41:59 -05:00
Byron Lathi
ed18b381f3 Change "clkdiv" to "tx_clkdiv" 2022-03-14 15:22:18 -05:00
Byron Lathi
264263b0d9 Change "state" to "tx_state" etc. 2022-03-14 15:10:59 -05:00
Byron Lathi
b2344d986e Add UART interrupts
Currently an interrupt is triggered any time there is any activity on
the UART_RXD line, but later it will only trigger once there is data
ready to be read.
2022-03-14 14:57:45 -05:00
Byron Lathi
e70fffb472 Add irq status register
Upon receiving an interrupt, the corresponding bit in the interrupt
status register will be set and an IRQ will be raised for the CPU. The
cpu can then respond to the interrupt and clear the interrupt by writing
back to the interrupt status register.
2022-03-14 13:16:09 -05:00
Byron Lathi
26070313f4 Ignore greybox_tmp 2022-03-14 13:15:20 -05:00
Byron Lathi
ff78fd0179 Connect Button 1 to cpu_irqb
A maskable interrupt can be generated by pressing button 1, the reset
button remains button 0.
2022-03-14 11:53:45 -05:00
Byron Lathi
4fb73f8e97 Update cs_testbench.sv
Add uart_cs and fix error messages
2022-03-14 10:56:15 -05:00
Byron Lathi
cfcf94a875 Integrate uart controller into top level module
Adds new chip select for the UART, and a new entry in the data_out mux
for the UART.
2022-03-14 10:45:45 -05:00
Byron Lathi
b48438f6b2 Add write and puts tasks to the uart testbench
The write task will transmit a single byte, the puts task will transmit
a string of length n. These do not do any verification, you still have
to look at the output.
2022-03-14 00:04:04 -05:00
Byron Lathi
f8da9206d9 Refactor uart.sv to better allow cpu control
Added new signal tx_flag, which indicates whether the transmitter is
ready for new data.

Added status register, which when read will return the tx_flag bit, as
well as others that can be implemented.

Added new state IDLE, which resets the TX flag and allows new data to be
written.

Added code to allow for different baud rates, though it is still fixed
currently.
2022-03-14 00:00:55 -05:00
Byron Lathi
e063e9f6a3 Add basic UART device
So far the device only transmits the ASCII set on repeat, but will
become fully featured later.
2022-03-13 19:42:41 -05:00
Byron Lathi
5834f179d2 Ignore more modelsim files
Ignore all bak files and msim_transcript
2022-03-13 19:39:14 -05:00
Byron Lathi
c7e8cc3798 Implement enable byte in hw 2022-03-12 21:45:30 -06:00
Byron Lathi
627b6a746a Add high pair of seven segment displays
This also increases the number of registers to 4, one more for the high
pair of displays, and a final one for a mask register which has not been
implemented yet.
2022-03-12 21:24:37 -06:00
Byron Lathi
79675ec773 Clean up modelsim folder 2022-03-12 19:41:08 -06:00