simulavr  1.1.0
HWUart Class Reference

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

#include <hwuart.h>

Inheritance diagram for HWUart:

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. More...
 
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 Member Functions inherited from Hardware
 Hardware (AvrDevice *core)
 
virtual ~Hardware ()
 
virtual bool IsLevelInterrupt (unsigned int vector)
 
virtual bool LevelInterruptPending (unsigned int vector)
 
- Public Member Functions inherited from TraceValueRegister
 TraceValueRegister (TraceValueRegister *parent, const std::string &name)
 Create a TraceValueRegister, with a scope prefix built on parent scope + name. More...
 
 TraceValueRegister ()
 Create a TraceValueRegister, with a empty scope name, single device application. More...
 
virtual ~TraceValueRegister ()
 
const std::string GetTraceValuePrefix (void)
 Returns the scope prefix. More...
 
const std::string GetScopeName (void)
 Returns the scope name. More...
 
void RegisterTraceValue (TraceValue *t)
 Registers a TraceValue for this register. More...
 
void UnregisterTraceValue (TraceValue *t)
 Unregisters a TraceValue, remove it from register. More...
 
TraceValueRegisterGetScopeGroupByName (const std::string &name)
 Get a here registered TraceValueRegister by it's name. More...
 
virtual TraceValueGetTraceValueByName (const std::string &name)
 Get a here registered TraceValue by it's name. More...
 
TraceValueRegisterFindScopeGroupByName (const std::string &name)
 Seek for a TraceValueRegister by it's name. More...
 
TraceValueFindTraceValueByName (const std::string &name)
 Seek for a TraceValue by it's name. More...
 
TraceSetGetAllTraceValues (void)
 Get all here registered TraceValue's only (not with descending values) More...
 
TraceSetGetAllTraceValuesRecursive (void)
 Get all here registered TraceValue's with descending values. More...
 

Public Attributes

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

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 Member Functions inherited from TraceValueRegister
virtual size_t _tvr_getValuesCount (void)
 Get the count of all TraceValues, that are registered here and descending. More...
 
virtual void _tvr_insertTraceValuesToSet (TraceSet &t)
 Insert all TraceValues into TraceSet, that registered here and descending. More...
 

Protected Attributes

unsigned char udrWrite
 Write stage of UDR register value. More...
 
unsigned char udrRead
 Read stage of UDR register value. More...
 
unsigned char usr
 USR register value, also used as UCSRA register value. More...
 
unsigned char ucr
 UCR register value, also used as UCSRB register value. More...
 
unsigned char ucsrc
 UCSRC register value. More...
 
unsigned short ubrr
 Baud rate register value (UBRR) More...
 
bool readParity
 The read parity flag for usart. More...
 
bool writeParity
 The write parity flag for usart. More...
 
int frameLength
 Hold length of UART frame. More...
 
HWIrqSystemirqSystem
 Connection to interrupt system. More...
 
PinAtPort pinTx
 TX pin. More...
 
PinAtPort pinRx
 RX pin. More...
 
unsigned int vectorRx
 Interrupt vector ID for receive interrupt. More...
 
unsigned int vectorUdre
 Interrupt vector ID for UDR empty interrupt. More...
 
unsigned int vectorTx
 Interrupt vector ID for sent byte interrupt. More...
 
unsigned char regSeq
 Cycle timer for controling read access to UCSRC/UBRRH combined register. More...
 
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

◆ T_RxState

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.

◆ T_TxState

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::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 
)

Member Function Documentation

◆ CheckForNewClearIrq()

void HWUart::CheckForNewClearIrq ( unsigned char  val)

Definition at line 600 of file hwuart.cpp.

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

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

◆ CheckForNewSetIrq()

void HWUart::CheckForNewSetIrq ( unsigned char  val)

Definition at line 594 of file hwuart.cpp.

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

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

◆ ClearIrqFlag()

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 586 of file hwuart.cpp.

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

◆ CpuCycle()

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.

◆ CpuCycleRx()

◆ CpuCycleTx()

◆ GetUbrr()

unsigned char HWUart::GetUbrr ( )

Definition at line 583 of file hwuart.cpp.

References ubrr.

◆ GetUbrrhi()

unsigned char HWUart::GetUbrrhi ( )

Definition at line 584 of file hwuart.cpp.

References ubrr.

Referenced by HWUsart::GetUcsrcUbrrh().

◆ GetUcr()

unsigned char HWUart::GetUcr ( )

Definition at line 582 of file hwuart.cpp.

References ucr.

◆ GetUdr()

unsigned char HWUart::GetUdr ( )

Definition at line 571 of file hwuart.cpp.

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

◆ GetUsr()

unsigned char HWUart::GetUsr ( )

Definition at line 581 of file hwuart.cpp.

References usr.

◆ Reset()

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 606 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().

◆ SetFrameLengthFromRegister()

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().

◆ SetUbrr()

void HWUart::SetUbrr ( unsigned char  val)

Definition at line 92 of file hwuart.cpp.

References ubrr.

◆ SetUbrrhi()

void HWUart::SetUbrrhi ( unsigned char  val)

Definition at line 96 of file hwuart.cpp.

References ubrr.

Referenced by HWUsart::SetUcsrcUbrrh().

◆ SetUcr()

◆ SetUdr()

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.

◆ SetUsr()

void HWUart::SetUsr ( unsigned char  val)

Definition at line 73 of file hwuart.cpp.

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

Member Data Documentation

◆ baudCnt

int HWUart::baudCnt
protected

Definition at line 64 of file hwuart.h.

Referenced by CpuCycle(), and Reset().

◆ baudCnt16

int HWUart::baudCnt16
protected

Definition at line 101 of file hwuart.h.

Referenced by CpuCycleTx(), and Reset().

◆ cntRxSamples

int HWUart::cntRxSamples
protected

Definition at line 95 of file hwuart.h.

Referenced by CpuCycleRx().

◆ frameLength

int HWUart::frameLength
protected

Hold length of UART frame.

Definition at line 51 of file hwuart.h.

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

◆ irqSystem

HWIrqSystem* HWUart::irqSystem
protected

Connection to interrupt system.

Definition at line 53 of file hwuart.h.

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

◆ pinRx

PinAtPort HWUart::pinRx
protected

RX pin.

Definition at line 56 of file hwuart.h.

Referenced by CpuCycleRx(), and SetUcr().

◆ pinTx

PinAtPort HWUart::pinTx
protected

TX pin.

Definition at line 55 of file hwuart.h.

Referenced by CpuCycleTx(), and SetUcr().

◆ readParity

bool HWUart::readParity
protected

The read parity flag for usart.

Definition at line 48 of file hwuart.h.

Referenced by CpuCycleRx().

◆ regSeq

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().

◆ rxBitCnt

int HWUart::rxBitCnt
protected

Definition at line 99 of file hwuart.h.

Referenced by CpuCycleRx().

◆ rxDataTmp

unsigned int HWUart::rxDataTmp
protected

Definition at line 98 of file hwuart.h.

Referenced by CpuCycleRx().

◆ rxHighCnt

int HWUart::rxHighCnt
protected

Definition at line 97 of file hwuart.h.

Referenced by CpuCycleRx().

◆ rxLowCnt

int HWUart::rxLowCnt
protected

Definition at line 96 of file hwuart.h.

Referenced by CpuCycleRx().

◆ rxState

T_RxState HWUart::rxState
protected

Definition at line 89 of file hwuart.h.

Referenced by CpuCycleRx(), and Reset().

◆ txBitCnt

int HWUart::txBitCnt
protected

Definition at line 103 of file hwuart.h.

Referenced by CpuCycleTx().

◆ txDataTmp

unsigned char HWUart::txDataTmp
protected

Definition at line 102 of file hwuart.h.

Referenced by CpuCycleTx().

◆ txState

T_TxState HWUart::txState
protected

Definition at line 90 of file hwuart.h.

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

◆ ubrr

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().

◆ ubrr_reg

◆ ubrrhi_reg

◆ ucr

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().

◆ ucr_reg

IOReg<HWUart> HWUart::ucr_reg

Definition at line 136 of file hwuart.h.

◆ ucsra_reg

◆ ucsrb_reg

◆ ucsrc

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().

◆ udr_reg

◆ udrRead

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().

◆ udrWrite

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().

◆ usr

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().

◆ usr_reg

IOReg<HWUart> HWUart::usr_reg

Definition at line 136 of file hwuart.h.

◆ vectorRx

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().

◆ vectorTx

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().

◆ vectorUdre

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().

◆ writeParity

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: