📄 addi_eeprom.c
字号:
| Function Name : VOID v_EepromWaitBusy || (WORD w_PCIBoardEepromAddress) |+----------------------------------------------------------------------------+| Task : Wait the busy flag from PCI controller |+----------------------------------------------------------------------------+| Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom base address |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value : - |+----------------------------------------------------------------------------+*/VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress) { BYTE b_EepromBusy = 0; do { /*************/ /* IMPORTANT */ /*************/ /************************************************************************/ /* An error has been written in the AMCC 5933 book at the page B-13*/ /* Ex: if you read a byte and look for the busy statusEEPROM=0x80 and */ /* the operator register is AMCC_OP_REG_MCSR+3*/ /* WORD read EEPROM=0x8000 andAMCC_OP_REG_MCSR+2 */ /* DWORD read EEPROM=0x80000000 and AMCC_OP_REG_MCSR */ /************************************************************************/ b_EepromBusy = inb(w_PCIBoardEepromAddress + 0x3F); b_EepromBusy = b_EepromBusy &0x80; } while(b_EepromBusy == 0x80); }/*+---------------------------------------------------------------------------------+| Function Name : VOID v_EepromClock76(DWORD dw_Address, || DWORD dw_RegisterValue) |+---------------------------------------------------------------------------------+| Task : This function sends the clocking sequence to the EEPROM. |+---------------------------------------------------------------------------------+| Input Parameters : DWORD dw_Address : PCI eeprom base address || DWORD dw_RegisterValue : PCI eeprom register value to write.|+---------------------------------------------------------------------------------+| Output Parameters : - |+---------------------------------------------------------------------------------+| Return Value : - |+---------------------------------------------------------------------------------+*/VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue) { /************************/ /* Set EEPROM clock Low */ /************************/ outl(dw_RegisterValue & 0x6,dw_Address); /***************/ /* Wait 0.1 ms */ /***************/ udelay(100); /*************************/ /* Set EEPROM clock High */ /*************************/ outl(dw_RegisterValue | 0x1,dw_Address); /***************/ /* Wait 0.1 ms */ /***************/ udelay(100); }/*+---------------------------------------------------------------------------------+| Function Name : VOID v_EepromSendCommand76(DWORD dw_Address, || DWORD dw_EepromCommand, || BYTE b_DataLengthInBits) |+---------------------------------------------------------------------------------+| Task : This function sends a Command to the EEPROM 93C76. |+---------------------------------------------------------------------------------+| Input Parameters : DWORD dw_Address : PCI eeprom base address || DWORD dw_EepromCommand : PCI eeprom command to write. || BYTE b_DataLengthInBits : PCI eeprom command data length. |+---------------------------------------------------------------------------------+| Output Parameters : - |+---------------------------------------------------------------------------------+| Return Value : - |+---------------------------------------------------------------------------------+*/VOID v_EepromSendCommand76(DWORD dw_Address,DWORD dw_EepromCommand,BYTE b_DataLengthInBits) { CHAR c_BitPos = 0; DWORD dw_RegisterValue = 0; /*****************************/ /* Enable EEPROM Chip Select */ /*****************************/ dw_RegisterValue = 0x2; /********************************************************************/ /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ /********************************************************************/ outl(dw_RegisterValue,dw_Address); /***************/ /* Wait 0.1 ms */ /***************/ udelay(100); /*******************************************/ /* Send EEPROM command - one bit at a time */ /*******************************************/ for (c_BitPos = (b_DataLengthInBits - 1); c_BitPos >= 0; c_BitPos--) { /**********************************/ /* Check if current bit is 0 or 1 */ /**********************************/ if (dw_EepromCommand & (1 << c_BitPos)) { /***********/ /* Write 1 */ /***********/ dw_RegisterValue = dw_RegisterValue | 0x4; } else { /***********/ /* Write 0 */ /***********/ dw_RegisterValue = dw_RegisterValue & 0x3; } /*********************/ /* Write the command */ /*********************/ outl(dw_RegisterValue,dw_Address); /***************/ /* Wait 0.1 ms */ /***************/ udelay(100); /****************************/ /* Trigger the EEPROM clock */ /****************************/ v_EepromClock76(dw_Address, dw_RegisterValue); } }/*+---------------------------------------------------------------------------------+| Function Name : VOID v_EepromCs76Read(DWORD dw_Address, || WORD w_offset, || PWORD pw_Value) |+---------------------------------------------------------------------------------+| Task : This function read a value from the EEPROM 93C76. |+---------------------------------------------------------------------------------+| Input Parameters : DWORD dw_Address : PCI eeprom base address || WORD w_offset : Offset of the adress to read || PWORD pw_Value : PCI eeprom 16 bit read value. |+---------------------------------------------------------------------------------+| Output Parameters : - |+---------------------------------------------------------------------------------+| Return Value : - |+---------------------------------------------------------------------------------+*/VOID v_EepromCs76Read(DWORD dw_Address,WORD w_offset,PWORD pw_Value) { CHAR c_BitPos = 0; DWORD dw_RegisterValue = 0; DWORD dw_RegisterValueRead = 0; /*************************************************/ /* Send EEPROM read command and offset to EEPROM */ /*************************************************/ v_EepromSendCommand76(dw_Address, (EE_READ << 4) | (w_offset / 2), EE76_CMD_LEN); /*******************************/ /* Get the last register value */ /*******************************/ dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | 0x2; /*****************************/ /* Set the 16-bit value of 0 */ /*****************************/ *pw_Value = 0; /************************/ /* Get the 16-bit value */ /************************/ for (c_BitPos = 0; c_BitPos < 16; c_BitPos++) { /****************************/ /* Trigger the EEPROM clock */ /****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -