Bug fix: check if vm exists
[avr-sim.git] / Timer8.h
blob505c4350fe8b26823e89537bd51162416de4eac6
1 #ifndef AVR_TIMER8_H
2 #define AVR_TIMER8_H
4 #include "Types.h"
5 #include "Hardware.h"
7 namespace avr {
9 class Timer8 : public Hardware {
10 public:
11 Timer8(Bus & bus, unsigned char tovmask, unsigned char ocfmask);
13 public:
14 bool attachReg(const char *name, IORegister *reg);
15 void regChanged( IORegister *reg );
16 void step();
18 private:
19 void setClock(unsigned char tccr);
20 void forceOutputCompare();
21 void compareMatchOutput(unsigned char tcnt);
23 private:
24 unsigned char tovmask;
25 unsigned char ocfmask;
26 int direction;
28 /* pg. 93 of manual. Block compareMatch for one period after
29 * TCNTn is written to. */
30 bool blockCompareMatch;
32 // For double buffering ocr register
33 unsigned char ocrBuf;
35 unsigned char timerMode;
36 unsigned char compareMode;
37 int period;
39 private:
40 IORegister *ocr;
41 IORegister *tcnt;
42 IORegister *tccr;
43 IORegister *tifr;
46 inline Timer8::Timer8(Bus & bus, unsigned char tovmask, unsigned char ocfmask)
47 : Hardware(bus), tovmask(tovmask), ocfmask(ocfmask), direction(1) {
48 blockCompareMatch = false;
49 timerMode = 0;
50 compareMode = 0;
51 period = 0;
56 #endif /*AVR_TIMER8_H*/