⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i557_eep.c

📁 基于ecos的redboot
💻 C
📖 第 1 页 / 共 2 页
字号:

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

    /* Send start/write enable command */
    if (((status = eeprom_send_start (pci_base, EEPROM_EWEN)) != OK) ||
  	  /* Send address */
   	  ((status = eeprom_send_addr (pci_base, EEPROM_EWEN_OP)) != 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);

    return (OK);
}

/*-------------------------------------------------------------
 * Function:	int eeprom_write_disable ()
 *
 * Action:	Disable writes to the eeprom
 *
 * Returns:	OK if command sent, EEPROM_NOT_RESPONDING if not.
 *
 *-------------------------------------------------------------*/
int eeprom_write_disable (unsigned long pci_base)
{
    int status;				/* result code */

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

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

    /* Send start/write enable command */
    if (((status = eeprom_send_start (pci_base, EEPROM_EWDS)) != OK) ||
    	/* Send address */
	 ((status = eeprom_send_addr (pci_base, EEPROM_EWDS_OP)) != 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);

    return (OK);
}


/******************************************************************************
*
* eeprom_delay - delay for a specified number of nanoseconds
*
* Note: this routine is a generous approximation as delays for eeproms
*       are specified as minimums.
*/
void eeprom_delay (int nsec)
{
	extern void polled_delay (int usec);

	/* generously delay 1 usec. for each nsec. */
	polled_delay (nsec);
}

/******************************************************************************
*
* eeprom_send_start - send a start bit with a read opcode to the '557 serial
*		      eeprom
*
*/
static int eeprom_send_start (unsigned long pci_base, int command)
{
    int op_code[2];

    switch (command)
    {
	case EEPROM_WRITE:
		op_code[0] = LOW;
		op_code[1] = HIGH;
		break;

	case EEPROM_READ:
		op_code[0] = HIGH;
		op_code[1] = LOW;
		break;

	case EEPROM_ERASE:
		op_code[0] = HIGH;
		op_code[1] = HIGH;
		break;

	case EEPROM_EWEN:
	case EEPROM_EWDS:
		op_code[0] = LOW;
		op_code[1] = LOW;
		break;

	default:
		return(EEPROM_INVALID_CMD);
    }

    set_scl_line (pci_base, LOW);
    set_sda_line (pci_base, HIGH);	/* start bit */
    eeprom_delay (DATA_IN_SETUP_TIME);
    set_scl_line (pci_base, HIGH);	/* clock high */
    eeprom_delay (SK_HIGH_PERIOD);
    set_scl_line (pci_base, LOW);	/* clock low */
    eeprom_delay (SK_LOW_PERIOD);

    /* send the opcode */
    set_sda_line (pci_base, op_code[0]);	/* MSB of opcode */
    eeprom_delay (DATA_IN_SETUP_TIME);
    set_scl_line (pci_base, HIGH);	/* clock high */
    eeprom_delay (SK_HIGH_PERIOD);
    set_scl_line (pci_base, LOW);	/* clock low */
    eeprom_delay (SK_LOW_PERIOD);
    set_sda_line (pci_base, op_code[1]);	/* LSB of opcode */
    eeprom_delay (DATA_IN_SETUP_TIME);
    set_scl_line (pci_base, HIGH);	/* clock high */
    eeprom_delay (SK_HIGH_PERIOD);
    set_scl_line (pci_base, LOW);	/* clock low */
    eeprom_delay (SK_LOW_PERIOD);

    return (OK);
}

/******************************************************************************
*
* eeprom_send_addr - send the read address to the '557 serial eeprom
*
*/
static int eeprom_send_addr (unsigned long pci_base,
			     unsigned char eeprom_addr)
{
    register int i;

    /* Do each address bit, MSB => LSB - after each address bit is
       sent, read the EEDO bit on the '557 to check for the "dummy 0 bit"
       which when set to 0, indicates that the address field is complete */
    for (i = 5; i >= 0; i--)
    {
        /* If this bit is a 1, set SDA high.  If 0, set it low */
        if (eeprom_addr & (1 << i))
            set_sda_line (pci_base, HIGH);
        else
            set_sda_line (pci_base, LOW);
 
        eeprom_delay (DATA_IN_SETUP_TIME); /* Data setup before raising clock */
        set_scl_line (pci_base, HIGH);     /* Clock in this data bit */
        eeprom_delay (SK_HIGH_PERIOD);
        set_scl_line (pci_base, LOW);	   /* Prepare for next bit */
        eeprom_delay (SK_LOW_PERIOD);

	/* check to see if "dummy 0 bit" is set to 0 indicating address
	   complete */
	if (get_sda_line (pci_base) == LOW)
	    break;			   /* address complete */
    }
    return (OK);
}

/******************************************************************************
*
* eeprom_get_word - read a 16 bit word from the '557 serial eeprom
*
* Note: this routine assumes that the start/opcode/address have already
*       been set up
*/
static int eeprom_get_word (unsigned long pci_base,
			    unsigned short *word_addr)
{
    register int i;
 
    /* Do each data bit, MSB => LSB */
    for (i = 15; i >= 0; i--)
    {
		set_scl_line (pci_base, HIGH);
        eeprom_delay (SK_HIGH_PERIOD);

		if (get_sda_line (pci_base) == HIGH)
			*word_addr |=  (1 << i);			/* store bit as a '1' */
		else
			*word_addr &= ~(1 << i);			/* store bit as a '0' */

		set_scl_line (pci_base, LOW);
        eeprom_delay (SK_LOW_PERIOD);
    }
    return (OK);
}

/******************************************************************************
*
* eeprom_put_word - write a 16 bit word to the '557 serial eeprom
*
* Note: this routine assumes that the start/opcode/address have already
*       been set up
*/
static int eeprom_put_word (unsigned long pci_base,
			    unsigned short data)
{
    register int i;
 
    /* Do each data bit, MSB => LSB */
    for (i = 15; i >= 0; i--)
    {
		if (data & (1 << i))
			set_sda_line(pci_base, HIGH);
		else
			set_sda_line(pci_base, LOW);

		eeprom_delay (DATA_IN_SETUP_TIME);
		set_scl_line (pci_base, HIGH);
        eeprom_delay (SK_HIGH_PERIOD);
		set_scl_line (pci_base, LOW);
        eeprom_delay (SK_LOW_PERIOD);
    }
    return (OK);
}

/*-------------------------------------------------------------
 * Function:	void set_scl_line ()
 *
 * Action:	Sets the value of the eeprom's serial clock line
 *		to the value HIGH or LOW.
 *
 * Returns:	N/A.
 *-------------------------------------------------------------*/
static void set_scl_line (unsigned long pci_base, /* PCI address */
			  int state)		  /* HIGH or LOW */
{
    if (state == HIGH)
	SK_HIGH_557_EEP (pci_base);
    else if (state == LOW)
	SK_LOW_557_EEP (pci_base);
}

/*-------------------------------------------------------------
 * Function:	void set_sda_line ()
 *
 * Action:	Sets the value of the eeprom's serial data line
 *		to the value HIGH or LOW.
 *
 * Returns:	N/A.
 *-------------------------------------------------------------*/
static void set_sda_line (unsigned long pci_base, /* PCI address */
			  int state)		  /* HIGH or LOW */
{
    if (state == HIGH)
		EEDI_HIGH_557_EEP (pci_base);
    else if (state == LOW)
		EEDI_LOW_557_EEP (pci_base);
}

/*-------------------------------------------------------------
 * Function:	int get_sda_line ()
 *
 * Action:	Returns the value of the eeprom's serial data line
 *
 * Returns:	HIGH or LOW.
 *-------------------------------------------------------------*/
static int get_sda_line (unsigned long pci_base) /* PCI address */
{
    int ret_val;				/* result code */

    if (EEDO_557_EEP (pci_base))
		ret_val = HIGH;
    else
		ret_val = LOW;

    return (ret_val);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -