initial commit

This commit is contained in:
2013-10-02 10:43:54 +02:00
commit f3e562f835
92 changed files with 7400 additions and 0 deletions

11
linux/Makefile Normal file
View File

@@ -0,0 +1,11 @@
DIRS = libstrm apps
all:
@for dir in $(DIRS); do \
$(MAKE) -C $$dir || exit 1; \
done
clean:
@for dir in $(DIRS); do \
$(MAKE) -C $$dir clean || exit 1; \
done

17
linux/apps/Makefile Normal file
View File

@@ -0,0 +1,17 @@
CC = gcc
LD = gcc
CFLAGS = -Wall -Werror -c -I../libstrm -O2
LDFLAGS = -L../libstrm
LDFLAGS_POST = -lstrm -lusb
BIN_STRM_DDR2 = strm_ddr2
SRC_STRM_DDR2 = strm_ddr2.c
OBJ_STRM_DDR2 = $(SRC_STRM_DDR2:%.c=%.o)
all: ${BIN_STRM_DDR2}
${BIN_STRM_DDR2}: ${OBJ_STRM_DDR2}
${LD} ${LDFLAGS} $^ -o $@ ${LDFLAGS_POST}
clean:
rm -f *.o ${BIN_STRM_DDR2}

119
linux/apps/strm_ddr2.c Normal file
View File

@@ -0,0 +1,119 @@
/*********************************************
* (2013) Benjamin Krill <ben@codiert.org>
*********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <usb.h>
#include <strm.h>
static void
show_usage(char *name)
{
printf("USAGE: %s <r|w> <address> <size> [<pattern>]\n"
"\tw - write needs address, size, pattern\n"
"\tr - read needs address, size\n"
"\t\tsize in DW (4bytes)\n"
, name);
return;
}
int
main(int argc, char **argv)
{
uint32_t *buf, pattern;
int address, size, size_dw, i;
clock_t start, end;
int ret = -1;
usb_dev_handle *hd;
if (argc < 3 || (strncmp(argv[1], "w", 1) == 0 && argc < 5)) {
show_usage(argv[0]);
exit(1);
}
if ((hd = strm_init(0x04b4, 0x2342)) == NULL) {
perror("cannot init usb2strm interface");
exit(1);
}
address = strtoull(argv[2], NULL, 0);
size_dw = strtoull(argv[3], NULL, 0);
size = size_dw*4;
if (size_dw > 0xffffff) {
perror("size cannot larger than 0xffffff DW");
goto out;
}
buf = (uint32_t*)malloc(size+8);
if (buf == NULL) {
perror("cannot allocate memory\n");
goto out;
}
if (strncmp(argv[1], "w", 1) == 0) {
pattern = strtoull(argv[4], NULL, 0);
for (i=0; i < size_dw; i++) {
buf[i+2] = pattern;
}
buf[0] = STRM_TYPE_DDR2 << 28 | ((size_dw+1) & 0xffffff);
buf[1] = STRM_DDR2_WRITE_HDR_INIT(address >> 2);
printf("address=0x%x size=%d pattern=0x%06x - ", address, size, pattern);
start = clock();
if ((ret = usb_bulk_write(hd, 2, (const char *)buf, size+8, 1000)) < 0) {
fprintf(stderr, "\nFAILED: write bulk transfer (%d) [%s].\n\t%s\n", ret,
__func__, usb_strerror());
} else {
printf("wrote: %d bytes\n", ret);
}
end = clock();
printf("Number of seconds: %f\n", (end-start)/(double)CLOCKS_PER_SEC);
} else if (strncmp(argv[1], "r", 1) == 0) {
buf[0] = STRM_TYPE_DDR2 << 28 | 2;
buf[1] = STRM_DDR2_READ_HDR_INIT(address >> 2);
buf[2] = ((size_dw) & 0xffffff);
printf("address=0x%x size=%d - ", address, size);
if ((ret = usb_bulk_write(hd, 2, (const char *)buf, 12, 1000)) < 0) {
fprintf(stderr, "\nFAILED: write bulk transfer (%d) [%s].\n\t%s\n", ret,
__func__, usb_strerror());
goto free;
} else {
printf("wrote: %d bytes\n", ret);
}
if ((ret = usb_bulk_read(hd, 6, (char *)buf, size+4, 6000000)) < 0) {
fprintf(stderr, "\nFAILED: read bulk transfer (%d) [%s].\n\t%s\n", ret,
__func__, usb_strerror());
goto free;
} else {
printf("read: %d bytes\n", ret);
}
for (i=0; i < size+4; i++) {
if (!(i%0x10))
printf("\n");
printf("%02x ", ((uint8_t*)buf)[i]);
}
printf("\n");
} else {
printf("Unknown argument.\n");
return -1;
}
free:
free(buf);
out:
strm_fini();
return 0;
}

13
linux/libstrm/Makefile Normal file
View File

@@ -0,0 +1,13 @@
CC = gcc
CFLAGS=-Wall -Werror -O2 -I. -c -fPIC
SRCS = usb2strm.c
OBJS = $(SRCS:%.c=%.o)
libstrm: ${OBJS}
${CC} -shared -Wl,-soname,$@.so.1 -o $@.so.1.0.1 $^ -lusb
@if [ ! -e $@.so ]; then ln -s $@.so.1.0.1 $@.so; fi
@if [ ! -e $@.so.1 ]; then ln -s $@.so.1.0.1 $@.so.1; fi
clean:
rm -f *.o *.so.* *.so

17
linux/libstrm/strm.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef _STRM_H
#define _STRM_H
#include <stdint.h>
#include <usb.h>
#define STRM_TYPE_DDR2 0x1
#define STRM_DDR2_WRITE_HDR_INIT(addr) \
(uint32_t)(0x80000000 | (addr & 0x0fffffff))
#define STRM_DDR2_READ_HDR_INIT(addr) \
(uint32_t)(~(0x1 << 31) & (addr & 0x0fffffff))
/* prototypes */
usb_dev_handle *strm_init(int vendor, int product);
int strm_fini(void);
#endif /* _STRM_H */

77
linux/libstrm/usb2strm.c Normal file
View File

@@ -0,0 +1,77 @@
/*********************************************
* (2013) Benjamin Krill <benjamin@krll.de>
*********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <usb.h>
#include <string.h>
#include <endian.h>
#include <strm.h>
#define DEBUG 0
#if defined(DEBUG) && DEBUG == 1
#define printf_dbg(fmt, args...) printf(fmt, ## args)
#else
#define printf_dbg(args...)
#endif
static usb_dev_handle *hd = NULL;
/* TODO: extend to support multiple USB device on one host! */
static struct usb_device *
find_device(struct usb_bus* busses, int vendor, int product)
{
struct usb_bus *bus;
struct usb_device *dev;
for (bus = busses; bus; bus = bus->next) {
printf_dbg("scanning bus %s\n", bus->dirname);
for (dev = bus->devices; dev; dev=dev->next) {
/* compare device vendor and product */
if ((dev->descriptor.idVendor == vendor) &&
(dev->descriptor.idProduct == product)) {
/* print device information */
printf_dbg("\tfound device %s bus %s (idVendor 0x%04x idProduct 0x%04x)\n",
dev->filename, dev->bus->dirname, dev->descriptor.idVendor,
dev->descriptor.idProduct);
return dev;
} else {
printf_dbg("\tdevice %s does not match\n", dev->filename);
}
}
}
return NULL;
}
usb_dev_handle *
strm_init(int vendor, int product)
{
struct usb_device *dev;
usb_init();
usb_find_busses();
usb_find_devices();
if ((dev = find_device(usb_get_busses(), vendor, product)) == NULL)
return NULL;
if (!(hd = usb_open(dev))) {
printf("FAILED: cannot open device.\n");
return NULL;
}
/* reset usb device */
usb_reset(hd);
printf_dbg("Lets do the magic (%p) ...\n", hd);
return hd;
}
int
strm_fini(void)
{
if (hd)
usb_close(hd);
hd = NULL;
return 0;
}