initial commit
This commit is contained in:
13
linux/libstrm/Makefile
Normal file
13
linux/libstrm/Makefile
Normal 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
17
linux/libstrm/strm.h
Normal 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
77
linux/libstrm/usb2strm.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user