avr: Fix documentation for Bus
[avr-sim.git] / src / Usart.h
blob7c57adfa3ab6e0e5ec0a68240104578a2eb2b2b4
1 #ifndef AVR_USART_H
2 #define AVR_USART_H
4 #include "Hardware.h"
5 #include <string>
7 namespace avr {
9 class Usart : public avr::Hardware {
10 public:
11 Usart(Bus & bus, const std::string & name, unsigned int udreVec,
12 unsigned int rxVec, unsigned int txVec);
13 ~Usart();
15 public:
16 /**
17 * Attach a register with name \e name to the hardware.
19 bool attachReg(const char *name, IORegister *reg);
21 /**
22 * Finishes the construction of the hardware.
23 * This should verify the registers and parameters
24 * @returns true if build was successful.
26 bool finishBuild();
28 /**
29 * An attached register changed state.
31 void regChanged( IORegister *reg );
33 /**
34 * Perform a single step.
36 void step();
38 /**
39 * Reset the internal hardware.
41 void reset();
43 /**
44 * Called just before an interrupt handler is invoked.
46 void beforeInvokeInterrupt(unsigned int vector);
48 private:
49 void receiveCycle();
50 void transmitCycle();
51 void checkForNewSetIrq(unsigned char val);
52 void checkForNewClearIrq(unsigned char val);
53 void setUdr(unsigned char udr);
54 void setUcsra(unsigned char ucsra);
55 void setUcsrb(unsigned char ucsrb);
56 void setFramelength();
58 private:
59 IORegister *udr;
60 IORegister *ucsra;
61 IORegister *ucsrb;
62 IORegister *ubrrl;
63 IORegister *ubrrh;
65 private:
66 std::string name;
67 unsigned int udreVec;
68 unsigned int rxVec;
69 unsigned int txVec;
71 unsigned char udrWrite;
72 unsigned char udrRead;
73 int baudRate;
74 int frameLength;
76 enum {
77 TX_STARTBIT,
78 TX_DATABIT,
79 TX_PARITY,
80 TX_STOPBIT,
81 TX_STOPBIT2,
82 TX_COMPLETE,
83 TX_FINISHED
84 } txState;
85 int txShift;
86 int txBitCount;
87 int txRate;
89 enum {
90 RX_STARTBIT,
91 RX_DATABIT,
92 RX_PARITY,
93 RX_STOPBIT,
94 RX_STOPBIT2,
95 RX_FINISHED
96 } rxState;
97 int rxShift;
98 int rxBitCount;
99 int rxSample;
101 unsigned char ucsra_old;
102 unsigned char ucsrb_old;
103 unsigned char ucsrc;
108 #endif /*AVR_USART_H*/