DevEEPROM.cpp revision dc39465aaaca0e680ddcdb7690a984513047803e
/** @file
* Microware-compatible 64x16-bit 93C46 EEPROM Emulation.
*/
/*
* Copyright (C) 2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <string.h>
#include "DevEEPROM.h"
/**
* Construct EEPROM device.
*
* @param initial Initial EEPROM content (optional). The size of initial
* content must be sizeof(uint16_t)*EEPROM93C46::SIZE
* bytes.
*/
{
if ( initial ) {
} else {
}
writeEnabled = false;
internalWires = 0;
}
/**
* Writes one word to specified location if write is enabled.
*
* @param addr Address to write at
* @param value Value to store
*/
{
if (writeEnabled) {
}
}
/**
* Fetch next word pointer by 'addr'.
*
* 'addr' is advanced and mask is reset to support sequential reads.
*
* @returns New state
*/
{
return WRITING_DO;
}
/**
* Write the value of 'word' member to the location specified by 'addr' member.
*
* @returns New state
*
*/
{
return WAITING_CS_FALL;
}
/**
* Overwrite the entire contents of EEPROM with the value of 'word' member.
*
* @returns New state
*
*/
{
for (int i=0; i<SIZE; i++)
return WAITING_CS_FALL;
}
/**
* Decode opcode and address from 'opAddr' member.
*
* Decodes operation and executes it immediately if possible;
* otherwise, stores the decoded operation and address.
*
* @returns New state
*/
{
switch (word>>6) {
case 3: // ERASE
return WAITING_CS_FALL;
case 2: // READ
return opRead(); // Load first word
case 1: // WRITE
word = 0;
return READING_DI;
case 0:
switch (word>>4) {
writeEnabled = false;
return STANDBY;
case 1: // WRITE ALL
word = 0;
return READING_DI;
case 2: // ERASE ALL
// Re-use opWriteAll
word = 0xFFFF;
return opWriteAll();
writeEnabled = true;
return STANDBY;
}
}
return state;
}
/**
* Set bits in EEPROM 4-wire interface.
*
* @param wires Values of DI, CS, SK.
* @remarks The value of DO bit in 'wires' is ignored.
*/
{
// Positive edge of clock
state = READING_DI;
mask = OPADDR_MSB;
word = 0;
}
}
else {
if (state == READING_DI) {
}
}
else if (state == WRITING_DO) {
internalWires &= ~DO;
internalWires |= DO;
}
}
else return;
// Next bit
mask >>= 1;
if (mask == 0)
}
}
else if (state == WAITING_CS_RISE) {
}
}
else {
switch(state) {
case WAITING_CS_RISE: break;
}
}
internalWires &= DO;
}
/**
* Read bits in EEPROM 4-wire interface.
*
* @returns Current values of DO, DI, CS, SK.
*
* @remarks Only DO is controlled by EEPROM, other bits are returned as they
* were written by 'write'.
*/
{
return internalWires;
}