
/* ////////////////////////////////////////////////////////////////////////////
			      InitializeEeprom()
///////////////////////////////////////////////////////////////////////////////
DESCRIPTION:	This function is called once a boot time to initialize the
		EEPROM.

REVISIONS:	 6 Apr 07 - RAC - Genesis
//////////////////////////////////////////////////////////////////////////// */

void InitializeEeprom() {

    unsigned value;
    unsigned cell;

    if ((ReadCell(0, &value) != USED) ||
	(value != SIGNATURE_VALUE)) {		/* Invalid signature */
	for (cell=0;				/* Write default values to */
	     cell < DEFINED_CELLS;		/*  all the defined cells */
	     cell++) {
	    WriteCell(cell, EEMirror[cell]);
	    }
	for (cell = DEFINED_CELLS;		/* Mark all the undefined */
	     cell < MAX_CELLS;			/*  cells as unused */
	     cell++) {
	    WriteEepromWord(cell * 2, 0);
	    WriteEepromWord((cell * 2) + OFFSET, 0);
	    }
	}					/* End 'invalid signature' */
    else {					/* Valid signature */
	for (cell=0;				/* For each defined cell ... */
	     cell < DEFINED_CELLS;
	     cell++) {
	    switch(ReadCell(cell, &value)) {
		case USED:			/* If it looks good, copy */
		    EEMirror[cell] = value;	/*  its value into the RAM */
		    break;			/*  mirror */
		case UNUSED:			/* If it's never been */
		    WriteCell(cell,		/*  written, write it with */
			EEMirror[cell]);	/*  a default value right */
		    break;			/*  now */
		case CORRUPTED:			/* If it's corrupted, punt */
		    PostError(EEPROM_CHECK_ERROR);
		    break;
		}				/* End switch */
	    }					/* End 'for each def'd cell' */
	}					/* End 'valid signature' */
    }						/* End InitializeEeprom() */
