simulavr  1.1.0
FlashProgramming Class Reference

Provides the programming engine for flash self programming. More...

#include <flashprog.h>

Inheritance diagram for FlashProgramming:

Public Types

enum  { SPM_TINY_MODE = 0, SPM_MEGA_MODE = 1, SPM_SIG_OPR = 2, SPM_TIMEOUT = 4000000 }
 

Public Member Functions

 FlashProgramming (AvrDevice *c, unsigned int pgsz, unsigned int nrww, int mode)
 Create a instance of FlashProgramming class. More...
 
 ~FlashProgramming ()
 
unsigned int CpuCycle ()
 
void Reset ()
 
unsigned char LPM_action (unsigned int xaddr, unsigned int addr)
 
int SPM_action (unsigned int data, unsigned int xaddr, unsigned int addr)
 
void SetSpmcr (unsigned char v)
 
unsigned char GetSpmcr ()
 
- Public Member Functions inherited from Hardware
 Hardware (AvrDevice *core)
 
virtual ~Hardware ()
 
virtual void ClearIrqFlag (unsigned int vector)
 
virtual bool IsLevelInterrupt (unsigned int vector)
 
virtual bool LevelInterruptPending (unsigned int vector)
 

Public Attributes

IOReg< FlashProgrammingspmcr_reg
 

Protected Types

enum  SPM_ACTIONtype { SPM_ACTION_NOOP = 0, SPM_ACTION_PREPARE, SPM_ACTION_LOCKCPU, SPM_ACTION_WAIT }
 states of processing engine More...
 
enum  SPM_OPStype {
  SPM_OPS_NOOP = 0, SPM_OPS_STOREBUFFER, SPM_OPS_WRITEBUFFER, SPM_OPS_ERASE,
  SPM_OPS_LOCKBITS, SPM_OPS_UNLOCKRWW, SPM_OPS_CLEARBUFFER, SPM_OPS_READSIG
}
 SPM operations. More...
 

Protected Member Functions

void ClearOperationBits (void)
 
void SetRWWLock (unsigned int addr)
 

Protected Attributes

unsigned int pageSize
 page size in words More...
 
unsigned int nrww_addr
 start address of non RWW area of flash (word address) More...
 
unsigned char spmcr_val
 holds the register value More...
 
unsigned char spmcr_opr_bits
 mask for operation bits, including SPMEN bit More...
 
unsigned char spmcr_valid_bits
 mask for valid bits More...
 
int opr_enable_count
 enable counter for SPM operation More...
 
SPM_ACTIONtype action
 state of the processing engine More...
 
SPM_OPStype spm_opr
 selected SPM operation More...
 
AvrDevicecore
 link to AvrDevice More...
 
SystemClockOffset timeout
 system time till operation run More...
 
unsigned char * tempBuffer
 hidden buffer for flash page operations More...
 
bool isATMega
 Flag: true, if in ATMega mode, if false, it's ATTiny mode. More...
 

Detailed Description

Provides the programming engine for flash self programming.

Todo:
not implemented yet: SPM interrupt. Support of LPM operation. Setting boot lock bits. Read-While-Write, if run code in NRWW section.

Definition at line 38 of file flashprog.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
SPM_TINY_MODE 
SPM_MEGA_MODE 
SPM_SIG_OPR 
SPM_TIMEOUT 

Definition at line 76 of file flashprog.h.

◆ SPM_ACTIONtype

states of processing engine

Enumerator
SPM_ACTION_NOOP 
SPM_ACTION_PREPARE 
SPM_ACTION_LOCKCPU 
SPM_ACTION_WAIT 

Definition at line 42 of file flashprog.h.

◆ SPM_OPStype

SPM operations.

Enumerator
SPM_OPS_NOOP 
SPM_OPS_STOREBUFFER 
SPM_OPS_WRITEBUFFER 
SPM_OPS_ERASE 
SPM_OPS_LOCKBITS 
SPM_OPS_UNLOCKRWW 
SPM_OPS_CLEARBUFFER 
SPM_OPS_READSIG 

Definition at line 49 of file flashprog.h.

Constructor & Destructor Documentation

◆ FlashProgramming()

FlashProgramming::FlashProgramming ( AvrDevice c,
unsigned int  pgsz,
unsigned int  nrww,
int  mode 
)

◆ ~FlashProgramming()

FlashProgramming::~FlashProgramming ( )

Definition at line 86 of file flashprog.cpp.

References avr_free(), and tempBuffer.

Member Function Documentation

◆ ClearOperationBits()

void FlashProgramming::ClearOperationBits ( void  )
protected

Definition at line 35 of file flashprog.cpp.

References action, SPM_ACTION_NOOP, spm_opr, SPM_OPS_NOOP, spmcr_opr_bits, and spmcr_val.

Referenced by CpuCycle(), and SPM_action().

◆ CpuCycle()

unsigned int FlashProgramming::CpuCycle ( void  )
virtual

Called for each AVR cycle when this hardware has registered itself as a receiver for AVR clocks. Returns nonzero if instructions should not be executed (e.g. a Flash write is in progress).

Reimplemented from Hardware.

Definition at line 90 of file flashprog.cpp.

References action, ClearOperationBits(), SystemClock::Instance(), opr_enable_count, SPM_ACTION_LOCKCPU, and timeout.

◆ GetSpmcr()

unsigned char FlashProgramming::GetSpmcr ( )
inline

Definition at line 93 of file flashprog.h.

References spmcr_val.

◆ LPM_action()

unsigned char FlashProgramming::LPM_action ( unsigned int  xaddr,
unsigned int  addr 
)

Definition at line 114 of file flashprog.cpp.

◆ Reset()

void FlashProgramming::Reset ( void  )
virtual

Implement the hardware's reset functionality here. The default is no action on reset.

Reimplemented from Hardware.

Definition at line 106 of file flashprog.cpp.

References action, opr_enable_count, SPM_ACTION_NOOP, spm_opr, SPM_OPS_NOOP, spmcr_val, and timeout.

Referenced by FlashProgramming().

◆ SetRWWLock()

void FlashProgramming::SetRWWLock ( unsigned int  addr)
protected

Definition at line 41 of file flashprog.cpp.

References core, AvrDevice::Flash, isATMega, nrww_addr, AvrFlash::SetRWWLock(), and spmcr_val.

Referenced by SPM_action().

◆ SetSpmcr()

◆ SPM_action()

Member Data Documentation

◆ action

SPM_ACTIONtype FlashProgramming::action
protected

state of the processing engine

Definition at line 65 of file flashprog.h.

Referenced by ClearOperationBits(), CpuCycle(), Reset(), SetSpmcr(), and SPM_action().

◆ core

AvrDevice* FlashProgramming::core
protected

link to AvrDevice

Definition at line 67 of file flashprog.h.

Referenced by FlashProgramming(), SetRWWLock(), and SPM_action().

◆ isATMega

bool FlashProgramming::isATMega
protected

Flag: true, if in ATMega mode, if false, it's ATTiny mode.

Definition at line 70 of file flashprog.h.

Referenced by FlashProgramming(), SetRWWLock(), and SetSpmcr().

◆ nrww_addr

unsigned int FlashProgramming::nrww_addr
protected

start address of non RWW area of flash (word address)

Definition at line 60 of file flashprog.h.

Referenced by SetRWWLock(), and SPM_action().

◆ opr_enable_count

int FlashProgramming::opr_enable_count
protected

enable counter for SPM operation

Definition at line 64 of file flashprog.h.

Referenced by CpuCycle(), Reset(), SetSpmcr(), and SPM_action().

◆ pageSize

unsigned int FlashProgramming::pageSize
protected

page size in words

Definition at line 59 of file flashprog.h.

Referenced by FlashProgramming(), and SPM_action().

◆ spm_opr

SPM_OPStype FlashProgramming::spm_opr
protected

selected SPM operation

Definition at line 66 of file flashprog.h.

Referenced by ClearOperationBits(), Reset(), SetSpmcr(), and SPM_action().

◆ spmcr_opr_bits

unsigned char FlashProgramming::spmcr_opr_bits
protected

mask for operation bits, including SPMEN bit

Definition at line 62 of file flashprog.h.

Referenced by ClearOperationBits(), FlashProgramming(), and SetSpmcr().

◆ spmcr_reg

◆ spmcr_val

unsigned char FlashProgramming::spmcr_val
protected

holds the register value

Definition at line 61 of file flashprog.h.

Referenced by ClearOperationBits(), GetSpmcr(), Reset(), SetRWWLock(), SetSpmcr(), and SPM_action().

◆ spmcr_valid_bits

unsigned char FlashProgramming::spmcr_valid_bits
protected

mask for valid bits

Definition at line 63 of file flashprog.h.

Referenced by FlashProgramming(), and SetSpmcr().

◆ tempBuffer

unsigned char* FlashProgramming::tempBuffer
protected

hidden buffer for flash page operations

Definition at line 69 of file flashprog.h.

Referenced by FlashProgramming(), SPM_action(), and ~FlashProgramming().

◆ timeout

SystemClockOffset FlashProgramming::timeout
protected

system time till operation run

Definition at line 68 of file flashprog.h.

Referenced by CpuCycle(), Reset(), and SPM_action().


The documentation for this class was generated from the following files: