openMSX
AmdFlash.hh
Go to the documentation of this file.
1#ifndef AMDFLASH_HH
2#define AMDFLASH_HH
3
4#include "MemBuffer.hh"
5#include "serialize_meta.hh"
6#include <array>
7#include <cstddef>
8#include <cstdint>
9#include <memory>
10#include <span>
11
12namespace openmsx {
13
14class MSXMotherBoard;
15class Rom;
16class SRAM;
17class DeviceConfig;
18
20{
21public:
22 struct SectorInfo {
23 size_t size;
25 };
26 enum class Addressing {
27 BITS_11,
28 BITS_12,
29 };
30 enum class Load {
31 NORMAL,
32 DONT, // don't load nor save modified flash content
33 };
34
50 AmdFlash(const Rom& rom, std::span<const SectorInfo> sectorInfo,
51 uint16_t ID, Addressing addressing,
52 const DeviceConfig& config, Load load = Load::NORMAL);
53 AmdFlash(const std::string& name, std::span<const SectorInfo> sectorInfo,
54 uint16_t ID, Addressing addressing,
55 const DeviceConfig& config);
57
58 void reset();
65 void setVppWpPinLow(bool value) { vppWpPinLow = value; }
66
67 [[nodiscard]] size_t size() const { return sz; }
68 [[nodiscard]] uint8_t read(size_t address) const;
69 [[nodiscard]] uint8_t peek(size_t address) const;
70 void write(size_t address, uint8_t value);
71 [[nodiscard]] const uint8_t* getReadCacheLine(size_t address) const;
72
73 template<typename Archive>
74 void serialize(Archive& ar, unsigned version);
75
76//private:
77 struct AmdCmd {
78 size_t addr;
79 uint8_t value;
80
81 template<typename Archive>
82 void serialize(Archive& ar, unsigned version);
83 };
84
86
87private:
88 void init(const std::string& name, const DeviceConfig& config, Load load, const Rom* rom);
89 struct GetSectorInfoResult { size_t sector, sectorSize, offset; };
90 [[nodiscard]] GetSectorInfoResult getSectorInfo(size_t address) const;
91
92 void setState(State newState);
93 [[nodiscard]] bool checkCommandReset();
94 [[nodiscard]] bool checkCommandEraseSector();
95 [[nodiscard]] bool checkCommandEraseChip();
96 [[nodiscard]] bool checkCommandProgramHelper(size_t numBytes, std::span<const uint8_t> cmdSeq);
97 [[nodiscard]] bool checkCommandProgram();
98 [[nodiscard]] bool checkCommandDoubleByteProgram();
99 [[nodiscard]] bool checkCommandQuadrupleByteProgram();
100 [[nodiscard]] bool checkCommandManufacturer();
101 [[nodiscard]] bool partialMatch(std::span<const uint8_t> dataSeq) const;
102
103 [[nodiscard]] bool isSectorWritable(size_t sector) const;
104
105private:
106 MSXMotherBoard& motherBoard;
107 std::unique_ptr<SRAM> ram;
108 MemBuffer<ptrdiff_t> writeAddress;
109 MemBuffer<const uint8_t*> readAddress;
110 const std::span<const SectorInfo> sectorInfo;
111 const size_t sz;
112 const uint16_t ID;
113 const Addressing addressing;
114
115 static constexpr unsigned MAX_CMD_SIZE = 8;
116 std::array<AmdCmd, MAX_CMD_SIZE> cmd;
117 unsigned cmdIdx;
118 State state = ST_IDLE;
119 bool vppWpPinLow = false; // true = protection on
120};
122
123} // namespace openmsx
124
125#endif
void write(size_t address, uint8_t value)
Definition AmdFlash.cc:265
void serialize(Archive &ar, unsigned version)
Definition AmdFlash.cc:404
const uint8_t * getReadCacheLine(size_t address) const
Definition AmdFlash.cc:254
void setVppWpPinLow(bool value)
Setting the Vpp/WP# pin LOW enables a certain kind of write protection of some sectors.
Definition AmdFlash.hh:65
size_t size() const
Definition AmdFlash.hh:67
uint8_t peek(size_t address) const
Definition AmdFlash.cc:212
uint8_t read(size_t address) const
Definition AmdFlash.cc:248
This file implemented 3 utility functions:
Definition Autofire.cc:9
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)
void serialize(Archive &ar, unsigned version)
Definition AmdFlash.cc:397