summaryrefslogtreecommitdiff
path: root/tb/jtag_uart.cpp
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2022-11-16 19:55:25 -0600
committerAlejandro Soto <alejandro@34project.org>2022-11-16 23:32:25 -0600
commitc64dee965fa00a4b7e3c3705da5e226ea56082ed (patch)
tree2c7371ac62b3b3870b61e411a4a71aa5c1eb281e /tb/jtag_uart.cpp
parent9805cd20d7106082d9a337a1104b4c857f91b514 (diff)
Implement JTAG-UART tx emulation
Diffstat (limited to 'tb/jtag_uart.cpp')
-rw-r--r--tb/jtag_uart.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tb/jtag_uart.cpp b/tb/jtag_uart.cpp
new file mode 100644
index 0000000..78d438e
--- /dev/null
+++ b/tb/jtag_uart.cpp
@@ -0,0 +1,55 @@
+#include "avalon.hpp"
+#include "jtag_uart.hpp"
+
+namespace taller::avalon
+{
+ jtag_uart::jtag_uart(std::uint32_t base) noexcept
+ : slave(base, 8, 4)
+ {}
+
+ bool jtag_uart::read(std::uint32_t addr, std::uint32_t &data) noexcept
+ {
+ switch(addr)
+ {
+ case 0:
+ data = 0; //TODO
+ break;
+
+ case 1:
+ data =
+ static_cast<std::uint32_t>(ctrl_re) << 0
+ | static_cast<std::uint32_t>(ctrl_we) << 1
+ //TODO: varios bits
+ | static_cast<std::uint32_t>(ctrl_ac) << 10
+ //TODO: disponibilidad de tx fifo
+ | static_cast<std::uint32_t>(255) << 10;
+
+ break;
+ }
+
+ return true;
+ }
+
+ bool jtag_uart::write(std::uint32_t addr, std::uint32_t data, unsigned byte_enable) noexcept
+ {
+ switch(addr)
+ {
+ case 0:
+ putchar(data & 0xff);
+ ctrl_ac = 1;
+ break;
+
+ case 1:
+ ctrl_re = !!(data & (1 << 0));
+ ctrl_we = !!(data & (1 << 1));
+ if(!!(data & (1 << 10)))
+ {
+ ctrl_ac = 0;
+ }
+
+ break;
+ }
+
+ return true;
+ }
+}