/*! ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers Copyright (C) 2009-2014 ZTEX GmbH. http://www.ztex.de This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/. !*/ /* EEPROM support an some I2C helper routines */ #ifndef[ZTEX_EEPROM_H] #define[ZTEX_EEPROM_H] #define[@CAPABILITY_EEPROM;] #define[EEPROM_ADDR][0xA2] /* ********************************************************************* ***** global variables ********************************************** ********************************************************************* */ __xdata WORD eeprom_addr; __xdata WORD eeprom_write_bytes; __xdata BYTE eeprom_write_checksum; /* ********************************************************************* ***** i2c_waitWrite ************************************************* ********************************************************************* */ /* Do the necessary steps after writing I2DAT register. Returns 1 on error. */ BYTE i2c_waitWrite() { unsigned char i2csbuf,toc; for ( toc=0; toc<255 && !(I2CS & bmBIT0); toc++ ); i2csbuf = I2CS; if ( (i2csbuf & bmBIT2) || (!(i2csbuf & bmBIT1)) ) { I2CS |= bmBIT6; return 1; } return 0; } /* ********************************************************************* ***** i2c_waitRead ************************************************** ********************************************************************* */ /* Do the necessary steps after reading I2DAT register. Returns 1 on error. */ BYTE i2c_waitRead(void) { unsigned char i2csbuf, toc; for ( toc=0; toc<255 && !(I2CS & bmBIT0); toc++ ); i2csbuf = I2CS; if (i2csbuf & bmBIT2) { I2CS |= bmBIT6; return 1; } return 0; } /* ********************************************************************* ***** i2c_waitStart ************************************************* ********************************************************************* */ /* Do the necessary steps after start bit. Returns 1 on error. */ BYTE i2c_waitStart() { BYTE toc; for ( toc=0; toc<255; toc++ ) { if ( ! (I2CS & bmBIT2) ) return 0; } return 1; } /* ********************************************************************* ***** i2c_waitStop ************************************************** ********************************************************************* */ /* Do the necessary steps after stop bit. Returns 1 on error. */ BYTE i2c_waitStop() { BYTE toc; for ( toc=0; toc<255; toc++ ) { if ( ! (I2CS & bmBIT6) ) return 0; } return 1; } /* ********************************************************************* ***** eeprom_select ************************************************* ********************************************************************* */ /* Select the EEPROM device, i.e. send the control Byte. specifies the time to wait in 0.1ms steps if the EEPROM is busy (during a write cycle). if =0 no sop bit is sent. Returns 1 on error or if EEPROM is busy. */ BYTE eeprom_select (BYTE addr, BYTE to, BYTE stop ) { BYTE toc = 0; eeprom_select_start: I2CS |= bmBIT7; // start bit i2c_waitStart(); I2DAT = addr; // select device for writing if ( ! i2c_waitWrite() ) { if ( stop ) { I2CS |= bmBIT6; i2c_waitStop(); } return 0; } else if (toc bytes from EEPROM address and write them to buf. Returns the number of bytes read. */ BYTE eeprom_read ( __xdata BYTE *buf, WORD addr, BYTE length ) { BYTE bytes = 0,i; if ( length == 0 ) return 0; if ( eeprom_select(EEPROM_ADDR, 100,0) ) goto eeprom_read_end; I2DAT = HI(addr); // write address if ( i2c_waitWrite() ) goto eeprom_read_end; I2DAT = LO(addr); // write address if ( i2c_waitWrite() ) goto eeprom_read_end; I2CS |= bmBIT6; i2c_waitStop(); I2CS |= bmBIT7; // start bit i2c_waitStart(); I2DAT = EEPROM_ADDR | 1; // select device for reading if ( i2c_waitWrite() ) goto eeprom_read_end; *buf = I2DAT; // dummy read if ( i2c_waitRead()) goto eeprom_read_end; for (; bytes bytes from buf to EEPROM address . must be smaller or equal than 8. Returns the number of bytes read. */ BYTE eeprom_write ( __xdata BYTE *buf, WORD addr, BYTE length ) { BYTE bytes = 0; if ( length == 0 ) return 0; if ( eeprom_select(EEPROM_ADDR, 100,0) ) goto eeprom_write_end; I2DAT = HI(addr); // write address if ( i2c_waitWrite() ) goto eeprom_write_end; I2DAT = LO(addr); // write address if ( i2c_waitWrite() ) goto eeprom_write_end; for (; bytes bytes from EEPROM address and write them to buf. Returns the number of bytes read. */ BYTE mac_eeprom_read ( __xdata BYTE *buf, BYTE addr, BYTE length ) { BYTE bytes = 0,i; if ( length == 0 ) return 0; if ( eeprom_select(EEPROM_MAC_ADDR, 100,0) ) goto mac_eeprom_read_end; I2DAT = addr; // write address if ( i2c_waitWrite() ) goto mac_eeprom_read_end; I2CS |= bmBIT6; i2c_waitStop(); I2CS |= bmBIT7; // start bit i2c_waitStart(); I2DAT = EEPROM_MAC_ADDR | 1; // select device for reading if ( i2c_waitWrite() ) goto mac_eeprom_read_end; *buf = I2DAT; // dummy read if ( i2c_waitRead()) goto mac_eeprom_read_end; for (; bytes bytes from buf to and write them EEPROM address . must be smaller or equal than 8. Returns the number of bytes written. */ BYTE mac_eeprom_write ( __xdata BYTE *buf, BYTE addr, BYTE length ) { BYTE bytes = 0; if ( length == 0 ) return 0; if ( eeprom_select(EEPROM_MAC_ADDR, 100,0) ) goto mac_eeprom_write_end; I2DAT = addr; // write address if ( i2c_waitWrite() ) goto mac_eeprom_write_end; while ( bytesError running this command: diff -w -U 5 "/tmp/hSrBdo" ""

diff: : No such file or directory