HWUart Class Reference

Implements the I/O hardware necessary to do UART transfers. More...

#include <hwuart.h>

Inheritance diagram for HWUart:
Inheritance graph
[legend]
Collaboration diagram for HWUart:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 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.
virtual unsigned int CpuCycle ()
void Reset ()
void SetUdr (unsigned char val)
void SetUsr (unsigned char val)
void SetUcr (unsigned char val)
void SetUbrr (unsigned char val)
void SetUbrrhi (unsigned char val)
unsigned char GetUdr ()
unsigned char GetUsr ()
unsigned char GetUcr ()
unsigned char GetUbrr ()
unsigned char GetUbrrhi ()
void ClearIrqFlag (unsigned int)
void CheckForNewSetIrq (unsigned char)
void CheckForNewClearIrq (unsigned char)

Public Attributes

IOReg< HWUartudr_reg
IOReg< HWUartusr_reg
IOReg< HWUartucr_reg
IOReg< HWUartucsra_reg
IOReg< HWUartucsrb_reg
IOReg< HWUartubrr_reg
 IO register "UBRRxL" - baudrate.
IOReg< HWUartubrrhi_reg
 IO register "UBRRxH" - baudrate.

Protected Types

enum  T_RxState {
  RX_DISABLED, RX_WAIT_FOR_HIGH, RX_WAIT_FOR_LOWEDGE, RX_READ_STARTBIT,
  RX_READ_DATABIT, RX_READ_PARITY, RX_READ_STOPBIT, RX_READ_STOPBIT2
}
enum  T_TxState {
  TX_DISABLED, TX_SEND_STARTBIT, TX_SEND_DATABIT, TX_SEND_PARITY,
  TX_SEND_STOPBIT, TX_SEND_STOPBIT2, TX_AFTER_STOPBIT, TX_FIRST_RUN,
  TX_FINISH
}

Protected Member Functions

unsigned int CpuCycleRx ()
unsigned int CpuCycleTx ()
void SetFrameLengthFromRegister ()

Protected Attributes

unsigned char udrWrite
 Write stage of UDR register value.
unsigned char udrRead
 Read stage of UDR register value.
unsigned char usr
 USR register value, also used as UCSRA register value.
unsigned char ucr
 UCR register value, also used as UCSRB register value.
unsigned char ucsrc
 UCSRC register value.
unsigned short ubrr
 Baud rate register value (UBRR).
bool readParity
 The read parity flag for usart.
bool writeParity
 The write parity flag for usart.
int frameLength
 Hold length of UART frame.
HWIrqSystemirqSystem
 Connection to interrupt system.
PinAtPort pinTx
 TX pin.
PinAtPort pinRx
 RX pin.
unsigned int vectorRx
 Interrupt vector ID for receive interrupt.
unsigned int vectorUdre
 Interrupt vector ID for UDR empty interrupt.
unsigned int vectorTx
 Interrupt vector ID for sent byte interrupt.
unsigned char regSeq
 Cycle timer for controling read access to UCSRC/UBRRH combined register.
int baudCnt
T_RxState rxState
T_TxState txState
int cntRxSamples
int rxLowCnt
int rxHighCnt
unsigned int rxDataTmp
int rxBitCnt
int baudCnt16
unsigned char txDataTmp
int txBitCnt

Detailed Description

Implements the I/O hardware necessary to do UART transfers.

Todo:
Needs rewrite! Only one async mode implemented!

Definition at line 38 of file hwuart.h.


Member Enumeration Documentation

enum HWUart::T_RxState [protected]
Enumerator:
RX_DISABLED 
RX_WAIT_FOR_HIGH 
RX_WAIT_FOR_LOWEDGE 
RX_READ_STARTBIT 
RX_READ_DATABIT 
RX_READ_PARITY 
RX_READ_STOPBIT 
RX_READ_STOPBIT2 

Definition at line 66 of file hwuart.h.

enum HWUart::T_TxState [protected]
Enumerator:
TX_DISABLED 
TX_SEND_STARTBIT 
TX_SEND_DATABIT 
TX_SEND_PARITY 
TX_SEND_STOPBIT 
TX_SEND_STOPBIT2 
TX_AFTER_STOPBIT 
TX_FIRST_RUN 
TX_FINISH 

Definition at line 77 of file hwuart.h.


Constructor & Destructor Documentation

HWUart::HWUart ( AvrDevice core,
HWIrqSystem s,
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 at line 524 of file hwuart.cpp.

References AvrDevice::AddToCycleList(), HWIrqSystem::DebugVerifyInterruptVector(), irqSystem, Reset(), trace_direct(), ubrr, ucr, udrRead, udrWrite, usr, vectorRx, vectorTx, and vectorUdre.

Here is the call graph for this function:


Member Function Documentation

void HWUart::CheckForNewClearIrq ( unsigned char  val  ) 

Definition at line 599 of file hwuart.cpp.

References HWIrqSystem::ClearIrqFlag(), irqSystem, RXC, TXC, UDRE, vectorRx, vectorTx, and vectorUdre.

Referenced by CpuCycleRx(), CpuCycleTx(), SetUcr(), and SetUsr().

Here is the call graph for this function:

Here is the caller graph for this function:

void HWUart::CheckForNewSetIrq ( unsigned char  val  ) 

Definition at line 593 of file hwuart.cpp.

References irqSystem, RXC, HWIrqSystem::SetIrqFlag(), TXC, UDRE, vectorRx, vectorTx, and vectorUdre.

Referenced by CpuCycleRx(), CpuCycleTx(), SetUcr(), and SetUsr().

Here is the call graph for this function:

Here is the caller graph for this function:

void HWUart::ClearIrqFlag ( unsigned int  vector  )  [virtual]

This signals the hardware that the given IRQ vector has been handled by the AVR core.

Reimplemented from Hardware.

Definition at line 585 of file hwuart.cpp.

References HWIrqSystem::ClearIrqFlag(), irqSystem, TXC, usr, and vectorTx.

Here is the call graph for this function:

unsigned int HWUart::CpuCycle ( void   )  [virtual]

Called for each AVR cycle when this hardware has registered itself as a receiver for AVR clocks. Returns nonzero if instructions should not be executed (e.g. a Flash write is in progress).

Reimplemented from Hardware.

Definition at line 170 of file hwuart.cpp.

References baudCnt, CpuCycleRx(), CpuCycleTx(), regSeq, and ubrr.

Here is the call graph for this function:

unsigned int HWUart::CpuCycleRx (  )  [protected]

Definition at line 185 of file hwuart.cpp.

References CheckForNewClearIrq(), CheckForNewSetIrq(), CHR9, cntRxSamples, FE, frameLength, OR, pinRx, readParity, RX_DISABLED, RX_READ_DATABIT, RX_READ_PARITY, RX_READ_STARTBIT, RX_READ_STOPBIT, RX_READ_STOPBIT2, RX_WAIT_FOR_HIGH, RX_WAIT_FOR_LOWEDGE, RXB8, rxBitCnt, RXC, rxDataTmp, RXEN, rxHighCnt, rxLowCnt, rxState, ucr, ucsrc, udrRead, UPE, UPM0, UPM1, USBS, and usr.

Referenced by CpuCycle().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int HWUart::CpuCycleTx (  )  [protected]
unsigned char HWUart::GetUbrr (  ) 

Definition at line 582 of file hwuart.cpp.

References ubrr.

unsigned char HWUart::GetUbrrhi (  ) 

Definition at line 583 of file hwuart.cpp.

References ubrr.

Referenced by HWUsart::GetUcsrcUbrrh().

Here is the caller graph for this function:

unsigned char HWUart::GetUcr (  ) 

Definition at line 581 of file hwuart.cpp.

References ucr.

unsigned char HWUart::GetUdr (  ) 

Definition at line 570 of file hwuart.cpp.

References HWIrqSystem::ClearIrqFlag(), irqSystem, RXC, ucr, udrRead, usr, and vectorRx.

Here is the call graph for this function:

unsigned char HWUart::GetUsr (  ) 

Definition at line 580 of file hwuart.cpp.

References usr.

void HWUart::Reset ( void   )  [virtual]

Implement the hardware's reset functionality here. The default is no action on reset.

Reimplemented from Hardware.

Definition at line 605 of file hwuart.cpp.

References baudCnt, baudCnt16, regSeq, RX_WAIT_FOR_LOWEDGE, rxState, SetFrameLengthFromRegister(), TX_FIRST_RUN, txState, ubrr, ucr, ucsrc, UCSZ0, UCSZ1, UDRE, udrRead, udrWrite, and usr.

Referenced by HWUart(), and HWUsart::HWUsart().

Here is the call graph for this function:

Here is the caller graph for this function:

void HWUart::SetFrameLengthFromRegister (  )  [protected]

Definition at line 100 of file hwuart.cpp.

References frameLength, ucr, ucsrc, UCSZ0, UCSZ1, and UCSZ2.

Referenced by Reset(), SetUcr(), and HWUsart::SetUcsrc().

Here is the caller graph for this function:

void HWUart::SetUbrr ( unsigned char  val  ) 

Definition at line 92 of file hwuart.cpp.

References ubrr.

void HWUart::SetUbrrhi ( unsigned char  val  ) 

Definition at line 96 of file hwuart.cpp.

References ubrr.

Referenced by HWUsart::SetUcsrcUbrrh().

Here is the caller graph for this function:

void HWUart::SetUcr ( unsigned char  val  ) 
void HWUart::SetUdr ( unsigned char  val  ) 

Definition at line 62 of file hwuart.cpp.

References HWIrqSystem::ClearIrqFlag(), irqSystem, ucr, UDRE, UDRIE, udrWrite, usr, and vectorUdre.

Here is the call graph for this function:

void HWUart::SetUsr ( unsigned char  val  ) 

Definition at line 73 of file hwuart.cpp.

References CheckForNewClearIrq(), CheckForNewSetIrq(), TXC, ucr, and usr.

Here is the call graph for this function:


Member Data Documentation

int HWUart::baudCnt [protected]

Definition at line 64 of file hwuart.h.

Referenced by CpuCycle(), and Reset().

int HWUart::baudCnt16 [protected]

Definition at line 101 of file hwuart.h.

Referenced by CpuCycleTx(), and Reset().

int HWUart::cntRxSamples [protected]

Definition at line 95 of file hwuart.h.

Referenced by CpuCycleRx().

int HWUart::frameLength [protected]

Hold length of UART frame.

Definition at line 51 of file hwuart.h.

Referenced by CpuCycleRx(), CpuCycleTx(), and SetFrameLengthFromRegister().

Connection to interrupt system.

Definition at line 53 of file hwuart.h.

Referenced by CheckForNewClearIrq(), CheckForNewSetIrq(), ClearIrqFlag(), GetUdr(), HWUart(), and SetUdr().

PinAtPort HWUart::pinRx [protected]

RX pin.

Definition at line 56 of file hwuart.h.

Referenced by CpuCycleRx(), and SetUcr().

PinAtPort HWUart::pinTx [protected]

TX pin.

Definition at line 55 of file hwuart.h.

Referenced by CpuCycleTx(), and SetUcr().

bool HWUart::readParity [protected]

The read parity flag for usart.

Definition at line 48 of file hwuart.h.

Referenced by CpuCycleRx().

unsigned char HWUart::regSeq [protected]

Cycle timer for controling read access to UCSRC/UBRRH combined register.

Definition at line 62 of file hwuart.h.

Referenced by CpuCycle(), HWUsart::GetUcsrcUbrrh(), and Reset().

int HWUart::rxBitCnt [protected]

Definition at line 99 of file hwuart.h.

Referenced by CpuCycleRx().

unsigned int HWUart::rxDataTmp [protected]

Definition at line 98 of file hwuart.h.

Referenced by CpuCycleRx().

int HWUart::rxHighCnt [protected]

Definition at line 97 of file hwuart.h.

Referenced by CpuCycleRx().

int HWUart::rxLowCnt [protected]

Definition at line 96 of file hwuart.h.

Referenced by CpuCycleRx().

Definition at line 89 of file hwuart.h.

Referenced by CpuCycleRx(), and Reset().

int HWUart::txBitCnt [protected]

Definition at line 103 of file hwuart.h.

Referenced by CpuCycleTx().

unsigned char HWUart::txDataTmp [protected]

Definition at line 102 of file hwuart.h.

Referenced by CpuCycleTx().

Definition at line 90 of file hwuart.h.

Referenced by CpuCycleTx(), Reset(), and SetUcr().

unsigned short HWUart::ubrr [protected]

Baud rate register value (UBRR).

Definition at line 46 of file hwuart.h.

Referenced by CpuCycle(), GetUbrr(), GetUbrrhi(), HWUart(), Reset(), SetUbrr(), and SetUbrrhi().

unsigned char HWUart::ucr [protected]

UCR register value, also used as UCSRB register value.

Definition at line 44 of file hwuart.h.

Referenced by CpuCycleRx(), CpuCycleTx(), GetUcr(), GetUdr(), HWUart(), Reset(), SetFrameLengthFromRegister(), SetUcr(), SetUdr(), and SetUsr().

unsigned char HWUart::ucsrc [protected]

UCSRC register value.

Definition at line 45 of file hwuart.h.

Referenced by CpuCycleRx(), CpuCycleTx(), HWUsart::GetUcsrc(), Reset(), SetFrameLengthFromRegister(), and HWUsart::SetUcsrc().

unsigned char HWUart::udrRead [protected]

Read stage of UDR register value.

Definition at line 42 of file hwuart.h.

Referenced by CpuCycleRx(), GetUdr(), HWUart(), and Reset().

unsigned char HWUart::udrWrite [protected]

Write stage of UDR register value.

Definition at line 41 of file hwuart.h.

Referenced by CpuCycleTx(), HWUart(), Reset(), and SetUdr().

unsigned char HWUart::usr [protected]

USR register value, also used as UCSRA register value.

Definition at line 43 of file hwuart.h.

Referenced by ClearIrqFlag(), CpuCycleRx(), CpuCycleTx(), GetUdr(), GetUsr(), HWUart(), Reset(), SetUcr(), SetUdr(), and SetUsr().

unsigned int HWUart::vectorRx [protected]

Interrupt vector ID for receive interrupt.

Definition at line 58 of file hwuart.h.

Referenced by CheckForNewClearIrq(), CheckForNewSetIrq(), GetUdr(), and HWUart().

unsigned int HWUart::vectorTx [protected]

Interrupt vector ID for sent byte interrupt.

Definition at line 60 of file hwuart.h.

Referenced by CheckForNewClearIrq(), CheckForNewSetIrq(), ClearIrqFlag(), and HWUart().

unsigned int HWUart::vectorUdre [protected]

Interrupt vector ID for UDR empty interrupt.

Definition at line 59 of file hwuart.h.

Referenced by CheckForNewClearIrq(), CheckForNewSetIrq(), HWUart(), and SetUdr().

bool HWUart::writeParity [protected]

The write parity flag for usart.

Definition at line 49 of file hwuart.h.

Referenced by CpuCycleTx().


The documentation for this class was generated from the following files:
Generated on Sun Feb 12 16:52:32 2012 for Simulavr by  doxygen 1.6.3