Implements the I/O hardware necessary to do UART transfers. More...
#include <hwuart.h>
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< HWUart > | udr_reg |
IOReg< HWUart > | usr_reg |
IOReg< HWUart > | ucr_reg |
IOReg< HWUart > | ucsra_reg |
IOReg< HWUart > | ucsrb_reg |
IOReg< HWUart > | ubrr_reg |
IO register "UBRRxL" - baudrate. | |
IOReg< HWUart > | ubrrhi_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. | |
HWIrqSystem * | irqSystem |
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 |
Implements the I/O hardware necessary to do UART transfers.
Definition at line 38 of file hwuart.h.
enum HWUart::T_RxState [protected] |
enum HWUart::T_TxState [protected] |
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.
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().
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().
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.
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.
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().
unsigned int HWUart::CpuCycleTx | ( | ) | [protected] |
Definition at line 385 of file hwuart.cpp.
References baudCnt16, CheckForNewClearIrq(), CheckForNewSetIrq(), frameLength, pinTx, PinAtPort::SetAlternatePort(), TX_AFTER_STOPBIT, TX_DISABLED, TX_FINISH, TX_FIRST_RUN, TX_SEND_DATABIT, TX_SEND_PARITY, TX_SEND_STARTBIT, TX_SEND_STOPBIT, TX_SEND_STOPBIT2, TXB8, txBitCnt, TXC, txDataTmp, TXEN, txState, ucr, ucsrc, UDRE, udrWrite, UPM0, UPM1, USBS, usr, and writeParity.
Referenced by CpuCycle().
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().
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.
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().
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().
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().
void HWUart::SetUcr | ( | unsigned char | val | ) |
Definition at line 126 of file hwuart.cpp.
References CheckForNewClearIrq(), CheckForNewSetIrq(), pinRx, pinTx, RXEN, PinAtPort::SetAlternateDdr(), PinAtPort::SetAlternatePort(), SetFrameLengthFromRegister(), PinAtPort::SetUseAlternateDdr(), PinAtPort::SetUseAlternatePort(), TX_FIRST_RUN, TX_SEND_STARTBIT, TXEN, txState, ucr, and usr.
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.
void HWUart::SetUsr | ( | unsigned char | val | ) |
Definition at line 73 of file hwuart.cpp.
References CheckForNewClearIrq(), CheckForNewSetIrq(), TXC, ucr, and usr.
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().
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().
PinAtPort HWUart::pinRx [protected] |
PinAtPort HWUart::pinTx [protected] |
bool HWUart::readParity [protected] |
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().
T_RxState HWUart::rxState [protected] |
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().
T_TxState HWUart::txState [protected] |
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().
IO register "UBRRxL" - baudrate.
Definition at line 136 of file hwuart.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_at90s4433::AvrDevice_at90s4433(), AvrDevice_at90s8515::AvrDevice_at90s8515(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), AvrDevice_atmega16_32::AvrDevice_atmega16_32(), AvrDevice_atmega668base::AvrDevice_atmega668base(), AvrDevice_atmega8::AvrDevice_atmega8(), and AvrDevice_attiny2313::AvrDevice_attiny2313().
IO register "UBRRxH" - baudrate.
Definition at line 136 of file hwuart.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_at90s4433::AvrDevice_at90s4433(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), and AvrDevice_atmega668base::AvrDevice_atmega668base().
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().
Definition at line 136 of file hwuart.h.
Referenced by AvrDevice_at90s4433::AvrDevice_at90s4433(), and AvrDevice_at90s8515::AvrDevice_at90s8515().
Definition at line 136 of file hwuart.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), AvrDevice_atmega16_32::AvrDevice_atmega16_32(), AvrDevice_atmega668base::AvrDevice_atmega668base(), AvrDevice_atmega8::AvrDevice_atmega8(), and AvrDevice_attiny2313::AvrDevice_attiny2313().
Definition at line 136 of file hwuart.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), AvrDevice_atmega16_32::AvrDevice_atmega16_32(), AvrDevice_atmega668base::AvrDevice_atmega668base(), AvrDevice_atmega8::AvrDevice_atmega8(), and AvrDevice_attiny2313::AvrDevice_attiny2313().
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().
Definition at line 136 of file hwuart.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_at90s4433::AvrDevice_at90s4433(), AvrDevice_at90s8515::AvrDevice_at90s8515(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), AvrDevice_atmega16_32::AvrDevice_atmega16_32(), AvrDevice_atmega668base::AvrDevice_atmega668base(), AvrDevice_atmega8::AvrDevice_atmega8(), and AvrDevice_attiny2313::AvrDevice_attiny2313().
unsigned char HWUart::udrRead [protected] |
unsigned char HWUart::udrWrite [protected] |
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().
Definition at line 136 of file hwuart.h.
Referenced by AvrDevice_at90s4433::AvrDevice_at90s4433(), and AvrDevice_at90s8515::AvrDevice_at90s8515().
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().