2014-10-18 11:33:48 +00:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <SpiRAM.h>
|
|
|
|
#include "memory.h"
|
|
|
|
#include "spiram.h"
|
|
|
|
#include "hardware.h"
|
|
|
|
|
|
|
|
extern SPIClass SPIRAM_DEV;
|
|
|
|
|
|
|
|
SpiRAM spiRam(SPIRAM_DEV, SPIRAM_CS);
|
|
|
|
|
|
|
|
void spiram::begin(byte cs, int module)
|
|
|
|
{
|
2014-10-22 18:47:06 +00:00
|
|
|
SPI_for_SD.setModule(module);
|
|
|
|
SPI_for_SD.setClockDivider(SPI_CLOCK_DIV16);
|
|
|
|
SPI_for_SD.setDataMode(SPI_MODE0);
|
|
|
|
pinMode(PF_3, OUTPUT);
|
|
|
|
pinMode(cs, OUTPUT);
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void spiram::operator=(byte b)
|
|
|
|
{
|
2014-10-22 18:47:06 +00:00
|
|
|
spiRam.write_byte(_acc, b);
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spiram::operator byte()
|
|
|
|
{
|
2014-10-22 18:47:06 +00:00
|
|
|
return spiRam.read_byte(_acc);
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void spiram::checkpoint(Stream &s)
|
|
|
|
{
|
2014-10-22 18:47:06 +00:00
|
|
|
char buf[Memory::page_size];
|
|
|
|
for (int i = 0; i < pages(); i++) {
|
|
|
|
spiRam.read_stream(i * 256, buf, sizeof(buf));
|
|
|
|
s.write((byte *)buf, sizeof(buf));
|
|
|
|
}
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void spiram::restore(Stream &s)
|
|
|
|
{
|
2014-10-22 18:47:06 +00:00
|
|
|
char buf[Memory::page_size];
|
|
|
|
for (int i = 0; i < pages(); i++) {
|
|
|
|
s.readBytes(buf, sizeof(buf));
|
|
|
|
spiRam.write_stream(i * 256, buf, sizeof(buf));
|
|
|
|
}
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|