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 HWSPI
00027 #define HWSPI
00028
00029 #include "hardware.h"
00030 #include "pinatport.h"
00031 #include "rwmem.h"
00032 #include "traceval.h"
00033
00034 class AvrDevice;
00035 class HWIrqSystem;
00036
00038 class HWSpi: public Hardware, public TraceValueRegister {
00039
00040 private:
00043 unsigned char shift_in;
00045 unsigned char data_read;
00047 unsigned char data_write;
00048 unsigned char spsr;
00049 unsigned char spcr;
00050
00051 AvrDevice *core;
00052 HWIrqSystem *irq;
00053
00054 PinAtPort MOSI;
00055 PinAtPort MISO;
00056 PinAtPort SCK;
00057 PinAtPort SS;
00058 unsigned int irq_vector;
00059
00062 int clkdiv;
00063
00065 void updatePrescaler();
00066
00069 bool spsr_read;
00070
00071
00072 bool oldsck;
00073
00075 int bitcnt;
00076
00078 unsigned clkcnt;
00079
00080
00081 int spi_cycles;
00082
00086 bool mega_mode;
00087
00089 bool finished;
00090
00092 void txbit(const int bitpos);
00093 void rxbit(const int bitpos);
00094
00096 void trxend();
00097
00099 void spdr_access();
00100
00101 public:
00102 HWSpi(AvrDevice *core,
00103 HWIrqSystem *,
00104 PinAtPort mosi,
00105 PinAtPort miso,
00106 PinAtPort sck,
00107 PinAtPort ss,
00108 unsigned int irq_vec,
00109 bool mega_mode=true);
00110
00111 unsigned int CpuCycle();
00112 void Reset();
00113
00114 void SetSPDR(unsigned char val);
00115 void SetSPSR(unsigned char val);
00116 void SetSPCR(unsigned char val);
00117
00118 unsigned char GetSPDR();
00119 unsigned char GetSPSR();
00120 unsigned char GetSPCR();
00121
00122 void ClearIrqFlag(unsigned int);
00123
00124 IOReg<HWSpi> spdr_reg,
00125 spsr_reg,
00126 spcr_reg;
00127 };
00128
00129 #endif