simulavr  1.1.0
HWSpi Class Reference

#include <hwspi.h>

Inheritance diagram for HWSpi:

Public Member Functions

 HWSpi (AvrDevice *core, HWIrqSystem *, PinAtPort mosi, PinAtPort miso, PinAtPort sck, PinAtPort ss, unsigned int irq_vec, bool mega_mode=true)
 
unsigned int CpuCycle ()
 
void Reset ()
 
void SetSPDR (unsigned char val)
 
void SetSPSR (unsigned char val)
 
void SetSPCR (unsigned char val)
 
unsigned char GetSPDR ()
 
unsigned char GetSPSR ()
 
unsigned char GetSPCR ()
 
void ClearIrqFlag (unsigned int)
 
- Public Member Functions inherited from Hardware
 Hardware (AvrDevice *core)
 
virtual ~Hardware ()
 
virtual bool IsLevelInterrupt (unsigned int vector)
 
virtual bool LevelInterruptPending (unsigned int vector)
 
- Public Member Functions inherited from TraceValueRegister
 TraceValueRegister (TraceValueRegister *parent, const std::string &name)
 Create a TraceValueRegister, with a scope prefix built on parent scope + name. More...
 
 TraceValueRegister ()
 Create a TraceValueRegister, with a empty scope name, single device application. More...
 
virtual ~TraceValueRegister ()
 
const std::string GetTraceValuePrefix (void)
 Returns the scope prefix. More...
 
const std::string GetScopeName (void)
 Returns the scope name. More...
 
void RegisterTraceValue (TraceValue *t)
 Registers a TraceValue for this register. More...
 
void UnregisterTraceValue (TraceValue *t)
 Unregisters a TraceValue, remove it from register. More...
 
TraceValueRegisterGetScopeGroupByName (const std::string &name)
 Get a here registered TraceValueRegister by it's name. More...
 
virtual TraceValueGetTraceValueByName (const std::string &name)
 Get a here registered TraceValue by it's name. More...
 
TraceValueRegisterFindScopeGroupByName (const std::string &name)
 Seek for a TraceValueRegister by it's name. More...
 
TraceValueFindTraceValueByName (const std::string &name)
 Seek for a TraceValue by it's name. More...
 
TraceSetGetAllTraceValues (void)
 Get all here registered TraceValue's only (not with descending values) More...
 
TraceSetGetAllTraceValuesRecursive (void)
 Get all here registered TraceValue's with descending values. More...
 

Public Attributes

IOReg< HWSpispdr_reg
 
IOReg< HWSpispsr_reg
 
IOReg< HWSpispcr_reg
 

Private Member Functions

void updatePrescaler ()
 Takes info from registers and updates clkdiv. More...
 
void txbit (const int bitpos)
 Send/receive one bit. More...
 
void rxbit (const int bitpos)
 
void trxend ()
 Handle end of transmission if necessary. More...
 
void spdr_access ()
 Called for all SPDR access to clear the WCOL and SPIF flags if needed. More...
 

Private Attributes

unsigned char shift_in
 
unsigned char data_read
 
unsigned char data_write
 
unsigned char spsr
 
unsigned char spcr
 
AvrDevicecore
 
HWIrqSystemirq
 
PinAtPort MOSI
 
PinAtPort MISO
 
PinAtPort SCK
 
PinAtPort SS
 
unsigned int irq_vector
 
int clkdiv
 
bool spsr_read
 
bool oldsck
 
int bitcnt
 
unsigned clkcnt
 
bool mega_mode
 
bool finished
 finished transmission? More...
 

Additional Inherited Members

- Protected Member Functions inherited from TraceValueRegister
virtual size_t _tvr_getValuesCount (void)
 Get the count of all TraceValues, that are registered here and descending. More...
 
virtual void _tvr_insertTraceValuesToSet (TraceSet &t)
 Insert all TraceValues into TraceSet, that registered here and descending. More...
 

Detailed Description

Implements the I/O hardware necessary to do SPI transfers.

Definition at line 38 of file hwspi.h.

Constructor & Destructor Documentation

◆ HWSpi()

HWSpi::HWSpi ( AvrDevice core,
HWIrqSystem _irq,
PinAtPort  mosi,
PinAtPort  miso,
PinAtPort  sck,
PinAtPort  ss,
unsigned int  irq_vec,
bool  mega_mode = true 
)

Member Function Documentation

◆ ClearIrqFlag()

void HWSpi::ClearIrqFlag ( unsigned int  vector)
virtual

This signals the hardware that the given IRQ vector has been handled by the AVR core.

Reimplemented from Hardware.

Definition at line 200 of file hwspi.cpp.

References HWIrqSystem::ClearIrqFlag(), irq, irq_vector, SPIF, and spsr.

◆ CpuCycle()

unsigned int HWSpi::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 239 of file hwspi.cpp.

References bitcnt, clkcnt, clkdiv, core, CPHA, CPOL, DORD, finished, PinAtPort::GetDdr(), irq, irq_vector, MOSI, MSTR, oldsck, rxbit(), SCK, PinAtPort::SetAlternatePort(), HWIrqSystem::SetIrqFlag(), SetSPCR(), shift_in, spcr, SPE, SPI_VERBOSE, SPIE, SPIF, spsr, SS, AvrDevice::trace_on, traceOut, trxend(), and txbit().

◆ GetSPCR()

unsigned char HWSpi::GetSPCR ( )

Definition at line 77 of file hwspi.cpp.

◆ GetSPDR()

unsigned char HWSpi::GetSPDR ( )

Definition at line 67 of file hwspi.cpp.

◆ GetSPSR()

unsigned char HWSpi::GetSPSR ( )

Definition at line 72 of file hwspi.cpp.

◆ Reset()

void HWSpi::Reset ( void  )
virtual

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

Reimplemented from Hardware.

Definition at line 194 of file hwspi.cpp.

References data_read, data_write, SetSPCR(), shift_in, and spsr.

Referenced by HWSpi().

◆ rxbit()

void HWSpi::rxbit ( const int  bitpos)
private

Definition at line 215 of file hwspi.cpp.

References MISO, MOSI, MSTR, shift_in, and spcr.

Referenced by CpuCycle().

◆ SetSPCR()

void HWSpi::SetSPCR ( unsigned char  val)

Definition at line 120 of file hwspi.cpp.

References CPOL, Pin::HIGH, Pin::LOW, MSTR, and SPE.

Referenced by CpuCycle(), and Reset().

◆ SetSPDR()

void HWSpi::SetSPDR ( unsigned char  val)

Definition at line 81 of file hwspi.cpp.

References MSTR, and WCOL.

◆ SetSPSR()

void HWSpi::SetSPSR ( unsigned char  val)

Definition at line 106 of file hwspi.cpp.

References SPI2X, and traceOut.

◆ spdr_access()

void HWSpi::spdr_access ( )
private

Called for all SPDR access to clear the WCOL and SPIF flags if needed.

Definition at line 57 of file hwspi.cpp.

References SPIF, and WCOL.

◆ trxend()

void HWSpi::trxend ( )
private

Handle end of transmission if necessary.

Definition at line 222 of file hwspi.cpp.

References core, data_read, data_write, finished, irq, irq_vector, HWIrqSystem::SetIrqFlag(), shift_in, spcr, SPI_VERBOSE, SPIE, SPIF, spsr, spsr_read, AvrDevice::trace_on, and traceOut.

Referenced by CpuCycle().

◆ txbit()

void HWSpi::txbit ( const int  bitpos)
private

Send/receive one bit.

Definition at line 209 of file hwspi.cpp.

References data_write, MISO, MOSI, MSTR, PinAtPort::SetAlternatePort(), and spcr.

Referenced by CpuCycle().

◆ updatePrescaler()

void HWSpi::updatePrescaler ( )
private

Takes info from registers and updates clkdiv.

Definition at line 95 of file hwspi.cpp.

References SPI2X, SPR0, and SPR1.

Member Data Documentation

◆ bitcnt

int HWSpi::bitcnt
private

Bit counter counting from zero (start bit) to eight (idle).

Definition at line 75 of file hwspi.h.

Referenced by CpuCycle(), and HWSpi().

◆ clkcnt

unsigned HWSpi::clkcnt
private

Main clock cycles (will be divided to yield SPI clock cycles)

Definition at line 78 of file hwspi.h.

Referenced by CpuCycle().

◆ clkdiv

int HWSpi::clkdiv
private

Clock divider for SPI transfers; the system clock is divided by this amount before being fed to the state logic.

Definition at line 62 of file hwspi.h.

Referenced by CpuCycle().

◆ core

AvrDevice* HWSpi::core
private

Definition at line 51 of file hwspi.h.

Referenced by CpuCycle(), and trxend().

◆ data_read

unsigned char HWSpi::data_read
private

Contents which appear when SPDR is read.

Definition at line 45 of file hwspi.h.

Referenced by HWSpi(), Reset(), and trxend().

◆ data_write

unsigned char HWSpi::data_write
private

Byte to send, accessed by SPDR write.

Definition at line 47 of file hwspi.h.

Referenced by HWSpi(), Reset(), trxend(), and txbit().

◆ finished

bool HWSpi::finished
private

finished transmission?

Definition at line 86 of file hwspi.h.

Referenced by CpuCycle(), HWSpi(), and trxend().

◆ irq

HWIrqSystem* HWSpi::irq
private

Definition at line 52 of file hwspi.h.

Referenced by ClearIrqFlag(), CpuCycle(), HWSpi(), and trxend().

◆ irq_vector

unsigned int HWSpi::irq_vector
private

Definition at line 58 of file hwspi.h.

Referenced by ClearIrqFlag(), CpuCycle(), and trxend().

◆ mega_mode

bool HWSpi::mega_mode
private

mega mode: Iff true, the SPI2X option becomes available and SPSR will be R/W.

Definition at line 83 of file hwspi.h.

◆ MISO

PinAtPort HWSpi::MISO
private

Definition at line 55 of file hwspi.h.

Referenced by rxbit(), and txbit().

◆ MOSI

PinAtPort HWSpi::MOSI
private

Definition at line 54 of file hwspi.h.

Referenced by CpuCycle(), rxbit(), and txbit().

◆ oldsck

bool HWSpi::oldsck
private

Definition at line 72 of file hwspi.h.

Referenced by CpuCycle().

◆ SCK

PinAtPort HWSpi::SCK
private

Definition at line 56 of file hwspi.h.

Referenced by CpuCycle().

◆ shift_in

unsigned char HWSpi::shift_in
private

Register into which incoming data is shifted first before it ends in spdrRead (double buffer).

Definition at line 43 of file hwspi.h.

Referenced by CpuCycle(), HWSpi(), Reset(), rxbit(), and trxend().

◆ spcr

unsigned char HWSpi::spcr
private

Definition at line 49 of file hwspi.h.

Referenced by CpuCycle(), HWSpi(), rxbit(), trxend(), and txbit().

◆ spcr_reg

◆ spdr_reg

◆ spsr

unsigned char HWSpi::spsr
private

Definition at line 48 of file hwspi.h.

Referenced by ClearIrqFlag(), CpuCycle(), HWSpi(), Reset(), and trxend().

◆ spsr_read

bool HWSpi::spsr_read
private

If this is true, SPSR has been read (see for example ATmega 8 DS 10/06, p. 131

Definition at line 69 of file hwspi.h.

Referenced by trxend().

◆ spsr_reg

◆ SS

PinAtPort HWSpi::SS
private

Definition at line 57 of file hwspi.h.

Referenced by CpuCycle().


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