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 FLASHPROG
00027 #define FLASHPROG
00028
00029 #include "rwmem.h"
00030 #include "hardware.h"
00031 #include "systemclocktypes.h"
00032
00033 class AvrDevice;
00034
00036
00038 class FlashProgramming: public Hardware {
00039
00040 protected:
00042 enum SPM_ACTIONtype {
00043 SPM_ACTION_NOOP = 0,
00044 SPM_ACTION_PREPARE,
00045 SPM_ACTION_LOCKCPU,
00046 SPM_ACTION_WAIT
00047 };
00049 enum SPM_OPStype {
00050 SPM_OPS_NOOP = 0,
00051 SPM_OPS_STOREBUFFER,
00052 SPM_OPS_WRITEBUFFER,
00053 SPM_OPS_ERASE,
00054 SPM_OPS_LOCKBITS,
00055 SPM_OPS_UNLOCKRWW,
00056 SPM_OPS_CLEARBUFFER,
00057 SPM_OPS_READSIG
00058 };
00059 unsigned int pageSize;
00060 unsigned int nrww_addr;
00061 unsigned char spmcr_val;
00062 unsigned char spmcr_opr_bits;
00063 unsigned char spmcr_valid_bits;
00064 int opr_enable_count;
00065 SPM_ACTIONtype action;
00066 SPM_OPStype spm_opr;
00067 AvrDevice *core;
00068 SystemClockOffset timeout;
00069 unsigned char *tempBuffer;
00070 bool isATMega;
00071
00072 void ClearOperationBits(void);
00073 void SetRWWLock(unsigned int addr);
00074
00075 public:
00076 enum {
00077 SPM_TINY_MODE = 0,
00078 SPM_MEGA_MODE = 1,
00079 SPM_SIG_OPR = 2,
00080 SPM_TIMEOUT = 4000000
00081 };
00082
00084 FlashProgramming(AvrDevice *c, unsigned int pgsz, unsigned int nrww, int mode);
00085 ~FlashProgramming();
00086
00087 unsigned int CpuCycle();
00088 void Reset();
00089
00090 unsigned char LPM_action(unsigned int xaddr, unsigned int addr);
00091 int SPM_action(unsigned int data, unsigned int xaddr, unsigned int addr);
00092 void SetSpmcr(unsigned char v);
00093 unsigned char GetSpmcr() { return spmcr_val; }
00094
00095 IOReg<FlashProgramming> spmcr_reg;
00096
00097 };
00098
00099 #endif