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 TIMERPRESCALER
00027 #define TIMERPRESCALER
00028
00029 #include "../hardware.h"
00030 #include "../avrdevice.h"
00031 #include "../rwmem.h"
00032 #include "../pinatport.h"
00033
00035
00037 class HWPrescaler: public Hardware, public IOSpecialRegClient {
00038
00039 private:
00040 int _resetBit;
00041 int _resetSyncBit;
00042
00043 protected:
00044 IOSpecialReg* resetRegister;
00045 unsigned short preScaleValue;
00046 bool countEnable;
00047
00048 unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv);
00050 unsigned char get_from_client(const IOSpecialReg *reg, unsigned char v) { return v; }
00051
00052 public:
00054 HWPrescaler(AvrDevice *core, const std::string &tracename);
00056 HWPrescaler(AvrDevice *core,
00057 const std::string &tracename,
00058 IOSpecialReg *ioreg,
00059 int resetBit);
00061 HWPrescaler(AvrDevice *core,
00062 const std::string &tracename,
00063 IOSpecialReg *ioreg,
00064 int resetBit,
00065 int resetSyncBit);
00067 virtual unsigned int CpuCycle() {
00068 if(countEnable) {
00069 preScaleValue++;
00070 if(preScaleValue > 1023) preScaleValue = 0;
00071 }
00072 return 0;
00073 }
00075 unsigned short GetValue() { return preScaleValue; }
00077 void Reset(){ preScaleValue = 0; }
00078 };
00079
00081
00083 class HWPrescalerAsync: public HWPrescaler {
00084
00085 public:
00087 HWPrescalerAsync(AvrDevice *core,
00088 const std::string &tracename,
00089 PinAtPort tosc_pin,
00090 IOSpecialReg *asyreg,
00091 int clockSelBit,
00092 IOSpecialReg *resreg,
00093 int resetBit);
00095 HWPrescalerAsync(AvrDevice *core,
00096 const std::string &tracename,
00097 PinAtPort tosc_pin,
00098 IOSpecialReg *asyreg,
00099 int clockSelBit,
00100 IOSpecialReg *resreg,
00101 int resetBit,
00102 int resetSyncBit);
00104 virtual unsigned int CpuCycle();
00105
00106 protected:
00108 unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv);
00109
00110 private:
00111 IOSpecialReg* asyncRegister;
00112 PinAtPort tosc_pin;
00113 bool pinstate;
00114 bool clockselect;
00115 int clockSelectBit;
00116 };
00117
00118 #endif // TIMERPRESCALER