22 * @brief The core of the AVR chip.
24 * This is the interpreter of the instructions and it contains the state.
28 Core(Bus
& bus
, unsigned int ioSpaceSize
, unsigned int ramSize
,
29 unsigned int flashSize
, unsigned int pageSize
,
30 word stackMask
, int pcBytes
= 2, ERam
*eram
= 0);
35 void loadFlash(unsigned char *data
, unsigned int offset
, unsigned int size
);
40 void reset(unsigned int type
);
43 * Executes a single cpu cycle.
47 void setDebugInterface(DebugInterface
*dbgi
);
48 bool isStopped() const { return stoppedMode
; }
51 void addIOReg(unsigned int address
,
52 const std::string
& name
, byte initial
= 0);
53 void addAnalyzer(Analyzer
*analyzer
);
54 const Register
& getR(int r
) const { return mmu
.getR(r
); }
55 IORegister
& getIoreg(unsigned int offset
);
56 IORegister
*getIoreg(const std::string
& name
);
59 byte
readRegister(unsigned int r
) const;
60 void writeRegister(unsigned int r
, byte val
);
62 void writeStatus(byte val
);
63 byte
readIORegister(unsigned int r
);
64 void writeIORegister(unsigned int r
, byte val
);
65 byte
readByte(unsigned int addr
) const;
66 void writeByte(unsigned int addr
, byte val
);
67 byte
readFlash(unsigned int addr
) const;
68 int writeFlash(unsigned int addr
, word data
);
72 int pcBytes() const { return pc_bytes
; }
75 void jump(sbyte offset
, bool push
= false);
77 void call(dword address
, bool push
= true);
78 void ret(bool interrupt
= false);
83 bool invokeInterrupt();
98 bool justReturnedFromInterrupt
;
102 SLEEP_MODE_ADC_REDUX
= 1,
103 SLEEP_MODE_PWR_DOWN
= 2,
104 SLEEP_MODE_PWR_SAVE
= 3,
105 SLEEP_MODE_reserved1
= 4,
106 SLEEP_MODE_reserved2
= 5,
107 SLEEP_MODE_STANDBY
= 6,
108 SLEEP_MODE_EXT_STANDBY
= 7,
113 std::list
<Analyzer
*> analyzers
;
116 DebugInterface
*dbgi
;
119 friend class DebugInterface
;
122 inline void Core::loadFlash(unsigned char *data
, unsigned int offset
, unsigned int size
) {
123 flash
.write(offset
, data
, size
);
126 inline void Core::addAnalyzer(Analyzer
*analyzer
) {
127 analyzers
.push_back( analyzer
);
130 inline void Core::setDebugInterface(DebugInterface
*dbgi
) {
134 inline void Core::addIOReg(unsigned int address
,
135 const std::string
& name
, byte initial
) {
136 mmu
.addIOReg(address
, name
, initial
);
139 inline IORegister
& Core::getIoreg(unsigned int offset
) {
140 return mmu
.getIoreg(offset
);
143 inline IORegister
*Core::getIoreg(const std::string
& name
) {
144 return mmu
.getIoreg(name
);
147 inline byte
Core::readStatus() {
148 return readIORegister(SReg
);
151 inline void Core::writeStatus(byte val
) {
152 writeIORegister(SReg
, val
);
157 #endif /*AVR_CORE_H*/