simulavr  1.1.0
hwuart.h
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003, 2004, 2005 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #ifndef HWUART
27 #define HWUART
28 
29 #include "avrdevice.h"
30 #include "irqsystem.h"
31 #include "hardware.h"
32 #include "pinatport.h"
33 #include "rwmem.h"
34 #include "traceval.h"
35 
37 
38 class HWUart: public Hardware, public TraceValueRegister {
39 
40  protected:
41  unsigned char udrWrite;
42  unsigned char udrRead;
43  unsigned char usr;
44  unsigned char ucr;
45  unsigned char ucsrc;
46  unsigned short ubrr;
47 
48  bool readParity;
49  bool writeParity;
50 
52 
54 
57 
58  unsigned int vectorRx;
59  unsigned int vectorUdre;
60  unsigned int vectorTx;
61 
62  unsigned char regSeq;
63 
64  int baudCnt;
65 
66  enum T_RxState {
75  } ;
76 
77  enum T_TxState{
87  } ;
88 
91 
92  unsigned int CpuCycleRx();
93  unsigned int CpuCycleTx();
94 
96  int rxLowCnt;
97  int rxHighCnt;
98  unsigned int rxDataTmp;
99  int rxBitCnt;
100 
102  unsigned char txDataTmp;
103  int txBitCnt;
104 
105  public:
107  HWUart(AvrDevice *core,
108  HWIrqSystem *,
109  PinAtPort tx,
110  PinAtPort rx,
111  unsigned int rx_interrupt,
112  unsigned int udre_interrupt,
113  unsigned int tx_interrupt,
114  int instance_id = 0);
115  virtual unsigned int CpuCycle();
116 
117  void Reset();
118 
119  void SetUdr(unsigned char val);
120  void SetUsr(unsigned char val);
121  void SetUcr(unsigned char val);
122  void SetUbrr(unsigned char val);
123  void SetUbrrhi(unsigned char val);
124 
125  unsigned char GetUdr();
126  unsigned char GetUsr();
127  unsigned char GetUcr();
128  unsigned char GetUbrr();
129  unsigned char GetUbrrhi();
130 
131  void ClearIrqFlag(unsigned int);
132  void CheckForNewSetIrq(unsigned char);
133  void CheckForNewClearIrq(unsigned char);
134 
137  usr_reg,
138  ucr_reg,
139  ucsra_reg,
140  ucsrb_reg,
141  ubrr_reg,
142  ubrrhi_reg;
143 
144  protected:
146 };
147 
149 class HWUsart: public HWUart {
150 
151  protected:
153 
154  public:
156  HWUsart(AvrDevice *core,
157  HWIrqSystem *,
158  PinAtPort tx,
159  PinAtPort rx,
160  PinAtPort xck,
161  unsigned int rx_interrupt,
162  unsigned int udre_interrupt,
163  unsigned int tx_interrupt,
164  int instance_id = 0,
165  bool mxReg = true);
166 
167  void SetUcsrc(unsigned char val);
168  void SetUcsrcUbrrh(unsigned char val);
169 
170  unsigned char GetUcsrc();
171  unsigned char GetUcsrcUbrrh();
172 
173  IOReg<HWUsart> ucsrc_reg,
174  ubrrh_reg,
176 };
177 
178 #endif
void Reset()
Definition: hwuart.cpp:606
T_RxState rxState
Definition: hwuart.h:89
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
unsigned char usr
USR register value, also used as UCSRA register value.
Definition: hwuart.h:43
int baudCnt
Definition: hwuart.h:64
HWIrqSystem * irqSystem
Connection to interrupt system.
Definition: hwuart.h:53
bool writeParity
The write parity flag for usart.
Definition: hwuart.h:49
unsigned int vectorRx
Interrupt vector ID for receive interrupt.
Definition: hwuart.h:58
void SetUdr(unsigned char val)
Definition: hwuart.cpp:62
unsigned int vectorUdre
Interrupt vector ID for UDR empty interrupt.
Definition: hwuart.h:59
unsigned int vectorTx
Interrupt vector ID for sent byte interrupt.
Definition: hwuart.h:60
IOReg< HWUart > ubrrhi_reg
IO register "UBRRxH" - baudrate.
Definition: hwuart.h:136
virtual unsigned int CpuCycle()
Definition: hwuart.cpp:170
int cntRxSamples
Definition: hwuart.h:95
bool readParity
The read parity flag for usart.
Definition: hwuart.h:48
int txBitCnt
Definition: hwuart.h:103
void SetUbrr(unsigned char val)
Definition: hwuart.cpp:92
T_TxState txState
Definition: hwuart.h:90
unsigned int rxDataTmp
Definition: hwuart.h:98
unsigned int CpuCycleTx()
Definition: hwuart.cpp:386
void SetUcr(unsigned char val)
Definition: hwuart.cpp:126
unsigned char GetUcr()
Definition: hwuart.cpp:582
PinAtPort pinXck
Clock pin for synchronous mode.
Definition: hwuart.h:152
IOReg< HWUart > ubrr_reg
IO register "UBRRxL" - baudrate.
Definition: hwuart.h:136
void SetUbrrhi(unsigned char val)
Definition: hwuart.cpp:96
unsigned char regSeq
Cycle timer for controling read access to UCSRC/UBRRH combined register.
Definition: hwuart.h:62
unsigned char udrWrite
Write stage of UDR register value.
Definition: hwuart.h:41
Implements the I/O hardware necessary to do USART transfers.
Definition: hwuart.h:149
IOReg< HWUart > ucr_reg
Definition: hwuart.h:136
unsigned char GetUbrr()
Definition: hwuart.cpp:583
IOReg< HWUart > ucsra_reg
Definition: hwuart.h:136
void SetFrameLengthFromRegister()
Definition: hwuart.cpp:100
Build a register for TraceValue&#39;s.
Definition: traceval.h:442
IOReg< HWUart > usr_reg
Definition: hwuart.h:136
IOReg< HWUart > ucsrb_reg
Definition: hwuart.h:136
void SetUsr(unsigned char val)
Definition: hwuart.cpp:73
unsigned char txDataTmp
Definition: hwuart.h:102
T_TxState
Definition: hwuart.h:77
HWUart(AvrDevice *core, HWIrqSystem *, PinAtPort tx, PinAtPort rx, unsigned int rx_interrupt, unsigned int udre_interrupt, unsigned int tx_interrupt, int instance_id=0)
Creates a instance of HWUart class.
Definition: hwuart.cpp:525
unsigned char GetUsr()
Definition: hwuart.cpp:581
int rxHighCnt
Definition: hwuart.h:97
void ClearIrqFlag(unsigned int)
Definition: hwuart.cpp:586
int baudCnt16
Definition: hwuart.h:101
IOReg< HWUsart > ucsrc_ubrrh_reg
Definition: hwuart.h:173
PinAtPort pinRx
RX pin.
Definition: hwuart.h:56
void CheckForNewClearIrq(unsigned char)
Definition: hwuart.cpp:600
unsigned char ucr
UCR register value, also used as UCSRB register value.
Definition: hwuart.h:44
T_RxState
Definition: hwuart.h:66
unsigned char GetUbrrhi()
Definition: hwuart.cpp:584
IOReg< HWUart > udr_reg
Definition: hwuart.h:136
int rxBitCnt
Definition: hwuart.h:99
int rxLowCnt
Definition: hwuart.h:96
int frameLength
Hold length of UART frame.
Definition: hwuart.h:51
PinAtPort pinTx
TX pin.
Definition: hwuart.h:55
Implements the I/O hardware necessary to do UART transfers.
Definition: hwuart.h:38
void CheckForNewSetIrq(unsigned char)
Definition: hwuart.cpp:594
unsigned char GetUdr()
Definition: hwuart.cpp:571
unsigned short ubrr
Baud rate register value (UBRR)
Definition: hwuart.h:46
unsigned char ucsrc
UCSRC register value.
Definition: hwuart.h:45
unsigned char udrRead
Read stage of UDR register value.
Definition: hwuart.h:42
unsigned int CpuCycleRx()
Definition: hwuart.cpp:185