00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef HWUART
00027 #define HWUART
00028
00029 #include "avrdevice.h"
00030 #include "irqsystem.h"
00031 #include "hardware.h"
00032 #include "pinatport.h"
00033 #include "rwmem.h"
00034 #include "traceval.h"
00035
00037
00038 class HWUart: public Hardware, public TraceValueRegister {
00039
00040 protected:
00041 unsigned char udrWrite;
00042 unsigned char udrRead;
00043 unsigned char usr;
00044 unsigned char ucr;
00045 unsigned char ucsrc;
00046 unsigned short ubrr;
00047
00048 bool readParity;
00049 bool writeParity;
00050
00051 int frameLength;
00052
00053 HWIrqSystem *irqSystem;
00054
00055 PinAtPort pinTx;
00056 PinAtPort pinRx;
00057
00058 unsigned int vectorRx;
00059 unsigned int vectorUdre;
00060 unsigned int vectorTx;
00061
00062 unsigned char regSeq;
00063
00064 int baudCnt;
00065
00066 enum T_RxState {
00067 RX_DISABLED,
00068 RX_WAIT_FOR_HIGH,
00069 RX_WAIT_FOR_LOWEDGE,
00070 RX_READ_STARTBIT,
00071 RX_READ_DATABIT,
00072 RX_READ_PARITY,
00073 RX_READ_STOPBIT,
00074 RX_READ_STOPBIT2
00075 } ;
00076
00077 enum T_TxState{
00078 TX_DISABLED,
00079 TX_SEND_STARTBIT,
00080 TX_SEND_DATABIT,
00081 TX_SEND_PARITY,
00082 TX_SEND_STOPBIT,
00083 TX_SEND_STOPBIT2,
00084 TX_AFTER_STOPBIT,
00085 TX_FIRST_RUN,
00086 TX_FINISH
00087 } ;
00088
00089 T_RxState rxState;
00090 T_TxState txState;
00091
00092 unsigned int CpuCycleRx();
00093 unsigned int CpuCycleTx();
00094
00095 int cntRxSamples;
00096 int rxLowCnt;
00097 int rxHighCnt;
00098 unsigned int rxDataTmp;
00099 int rxBitCnt;
00100
00101 int baudCnt16;
00102 unsigned char txDataTmp;
00103 int txBitCnt;
00104
00105 public:
00107 HWUart(AvrDevice *core,
00108 HWIrqSystem *,
00109 PinAtPort tx,
00110 PinAtPort rx,
00111 unsigned int rx_interrupt,
00112 unsigned int udre_interrupt,
00113 unsigned int tx_interrupt,
00114 int instance_id = 0);
00115 virtual unsigned int CpuCycle();
00116
00117 void Reset();
00118
00119 void SetUdr(unsigned char val);
00120 void SetUsr(unsigned char val);
00121 void SetUcr(unsigned char val);
00122 void SetUbrr(unsigned char val);
00123 void SetUbrrhi(unsigned char val);
00124
00125 unsigned char GetUdr();
00126 unsigned char GetUsr();
00127 unsigned char GetUcr();
00128 unsigned char GetUbrr();
00129 unsigned char GetUbrrhi();
00130
00131 void ClearIrqFlag(unsigned int);
00132 void CheckForNewSetIrq(unsigned char);
00133 void CheckForNewClearIrq(unsigned char);
00134
00135 IOReg<HWUart>
00136 udr_reg,
00137 usr_reg,
00138 ucr_reg,
00139 ucsra_reg,
00140 ucsrb_reg,
00141 ubrr_reg,
00142 ubrrhi_reg;
00143
00144 protected:
00145 void SetFrameLengthFromRegister();
00146 };
00147
00149 class HWUsart: public HWUart {
00150
00151 protected:
00152 PinAtPort pinXck;
00153
00154 public:
00156 HWUsart(AvrDevice *core,
00157 HWIrqSystem *,
00158 PinAtPort tx,
00159 PinAtPort rx,
00160 PinAtPort xck,
00161 unsigned int rx_interrupt,
00162 unsigned int udre_interrupt,
00163 unsigned int tx_interrupt,
00164 int instance_id = 0,
00165 bool mxReg = true);
00166
00167 void SetUcsrc(unsigned char val);
00168 void SetUcsrcUbrrh(unsigned char val);
00169
00170 unsigned char GetUcsrc();
00171 unsigned char GetUcsrcUbrrh();
00172
00173 IOReg<HWUsart> ucsrc_reg,
00174 ubrrh_reg,
00175 ucsrc_ubrrh_reg;
00176 };
00177
00178 #endif