OpenCores
URL https://opencores.org/ocsvn/usb_fpga_1_15/usb_fpga_1_15/trunk

Subversion Repositories usb_fpga_1_15

[/] [usb_fpga_1_15/] [trunk/] [include/] [ztex-eeprom.h] - Diff between revs 2 and 3

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 3
Line 125... Line 125...
 
 
/* *********************************************************************
/* *********************************************************************
   ***** eeprom_read ***************************************************
   ***** eeprom_read ***************************************************
   ********************************************************************* */
   ********************************************************************* */
/* Reads <length> bytes from EEPROM address <addr> and write them to buf.
/* Reads <length> bytes from EEPROM address <addr> and write them to buf.
   Returns the number of bytes read. This number is 0 during a write cycle. */
   Returns the number of bytes read. */
BYTE eeprom_read ( __xdata BYTE *buf, WORD addr, BYTE length ) {
BYTE eeprom_read ( __xdata BYTE *buf, WORD addr, BYTE length ) {
    BYTE bytes = 0,i;
    BYTE bytes = 0,i;
 
 
    if ( length == 0 )
    if ( length == 0 )
        return 0;
        return 0;
Line 172... Line 172...
/* *********************************************************************
/* *********************************************************************
   ***** eeprom_write **************************************************
   ***** eeprom_write **************************************************
   ********************************************************************* */
   ********************************************************************* */
/* Writes <length> bytes from buf to EEPROM address <addr>.
/* Writes <length> bytes from buf to EEPROM address <addr>.
   <length> must be smaller or equal than 8. Returns the number of bytes
   <length> must be smaller or equal than 8. Returns the number of bytes
   read. This number is 0 during a write cycle. */
   read. */
BYTE eeprom_write ( __xdata BYTE *buf, WORD addr, BYTE length ) {
BYTE eeprom_write ( __xdata BYTE *buf, WORD addr, BYTE length ) {
    BYTE bytes = 0;
    BYTE bytes = 0;
 
 
 
    if ( length == 0 )
 
        return 0;
 
 
    if ( eeprom_select(EEPROM_ADDR, 100,0) )
    if ( eeprom_select(EEPROM_ADDR, 100,0) )
        goto eeprom_write_end;
        goto eeprom_write_end;
 
 
    I2DAT = HI(addr);           // write address
    I2DAT = HI(addr);           // write address
    if ( i2c_waitWrite() ) goto eeprom_write_end;
    if ( i2c_waitWrite() ) goto eeprom_write_end;
Line 254... Line 257...
#define[EEPROM_MAC_ADDR][0xA6]
#define[EEPROM_MAC_ADDR][0xA6]
#define[@CAPABILITY_MAC_EEPROM;]
#define[@CAPABILITY_MAC_EEPROM;]
 
 
__xdata BYTE mac_eeprom_addr;
__xdata BYTE mac_eeprom_addr;
 
 
 
// details about the configuration data structure can be found at 
 
// http://www.ztex.de/firmware-kit/docs/java/ztex/ConfigData.html
 
 
 
__xdata BYTE config_data_valid;
 
 
/* *********************************************************************
/* *********************************************************************
   ***** mac_eeprom_read ***********************************************
   ***** mac_eeprom_read ***********************************************
   ********************************************************************* */
   ********************************************************************* */
/* Reads <length> bytes from EEPROM address <addr> and write them to buf.
/* Reads <length> bytes from EEPROM address <addr> and write them to buf.
   Returns the number of bytes read. This number is 0 during a write cycle. */
   Returns the number of bytes read. */
BYTE mac_eeprom_read ( __xdata BYTE *buf, BYTE addr, BYTE length ) {
BYTE mac_eeprom_read ( __xdata BYTE *buf, BYTE addr, BYTE length ) {
    BYTE bytes = 0,i;
    BYTE bytes = 0,i;
 
 
    if ( length == 0 )
    if ( length == 0 )
        return 0;
        return 0;
Line 273... Line 281...
    I2DAT = addr;               // write address
    I2DAT = addr;               // write address
    if ( i2c_waitWrite() ) goto mac_eeprom_read_end;
    if ( i2c_waitWrite() ) goto mac_eeprom_read_end;
    I2CS |= bmBIT6;
    I2CS |= bmBIT6;
    i2c_waitStop();
    i2c_waitStop();
 
 
 
 
    I2CS |= bmBIT7;             // start bit
    I2CS |= bmBIT7;             // start bit
    i2c_waitStart();
    i2c_waitStart();
    I2DAT = EEPROM_MAC_ADDR | 1;  // select device for reading
    I2DAT = EEPROM_MAC_ADDR | 1;  // select device for reading
    if ( i2c_waitWrite() ) goto mac_eeprom_read_end;
    if ( i2c_waitWrite() ) goto mac_eeprom_read_end;
 
 
Line 304... Line 311...
/* *********************************************************************
/* *********************************************************************
   ***** mac_eeprom_write **********************************************
   ***** mac_eeprom_write **********************************************
   ********************************************************************* */
   ********************************************************************* */
/* Writes <length> bytes from buf to and write them EEPROM address <addr>.
/* Writes <length> bytes from buf to and write them EEPROM address <addr>.
   <length> must be smaller or equal than 8. Returns the number of bytes
   <length> must be smaller or equal than 8. Returns the number of bytes
   read. This number is 0 during a write cycle. */
   written. */
BYTE mac_eeprom_write ( __xdata BYTE *buf, BYTE addr, BYTE length ) {
BYTE mac_eeprom_write ( __xdata BYTE *buf, BYTE addr, BYTE length ) {
    BYTE bytes = 0;
    BYTE bytes = 0;
 
 
 
    if ( length == 0 )
 
        return 0;
 
 
    if ( eeprom_select(EEPROM_MAC_ADDR, 100,0) )
    if ( eeprom_select(EEPROM_MAC_ADDR, 100,0) )
        goto mac_eeprom_write_end;
        goto mac_eeprom_write_end;
 
 
    I2DAT = addr;               // write address
    I2DAT = addr;               // write address
    if ( i2c_waitWrite() ) goto mac_eeprom_write_end;
    if ( i2c_waitWrite() ) goto mac_eeprom_write_end;
 
 
    for (; bytes<length; bytes++ ) {
    while ( bytes<length ) {
        I2DAT = *buf;           // write data 
        I2DAT = *buf;           // write data 
        buf++;
        buf++;
        if ( i2c_waitWrite() ) goto mac_eeprom_write_end;
        if ( i2c_waitWrite() ) goto mac_eeprom_write_end;
 
 
 
        addr++;
 
        bytes++;
 
        if ( ( (addr & 8) == 0 ) && ( bytes<length ) ) {
 
            I2CS |= bmBIT6;             // stop bit
 
            i2c_waitStop();
 
 
 
            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;
 
        }
    }
    }
    I2CS |= bmBIT6;             // stop bit
    I2CS |= bmBIT6;             // stop bit
    i2c_waitStop();
    i2c_waitStop();
 
 
mac_eeprom_write_end:
mac_eeprom_write_end:
 
    mac_eeprom_addr = addr;
    return bytes;
    return bytes;
}
}
 
 
/* *********************************************************************
/* *********************************************************************
   ***** EP0 vendor request 0x3B ***************************************
   ***** EP0 vendor request 0x3B ***************************************
   ********************************************************************* */
   ********************************************************************* */
BYTE mac_eeprom_read_ep0 () {
BYTE mac_eeprom_read_ep0 () {
    BYTE i, b;
    BYTE i, b;
    b = ep0_payload_transfer;
    b = ep0_payload_transfer;
    i = mac_eeprom_read(EP0BUF, mac_eeprom_addr, b);
    i = mac_eeprom_read(EP0BUF, mac_eeprom_addr, b);
 
    mac_eeprom_addr += b;
    return i;
    return i;
}
}
 
 
ADD_EP0_VENDOR_REQUEST((0x3B,,                          // read from EEPROM
ADD_EP0_VENDOR_REQUEST((0x3B,,                          // read from EEPROM
    mac_eeprom_addr =  SETUPDAT[2];                     // Address
    mac_eeprom_addr =  SETUPDAT[2];                     // Address

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.