#include <hwspi.h>
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< HWSpi > | spdr_reg |
IOReg< HWSpi > | spsr_reg |
IOReg< HWSpi > | spcr_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 |
AvrDevice * | core |
HWIrqSystem * | irq |
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? |
Implements the I/O hardware necessary to do SPI transfers.
Definition at line 38 of file hwspi.h.
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().
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.
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().
unsigned char HWSpi::GetSPDR | ( | ) |
Definition at line 67 of file hwspi.cpp.
References data_read, and spdr_access().
unsigned char HWSpi::GetSPSR | ( | ) |
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().
void HWSpi::rxbit | ( | const int | bitpos | ) | [private] |
void HWSpi::SetSPCR | ( | unsigned char | val | ) |
Definition at line 120 of file hwspi.cpp.
References AvrDevice::AddToCycleList(), bitcnt, core, CPOL, finished, PinAtPort::GetPin(), Pin::HIGH, Pin::LOW, MISO, MOSI, MSTR, Pin::outState, AvrDevice::RemoveFromCycleList(), SCK, PinAtPort::SetAlternateDdr(), PinAtPort::SetAlternatePort(), PinAtPort::SetUseAlternateDdr(), PinAtPort::SetUseAlternatePortIfDdrSet(), spcr, SPE, SS, and updatePrescaler().
Referenced by CpuCycle(), and Reset().
void HWSpi::SetSPDR | ( | unsigned char | val | ) |
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().
void HWSpi::spdr_access | ( | ) | [private] |
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().
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().
void HWSpi::updatePrescaler | ( | ) | [private] |
int HWSpi::bitcnt [private] |
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] |
unsigned char HWSpi::data_read [private] |
unsigned char HWSpi::data_write [private] |
bool HWSpi::finished [private] |
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] |
PinAtPort HWSpi::MISO [private] |
PinAtPort HWSpi::MOSI [private] |
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] |
unsigned char HWSpi::spcr [private] |
Definition at line 124 of file hwspi.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_at90s8515::AvrDevice_at90s8515(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), AvrDevice_atmega16_32::AvrDevice_atmega16_32(), AvrDevice_atmega668base::AvrDevice_atmega668base(), and AvrDevice_atmega8::AvrDevice_atmega8().
Definition at line 124 of file hwspi.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_at90s8515::AvrDevice_at90s8515(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), AvrDevice_atmega16_32::AvrDevice_atmega16_32(), AvrDevice_atmega668base::AvrDevice_atmega668base(), and AvrDevice_atmega8::AvrDevice_atmega8().
int HWSpi::spi_cycles [private] |
unsigned char HWSpi::spsr [private] |
Definition at line 48 of file hwspi.h.
Referenced by ClearIrqFlag(), CpuCycle(), GetSPSR(), HWSpi(), Reset(), SetSPDR(), SetSPSR(), spdr_access(), trxend(), and updatePrescaler().
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().
Definition at line 124 of file hwspi.h.
Referenced by AvrDevice_at90canbase::AvrDevice_at90canbase(), AvrDevice_at90s8515::AvrDevice_at90s8515(), AvrDevice_atmega128::AvrDevice_atmega128(), AvrDevice_atmega1284Abase::AvrDevice_atmega1284Abase(), AvrDevice_atmega16_32::AvrDevice_atmega16_32(), AvrDevice_atmega668base::AvrDevice_atmega668base(), and AvrDevice_atmega8::AvrDevice_atmega8().
Definition at line 57 of file hwspi.h.
Referenced by CpuCycle(), and SetSPCR().