Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Device.h
blob831e5a33f733f7e0d34392b35a6e099993d51fc4
1 #ifndef DEVICE_H_
2 #define DEVICE_H_
4 #include "SimulationObject.h"
5 #include "Bus.h"
7 #include <vector>
8 #include <map>
10 namespace avr {
11 typedef unsigned long long ClockFrequency;
13 class Pin;
14 class ERam;
15 class Core;
16 class Hardware;
17 class Eeprom;
18 class DebugInterface;
20 class Analyzer;
21 class ScriptEngine;
22 class Program;
23 class HardwareSettings;
24 class DeviceSettings;
26 /**
27 * @author Tom Haber
28 * @date Apr 21, 2008
29 * @brief A facade to the complete Atmel AVR chip.
31 * This class represents a complete Atmel AVR chip and
32 * forms a facade for the outside "world".
33 * The class contains some useful construction methods
34 * used by the DeviceSettings class.
36 class Device : public sim::SimulationObject {
37 public:
38 Device(sim::SimulationClock & clock,
39 const char *devicename = 0,
40 bool allowStopping = true);
41 ~Device();
43 public:
44 /**
45 * Loads the useful sections from the program file
46 * into eeprom, sram and flash.
48 void load(Program & program);
50 /**
51 * Instantiates and adds an analyzer to the core.
53 void addAnalyzer(const char *name);
55 /**
56 * Adds an analyzer to the core.
58 void addAnalyzer(Analyzer *analyzer);
60 /**
61 * Adds a trace analyzer to the core
62 * which outputs to the specified file.
64 void trace(const char *tracefile);
66 /**
67 * Performs a single cpu cycle.
69 void step();
71 /**
72 * Change the clock frequency of the device.
74 void setClockFrequency(ClockFrequency frq);
76 /**
77 * Reset the chip.
79 void reset(unsigned int type);
81 Pin *getPin(unsigned int id) const;
82 Pin *getPin(const std::string & name) const;
84 public:
85 /**
86 * Returns an interface for debugging, this interface
87 * has access to some protected parts of the core.
89 DebugInterface *debugInterface();
91 private:
92 // Construction methods for DeviceSettings
93 void buildCore(unsigned int ioSpaceSize, unsigned int ramSize,
94 unsigned int flashSize, unsigned int pageSize,
95 unsigned int stackMask, int pcBytes = 2,
96 ERam *eram = 0);
97 void buildHardware(const char *hwname, HardwareSettings & hws);
98 void addIOReg(unsigned int address, const std::string & name,
99 unsigned char initial = 0);
100 void addInterrupt(unsigned int vector, unsigned int address,
101 const char *name);
102 void addPin(unsigned int id, const char *name, unsigned int num);
104 private:
105 static const ClockFrequency defaultFrequency = 8000000;
106 sim::ClockOffset frq;
107 Core *core;
108 bool allowStopping;
110 Bus bus;
111 Eeprom *eeprom;
113 std::vector<Pin *> pins;
114 std::map<std::string, Pin *> name2pin;
116 friend class DeviceSettings;
119 inline Pin *Device::getPin(unsigned int id) const {
120 if( id >= pins.size() )
121 return 0;
122 return pins[ id - 1 ];
126 #endif /*DEVICE_H_*/