void eeprom_write_byte(unsigned char *addr, unsigned char val)
{
    eeprom_write_enable();

    eeprom_generic_write(addr, val);

    eeprom_write_disable();
}
void eeprom_write_block(const void *buf, void *addr, size_t n)
{
    unsigned char *p, *s;

    p = (unsigned char *) addr;
    s = (unsigned char *) buf;

    eeprom_write_enable();

    while (n-- > 0)
        eeprom_generic_write(p++, *(s++));

    eeprom_write_disable();
}
void eeprom_erase_all(void)
{
    signed char i;
    unsigned short cmd;

    eeprom_write_enable();

    eeprom_enable();

    cmd = 0x0900;
    for (i = 11; i >= 0; --i)
        eeprom_pulse(EEPROM_MASK(cmd, bitmask[i]));

    eeprom_disable();

    eeprom_enable();
    while (EEPROM_DO == 0);
    eeprom_disable();

    eeprom_write_disable();
}
void eeprom_erase(unsigned char *addr)
{
    signed char i;
    unsigned short cmd;

    eeprom_write_enable();

    eeprom_enable();

    cmd = 0x0e00 | (size_t) addr;
    for (i = 11; i >= 0; --i)
        eeprom_pulse(EEPROM_MASK(cmd, bitmask[i]));

    eeprom_disable();

    eeprom_enable();
    while (EEPROM_DO == 0);
    eeprom_disable();

    eeprom_write_disable();
}
void eeprom_fill_all(const unsigned char c)
{
    signed char i;
    unsigned short cmd;

    eeprom_write_enable();

    eeprom_enable();

    cmd = 0x0880;
    for (i = 11; i >= 0; --i)
        eeprom_pulse(EEPROM_MASK(cmd, bitmask[i]));

    for (i = 7; i >= 0; --i)
        eeprom_pulse(EEPROM_MASK(c, bitmask[i]));

    eeprom_disable();

    eeprom_enable();
    while (EEPROM_DO == 0);
    eeprom_disable();

    eeprom_write_disable();
}
示例#6
0
/*-------------------------------------------------------------
 * Function:	int eeprom_write ()
 *
 * Action:	Write data from p_data to the eeprom
 *
 * Returns:	OK if write worked, EEPROM_NOT_RESPONDING if
 *		write failed.
 *-------------------------------------------------------------*/
int eeprom_write (unsigned long pci_base,/* PCI Base address */
		 int eeprom_addr,	/* word offset from start of eeprom */
		 unsigned short *p_data,/* data source in memory */
		 int nwords		/* number of 16bit words to read */
		 )
{
    int status;				/* result code */
    int i;					/* loop variable */
	int check_cntr;
    unsigned short data;

    /*
     * Make sure caller isn't requesting a read beyond the end of the 
     * eeprom.
     */
    if ((eeprom_addr + nwords) > EEPROM_WORD_SIZE)
	return (EEPROM_TO_SMALL);
    
    /* enable eeprom writes */
    if ((status = eeprom_write_enable(pci_base)) != OK)
	return(status);

    /* Read in desired number of words */
    for (i = 0; i < nwords; i++, eeprom_addr++)
    {
     	/* Select the serial EEPROM */
    	SELECT_557_EEP(pci_base);

		/* Wait CS setup time */
		eeprom_delay (SELECT_SETUP_TIME);

    	/* Send start/write command to begin the read */
    	if (((status = eeprom_send_start (pci_base, EEPROM_WRITE)) != OK) ||
    	/* Send address */
			((status = eeprom_send_addr (pci_base, eeprom_addr)) != OK))
			return (status);

		data = *p_data++;
		if ((status = eeprom_put_word (pci_base, data)) != OK)
			return (status);

    	/* De-Select the serial EEPROM */
    	DESELECT_557_EEP(pci_base);

		/* wait the required de-select time between commands */
		eeprom_delay (DESELECT_TIME);

		/* Re-Select the serial EEPROM */
    	SELECT_557_EEP(pci_base);

		/* now that the write command/data have been clocked into the EEPROM
		   we must wait for the BUSY indicator (DO driven low) to indicate
		   READY (DO driven high) */
		check_cntr = 0;

		while (1)
		{
			check_cntr++;

			if (get_sda_line (pci_base) == HIGH) break;		/* programming complete */

			if (check_cntr > 100000)						/* timeout */
			{
				/* De-Select the serial EEPROM */
    			DESELECT_557_EEP(pci_base);
				/* wait the required de-select time between commands */
				eeprom_delay (DESELECT_TIME);

				return (EEPROM_ERROR);
			}
		}

		/* De-Select the serial EEPROM */
    	DESELECT_557_EEP(pci_base);

		/* wait the required de-select time between commands */
		eeprom_delay (DESELECT_TIME);
    }

    /* disable eeprom writes */
    if ((status = eeprom_write_disable(pci_base)) != OK)
	return(status);

    return (OK);
}