summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-12-31 13:43:51 +0000
committerFreeArtMan <dos21h@gmail.com>2015-12-31 13:43:51 +0000
commit891ba007a455590ac544bbebd270ebe8d3417f2c (patch)
treee848f2c880d2bddc3b62c6090d88c966ab2b3d13
parent2d6d67e07233cc6b085fd9eebdd6795602c75a0b (diff)
downloadradiola-891ba007a455590ac544bbebd270ebe8d3417f2c.tar.gz
radiola-891ba007a455590ac544bbebd270ebe8d3417f2c.zip
Add eeprom dump test
-rw-r--r--hw/hw_eeprom.c47
-rw-r--r--hw/hw_eeprom.h15
-rw-r--r--test/.gitignore2
-rw-r--r--test/dump_eeprom.c74
4 files changed, 138 insertions, 0 deletions
diff --git a/hw/hw_eeprom.c b/hw/hw_eeprom.c
index e69de29..10ae817 100644
--- a/hw/hw_eeprom.c
+++ b/hw/hw_eeprom.c
@@ -0,0 +1,47 @@
+#include "hw_eeprom.h"
+
+
+
+int dump_eeprom( rtlsdr_dev_t *dev, uint8_t *data, uint16_t len )
+{
+ int fret = 0;
+
+ if ( len != EEPROM_SIZE )
+ {
+ printf("EEPROM sump size expected to be %d\n", EEPROM_SIZE);
+ return -1;
+ }
+
+ fret = hw_read_eeprom( dev, data, 0, len );
+ if ( fret != 0 )
+ {
+ printf("Cannot read eeprom rtlsdr err (%d)\n", fret);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int restore_eeprom( rtlsdr_dev_t *dev, uint8_t *data, uint16_t len )
+{
+ int fret = 0;
+
+ if ( len != EEPROM_SIZE )
+ {
+ printf("EEPROM sump size expected to be %d\n", EEPROM_SIZE);
+ return -1;
+ }
+
+ fret = hw_write_eeprom( dev, data, 0, len );
+ if ( fret != 0 )
+ {
+ printf("Cannot write eeprom rtlsdr err(%d)\n", fret);
+ return -1;
+ }
+
+
+ return 0;
+}
+
+
diff --git a/hw/hw_eeprom.h b/hw/hw_eeprom.h
index e69de29..ac3ec0a 100644
--- a/hw/hw_eeprom.h
+++ b/hw/hw_eeprom.h
@@ -0,0 +1,15 @@
+#ifndef __RADIOLA_HW_EEPROM_H
+#define __RADIOLA_HW_EEPROM_H
+
+#include "hw.h"
+
+#define EEPROM_SIZE 256
+
+int dump_eeprom( rtlsdr_dev_t *dev, uint8_t *data, uint16_t len );
+int restore_eeprom( rtlsdr_dev_t *dev, uint8_t *data, uint16_t len );
+
+//int eeprom_read_config();
+//int eeprom_write_config();
+
+
+#endif \ No newline at end of file
diff --git a/test/.gitignore b/test/.gitignore
index 7bd96c4..a37bb52 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -8,3 +8,5 @@ ui_gl_filter
sdr_fm
div20
*.o
+dump0
+dump_eeprom
diff --git a/test/dump_eeprom.c b/test/dump_eeprom.c
new file mode 100644
index 0000000..b32e74e
--- /dev/null
+++ b/test/dump_eeprom.c
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+//rtlsdr
+#include <rtl-sdr.h>
+#include <hw/sdr.h>
+#include <hw/hw.h>
+#include <hw/hw_eeprom.h>
+
+int print_dump( uint8_t *data, uint16_t size )
+{
+ int i;
+ const int line_sz = 32;
+ for (i=0; i<size;i++)
+ {
+ printf("%02x ", data[i]);
+ if (i % 32 == 31)
+ {
+ printf("\n");
+ }
+ }
+ for (i=0; i<size;i++)
+ {
+ if ( isprint(data[i]) )
+ {
+ printf("%c", data[i]);
+ } else
+ {
+ printf(".");
+ }
+ if (i % 32 == 31)
+ {
+ printf("\n");
+ }
+ }
+ return 0;
+}
+
+int main( )
+{
+ int i;
+ uint32_t dev_num;
+ rtlsdr_dev_t *dev=NULL;
+ int ret;
+
+ const int buf_size = 256;
+ uint8_t buf[buf_size];
+
+ memset(buf, 0, buf_size );
+
+ dev_num = rtlsdr_get_device_count();
+ printf("Found %d device(s)\n", dev_num );
+
+ printf("List device names:\n");
+ for (i=0; i<dev_num; i++)
+ {
+ hw_open( &dev, i );
+
+ ret = dump_eeprom( dev, buf, buf_size );
+ if (ret != 0)
+ {
+ printf("Couldnt dump eeprom\n");
+ } else
+ {
+ printf("Dumped device %d\n",i);
+ }
+ print_dump( buf, buf_size );
+
+ hw_close( dev );
+ }
+
+ return 0;
+} \ No newline at end of file