summaryrefslogtreecommitdiff
path: root/tb/jtag_uart.hpp
blob: 3c378c3144628e6f7d0338478e06e2e90064b027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef TALLER_JTAG_UART_HPP
#define TALLER_JTAG_UART_HPP

#include <cstdint>

#include "avalon.hpp"

namespace taller::avalon
{
	class jtag_uart : public slave
	{
		public:
			jtag_uart(std::uint32_t base) noexcept;
			~jtag_uart() noexcept;

			void tick() noexcept;

			virtual bool read(std::uint32_t addr, std::uint32_t &data) noexcept final override;
			virtual bool write(std::uint32_t addr, std::uint32_t data, unsigned byte_enable) noexcept final override;

			void takeover() noexcept;
			void release() noexcept;

		private:
			unsigned     countdown = 0;
			unsigned     rx_avail  = 0;
			unsigned     rx_next   = 0;
			bool         ctrl_re   = false;
			bool         ctrl_we   = false;
			bool         ctrl_ac   = true;
			bool         took_over = false;
			std::uint8_t rx[64];
	};
}

#endif