HWSpi Class Reference

#include <hwspi.h>

Inheritance diagram for HWSpi:
Inheritance graph
[legend]
Collaboration diagram for HWSpi:
Collaboration graph
[legend]

List of all members.

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 Attributes

IOReg< HWSpispdr_reg
IOReg< HWSpispsr_reg
IOReg< HWSpispcr_reg

Private Member Functions

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

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
int spi_cycles
bool mega_mode
bool finished
 finished transmission?

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 ( AvrDevice core,
HWIrqSystem _irq,
PinAtPort  mosi,
PinAtPort  miso,
PinAtPort  sck,
PinAtPort  ss,
unsigned int  irq_vec,
bool  mega_mode = true 
)

Definition at line 166 of file hwspi.cpp.

References bitcnt, data_read, data_write, HWIrqSystem::DebugVerifyInterruptVector(), finished, irq, Reset(), shift_in, spcr, spsr, and trace_direct().

Here is the call graph for this function:


Member Function Documentation

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.

Here is the call graph for this function:

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().

Here is the call graph for this function:

unsigned char HWSpi::GetSPCR (  ) 

Definition at line 77 of file hwspi.cpp.

References spcr.

unsigned char HWSpi::GetSPDR (  ) 

Definition at line 67 of file hwspi.cpp.

References data_read, and spdr_access().

Here is the call graph for this function:

unsigned char HWSpi::GetSPSR (  ) 

Definition at line 72 of file hwspi.cpp.

References spsr, and spsr_read.

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

void HWSpi::SetSPCR ( unsigned char  val  ) 
void HWSpi::SetSPDR ( unsigned char  val  ) 

Definition at line 81 of file hwspi.cpp.

References bitcnt, clkcnt, data_write, finished, MSTR, spcr, spdr_access(), spsr, and WCOL.

Here is the call graph for this function:

void HWSpi::SetSPSR ( unsigned char  val  ) 

Definition at line 106 of file hwspi.cpp.

References core, AvrDevice::Flash, Memory::GetSymbolAtAddress(), mega_mode, AvrDevice::PC, SPI2X, spsr, AvrDevice::trace_on, traceOut, and updatePrescaler().

Here is the call graph for this function:

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, spsr, spsr_read, and WCOL.

Referenced by GetSPDR(), and SetSPDR().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

void HWSpi::updatePrescaler (  )  [private]

Takes info from registers and updates clkdiv.

Definition at line 95 of file hwspi.cpp.

References clkdiv, spcr, SPI2X, SPR0, SPR1, and spsr.

Referenced by SetSPCR(), and SetSPSR().

Here is the caller graph for this function:


Member Data Documentation

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(), HWSpi(), SetSPCR(), and SetSPDR().

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(), and SetSPDR().

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(), and updatePrescaler().

AvrDevice* HWSpi::core [private]

Definition at line 51 of file hwspi.h.

Referenced by CpuCycle(), SetSPCR(), SetSPSR(), and trxend().

unsigned char HWSpi::data_read [private]

Contents which appear when SPDR is read.

Definition at line 45 of file hwspi.h.

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

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(), SetSPDR(), trxend(), and txbit().

bool HWSpi::finished [private]

finished transmission?

Definition at line 89 of file hwspi.h.

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

HWIrqSystem* HWSpi::irq [private]

Definition at line 52 of file hwspi.h.

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

unsigned int HWSpi::irq_vector [private]

Definition at line 58 of file hwspi.h.

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

bool HWSpi::mega_mode [private]

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

Definition at line 86 of file hwspi.h.

Referenced by SetSPSR().

Definition at line 55 of file hwspi.h.

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

Definition at line 54 of file hwspi.h.

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

bool HWSpi::oldsck [private]

Definition at line 72 of file hwspi.h.

Referenced by CpuCycle().

PinAtPort HWSpi::SCK [private]

Definition at line 56 of file hwspi.h.

Referenced by CpuCycle(), and SetSPCR().

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().

unsigned char HWSpi::spcr [private]

Definition at line 49 of file hwspi.h.

Referenced by CpuCycle(), GetSPCR(), HWSpi(), rxbit(), SetSPCR(), SetSPDR(), trxend(), txbit(), and updatePrescaler().

int HWSpi::spi_cycles [private]

Definition at line 81 of file hwspi.h.

unsigned char HWSpi::spsr [private]
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 GetSPSR(), spdr_access(), and trxend().

PinAtPort HWSpi::SS [private]

Definition at line 57 of file hwspi.h.

Referenced by CpuCycle(), and SetSPCR().


The documentation for this class was generated from the following files:
Generated on Sun Feb 12 16:51:49 2012 for Simulavr by  doxygen 1.6.3