Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Hardware.h
blob7be89f32725d72ac83727c5e0d9b0848cf53c0c1
1 #ifndef AVR_HARDWARE_H
2 #define AVR_HARDWARE_H
4 namespace avr {
6 class Bus;
7 class IORegister;
9 /**
10 * @author Tom Haber
11 * @date Apr 26, 2008
12 * @brief Abstraction of all internal devices
14 * This is an abstraction of all the internal devices inside
15 * an AVR chip. These encompass timers, usart, spi, etc
17 * Hardware can negotiate its timing with the Bus,
18 * \e step is called based on this timing.
20 class Hardware {
21 public:
22 Hardware(Bus & bus) : bus(bus), holdCycles(0) {}
23 virtual ~Hardware() {}
25 public:
26 /**
27 * Attach a register with name \e name to the hardware.
29 virtual bool attachReg(const char *name, IORegister *reg) = 0;
31 /**
32 * Finishes the construction of the hardware.
33 * This should verify the registers and parameters
34 * @returns true if build was successful.
36 virtual bool finishBuild() { return true; }
38 /**
39 * An attached register changed state.
41 virtual void regChanged( IORegister *reg ) = 0;
43 /**
44 * An attached register is accessed.
46 virtual void regAccess( IORegister * /*reg*/ ) {}
48 /**
49 * Perform a single step.
51 virtual void step() {}
53 /**
54 * Reset the internal hardware.
56 virtual void reset() {}
58 /**
59 * Called just before an interrupt handler is invoked.
61 virtual void beforeInvokeInterrupt(unsigned int /*vector*/) {}
63 public:
64 /**
65 * Are we holding the CPU?
66 * @warning only call this once per CPU cycle.
68 bool isHoldingCPU();
70 protected:
71 /**
72 * Set the number of cycles to hold the CPU.
74 void setHoldCycles(unsigned int cycles);
76 protected:
77 Bus & bus;
78 unsigned int holdCycles;
81 inline void Hardware::setHoldCycles(unsigned int cycles) {
82 holdCycles = cycles;
85 inline bool Hardware::isHoldingCPU() {
86 if( holdCycles != 0 )
87 holdCycles--;
89 return (holdCycles != 0);
94 #endif /*AVR_HARDWARE_H*/