Functions for read/write of a single eeprom location
authorOleg Seiljus <oseiljus@xverve.com>
Tue, 3 Nov 2009 16:05:01 +0000 (17:05 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 3 Nov 2009 16:05:01 +0000 (17:05 +0100)
src/ftdi.c
src/ftdi.h

index 8b589eb..5051059 100644 (file)
@@ -2130,6 +2130,24 @@ int ftdi_eeprom_decode(struct ftdi_eeprom *eeprom, unsigned char *buf, int size)
 }
 
 /**
+    Read eeprom location
+
+    \param ftdi pointer to ftdi_context
+    \param eeprom_addr Address of eeprom location to be read
+    \param eeprom_val Pointer to store read eeprom location
+
+    \retval  0: all fine
+    \retval -1: read failed
+*/
+int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val)
+{
+    if (usb_control_msg(ftdi->usb_dev, FTDI_DEVICE_IN_REQTYPE, SIO_READ_EEPROM_REQUEST, 0, eeprom_addr, (char *)eeprom_val, 2, ftdi->usb_read_timeout) != 2)
+        ftdi_error_return(-1, "reading eeprom failed");
+
+    return 0;
+}
+
+/**
     Read eeprom
 
     \param ftdi pointer to ftdi_context
@@ -2231,6 +2249,26 @@ int ftdi_read_eeprom_getsize(struct ftdi_context *ftdi, unsigned char *eeprom, i
 }
 
 /**
+    Write eeprom location
+
+    \param ftdi pointer to ftdi_context
+    \param eeprom_addr Address of eeprom location to be written
+    \param eeprom_val Value to be written
+
+    \retval  0: all fine
+    \retval -1: read failed
+*/
+int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr, unsigned short eeprom_val)
+{
+    if (usb_control_msg(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
+                                    SIO_WRITE_EEPROM_REQUEST, eeprom_val, eeprom_addr,
+                                    NULL, 0, ftdi->usb_write_timeout) != 0)
+        ftdi_error_return(-1, "unable to write eeprom");
+
+    return 0;
+}
+
+/**
     Write eeprom
 
     \param ftdi pointer to ftdi_context
index f629821..74a397b 100644 (file)
@@ -347,8 +347,11 @@ extern "C"
     int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
     int ftdi_erase_eeprom(struct ftdi_context *ftdi);
 
+    int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val);
+    int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr, unsigned short eeprom_val);
+
     char *ftdi_get_error_string(struct ftdi_context *ftdi);
+
 #ifdef __cplusplus
 }
 #endif