📄 eeprom.c
字号:
return BSP_OK;#endif /*CCA_146*/ } else { DEBUGEP(("eepromWrite: offset out of range\n")); return (BSP_ERROR); }}#if !(defined(CCA_145) || defined(CCA_146))/******************************************************************************** ipmEepromRead - Read from IPM EEPROM** DESCRIPTION:** INPUT:* None** RETURN:********************************************************************************/BSP_STATUS ipmEepromRead(unsigned int offset, unsigned char *data, unsigned int byteCount){ unsigned int status; unsigned int timeoutValue = 0; DEBUGMP(("ipm eeprom read\n")); if (byteCount > EEPROM_PAGE_SIZE) { DEBUGEP(("ipmEepromRead: cant read more than 16 bytes at a time.\n")); return(BSP_ERROR); } if ((offset >= EEPROM_BANK0_OFFSET) && ( offset <= EEPROM_BANK0_MAX_OFFSET)) { status = dy4I2cMasterRead(I2C_EEPROM, I2C_IPM_EEPROM_ADDR, offset, data, byteCount); timeoutValue++; while (status != STAT_I2C_OK) { if(timeoutValue >= MAX_TIMEOUT) { return BSP_ERROR; } DEBUGMP(("retrying ipm eeprom read...\n")); taskDelay(1); status = dy4I2cMasterRead(I2C_EEPROM, I2C_IPM_EEPROM_ADDR, offset, data, byteCount); timeoutValue++; } return BSP_OK; } else if ((offset >= EEPROM_BANK1_OFFSET) && ( offset <= EEPROM_BANK1_MAX_OFFSET)) { status = dy4I2cMasterRead(I2C_EEPROM, I2C_IPM_EEPROM_ADDR + I2C_EEPROM_BANK1_ADDR, offset - EEPROM_BANK1_OFFSET, data, byteCount); timeoutValue++; while (status != STAT_I2C_OK) { if(timeoutValue >= MAX_TIMEOUT) { DEBUGEP(("ipmEepromRead: exceeded read retries.\n")); return BSP_ERROR; } DEBUGMP(("ipmEepromRead: retrying eeprom read...\n")); taskDelay(1); status = dy4I2cMasterRead(I2C_EEPROM, I2C_IPM_EEPROM_ADDR + I2C_EEPROM_BANK1_ADDR, offset - EEPROM_BANK1_OFFSET, data, byteCount); timeoutValue++; } return BSP_OK; } else { DEBUGEP(("ipmEepromRead: offset out of range\n")); return (BSP_ERROR); }}/******************************************************************************** ipmEepromWrite - Write to IPM EEPROM** DESCRIPTION:** INPUT:* None** RETURN:********************************************************************************/BSP_STATUS ipmEepromWrite(unsigned int offset, unsigned char *data, unsigned int byteCount){ unsigned int status; unsigned int timeoutValue = 0; DEBUGEP(("ipm eeprom write\n")); if (byteCount > EEPROM_PAGE_SIZE) { DEBUGEP(("ipmEepromWrite: cant write more than 16 bytes at a time.\n")); return(BSP_ERROR); } if ((offset >= EEPROM_BANK0_OFFSET) && ( offset <= EEPROM_BANK0_MAX_OFFSET)) { status = dy4I2cMasterWrite(I2C_EEPROM, I2C_IPM_EEPROM_ADDR, offset, data, byteCount); timeoutValue++; while (status != STAT_I2C_OK) { if(timeoutValue >= MAX_TIMEOUT) { return BSP_ERROR; } DEBUGEP(("retrying ipm eeprom write...\n")); taskDelay(1); status = dy4I2cMasterWrite(I2C_EEPROM, I2C_IPM_EEPROM_ADDR, offset, data, byteCount); timeoutValue++; } return BSP_OK; } else if ((offset >= EEPROM_BANK1_OFFSET) && ( offset <= EEPROM_BANK1_MAX_OFFSET)) { status = dy4I2cMasterWrite(I2C_EEPROM, I2C_IPM_EEPROM_ADDR + I2C_EEPROM_BANK1_ADDR, offset - EEPROM_BANK1_OFFSET, data, byteCount); timeoutValue++; while (status != STAT_I2C_OK) { if(timeoutValue >= MAX_TIMEOUT) { DEBUGEP(("ipmEepromWrite: exceeded write retries.\n")); return BSP_ERROR; } DEBUGMP(("ipmEepromWrite: eeprom write retry...\n")); taskDelay(1); status = dy4I2cMasterWrite(I2C_EEPROM, I2C_IPM_EEPROM_ADDR + I2C_EEPROM_BANK1_ADDR, offset - EEPROM_BANK1_OFFSET, data, byteCount); timeoutValue++; } return BSP_OK; } else { DEBUGEP(("ipmEepromWrite: offset out of range\n")); return (BSP_ERROR); }}#endif/****************************************************************************** eepromInit - init the eeprom driver** DESCRIPTION: Stub function to link the eeprom.o object.** INPUT:* None** RETURN: always OK******************************************************************************/BSP_STATUS eepromInit(void){return(OK) ;}#ifdef CCA_146/****************************************************************************** sysSerialNumberGet - Get the board's serial number from the eeprom** DESCRIPTION: This function calls eepromRead() to read offset 256 to get the* serial number of the board.* INPUT:* unsigned char *snData : buffer to return the serial number.** RETURN: BSP_OK or BSP_ERROR if EEPROM read fails.******************************************************************************/BSP_STATUS sysSerialNumberGet(unsigned char *snData){ unsigned int status; /* Read SN from EEPROM */ status = eepromRead((unsigned int)CCA146_SN_EEPROM_OFFSET, snData, (unsigned int)CCA146_SN_SIZE); if (status != BSP_OK) { DEBUGEP(("ERROR: Could not Read SN from the EEPROM\n")); return(BSP_ERROR); } DEBUGMP(("The Borads Serial Number is SN=%.7s\n",(char *)snData)); return(BSP_OK);}/****************************************************************************** sysSerialNumberShow - Show the board's serial number stored in the eeprom** DESCRIPTION: This function prints the board's serial number stored in the eeprom** INPUT:* NONE** RETURN: BSP_OK or BSP_ERROR if EEPROM read fails.******************************************************************************/BSP_STATUS sysSerialNumberShow(void){ unsigned int status; char * snData; snData = malloc(CCA146_SN_SIZE+1); /* Read SN from EEPROM */ status = eepromRead((unsigned int)CCA146_SN_EEPROM_OFFSET, snData, (unsigned int)CCA146_SN_SIZE); if (status != BSP_OK) { DEBUGEP(("ERROR: Could not Read SN from the EEPROM\n")); free(snData); return(BSP_ERROR); } printf("The Borads Serial Number is SN=%.7s\n",(char *)snData); free(snData); return(BSP_OK);}#endif /*CCA_146*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -