simulavr  1.1.0
flashprog.h
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #ifndef FLASHPROG
27 #define FLASHPROG
28 
29 #include "rwmem.h"
30 #include "hardware.h"
31 #include "systemclocktypes.h"
32 
33 class AvrDevice;
34 
36 
38 class FlashProgramming: public Hardware {
39 
40  protected:
47  };
49  enum SPM_OPStype {
58  };
59  unsigned int pageSize;
60  unsigned int nrww_addr;
61  unsigned char spmcr_val;
62  unsigned char spmcr_opr_bits;
63  unsigned char spmcr_valid_bits;
69  unsigned char *tempBuffer;
70  bool isATMega;
71 
72  void ClearOperationBits(void);
73  void SetRWWLock(unsigned int addr);
74 
75  public:
76  enum {
80  SPM_TIMEOUT = 4000000
81  };
82 
84  FlashProgramming(AvrDevice *c, unsigned int pgsz, unsigned int nrww, int mode);
86 
87  unsigned int CpuCycle();
88  void Reset();
89 
90  unsigned char LPM_action(unsigned int xaddr, unsigned int addr);
91  int SPM_action(unsigned int data, unsigned int xaddr, unsigned int addr);
92  void SetSpmcr(unsigned char v);
93  unsigned char GetSpmcr() { return spmcr_val; }
94 
96 
97 };
98 
100 class AvrFuses {
101 
102  private:
104  unsigned long fuseBits;
105  unsigned int nrwwAddr;
106  unsigned int nrwwSize;
109  bool flagBOOTRST;
111 
112  public:
113  enum {
114  FB_CKDIV8 = 7
115  };
116 
117  AvrFuses(void);
119  void SetFuseConfiguration(int size, unsigned long defvalue);
121  bool LoadFuses(const unsigned char *buffer, int size);
123  unsigned char GetFuseByte(int index) { return (fuseBits >> (index * 8)) & 0xff; }
125  bool GetFuseBit(int index) { return !(bool)((fuseBits >> index) & 0x1); }
127  int GetFuseByteSize(void) { return (fuseBitsSize / 8) + 1; }
129  void SetBootloaderConfig(unsigned addr, int size, int bPosBOOTSZ, int bPosBOOTRST);
131  unsigned int GetBLSStart(void);
133  unsigned int GetResetAddr(void);
134 
135 };
136 
138 class AvrLockBits {
139 
140  private:
142  unsigned char lockBits;
143 
144  public:
145  AvrLockBits(void);
147  void SetLockBitsConfiguration(int size);
149  bool LoadLockBits(const unsigned char *buffer, int size);
151  unsigned char GetLockByte(void) { return lockBits; }
153  void SetLockBits(unsigned char bits);
154 
155 };
156 
157 #endif
FlashProgramming(AvrDevice *c, unsigned int pgsz, unsigned int nrww, int mode)
Create a instance of FlashProgramming class.
Definition: flashprog.cpp:52
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
SPM_OPStype
SPM operations.
Definition: flashprog.h:49
unsigned char spmcr_opr_bits
mask for operation bits, including SPMEN bit
Definition: flashprog.h:62
unsigned char * tempBuffer
hidden buffer for flash page operations
Definition: flashprog.h:69
int lockBitsSize
count of lock bits
Definition: flashprog.h:141
SPM_ACTIONtype
states of processing engine
Definition: flashprog.h:42
bool isATMega
Flag: true, if in ATMega mode, if false, it's ATTiny mode.
Definition: flashprog.h:70
int GetFuseByteSize(void)
Get count of fuse bytes available.
Definition: flashprog.h:127
int valueBOOTSZ
value of BOOTSZ fuse bits
Definition: flashprog.h:110
int bitPosBOOTRST
bit position BOOTRST fuses (1 Bit) in fuseBits
Definition: flashprog.h:108
unsigned char spmcr_valid_bits
mask for valid bits
Definition: flashprog.h:63
bool flagBOOTRST
value of BOOTRST fuse bit
Definition: flashprog.h:109
unsigned char LPM_action(unsigned int xaddr, unsigned int addr)
Definition: flashprog.cpp:114
unsigned char lockBits
lock bits data
Definition: flashprog.h:142
SystemClockOffset timeout
system time till operation run
Definition: flashprog.h:68
int opr_enable_count
enable counter for SPM operation
Definition: flashprog.h:64
unsigned char spmcr_val
holds the register value
Definition: flashprog.h:61
SPM_OPStype spm_opr
selected SPM operation
Definition: flashprog.h:66
SPM_ACTIONtype action
state of the processing engine
Definition: flashprog.h:65
void ClearOperationBits(void)
Definition: flashprog.cpp:35
unsigned char GetLockByte(void)
Get lock bits (for LPM instruction)
Definition: flashprog.h:151
long long SystemClockOffset
unsigned int CpuCycle()
Definition: flashprog.cpp:90
unsigned int nrwwSize
size of NRWW section in byte
Definition: flashprog.h:106
Support for fuse bits.
Definition: flashprog.h:100
void SetRWWLock(unsigned int addr)
Definition: flashprog.cpp:41
void SetSpmcr(unsigned char v)
Definition: flashprog.cpp:186
int bitPosBOOTSZ
bit position BOOTSZ fuses (2 Bit) in fuseBits
Definition: flashprog.h:107
Provides the programming engine for flash self programming.
Definition: flashprog.h:38
int SPM_action(unsigned int data, unsigned int xaddr, unsigned int addr)
Definition: flashprog.cpp:118
unsigned int pageSize
page size in words
Definition: flashprog.h:59
unsigned int nrwwAddr
start address NRWW section
Definition: flashprog.h:105
unsigned int nrww_addr
start address of non RWW area of flash (word address)
Definition: flashprog.h:60
unsigned char GetFuseByte(int index)
Get fuse byte by index.
Definition: flashprog.h:123
unsigned char GetSpmcr()
Definition: flashprog.h:93
bool GetFuseBit(int index)
Get fuse bit by bit index, starts with 0 on lfuse bit 0, bit = 0 means true!
Definition: flashprog.h:125
int fuseBitsSize
count of bits in fuses
Definition: flashprog.h:103
AvrDevice * core
link to AvrDevice
Definition: flashprog.h:67
Support for lock bits.
Definition: flashprog.h:138
unsigned long fuseBits
fuse data
Definition: flashprog.h:104
IOReg< FlashProgramming > spmcr_reg
Definition: flashprog.h:95