summaryrefslogtreecommitdiff
path: root/tb/mem.hpp
blob: 09435306a082b6c114aae4b1d19088520de7991e (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
37
#ifndef TALLER_MEM_HPP
#define TALLER_MEM_HPP

#include <cstdint>
#include <memory>

#include "avalon.hpp"

namespace taller::avalon
{
	template<typename Cell>
	class mem : public slave
	{
		public:
			mem(std::uint32_t base, std::uint32_t size);

			virtual bool read(std::uint32_t addr, std::uint32_t &data) final override;

			virtual bool write
			(
				std::uint32_t addr, std::uint32_t data, unsigned byte_enable = 0b1111
			) final override;

			template<typename F>
			void load(F loader, std::size_t offset = 0);

		private:
			std::unique_ptr<Cell[]> block;
			unsigned                count = 0;

			bool ready() noexcept;
	};
}

#include "mem.impl.hpp"

#endif