mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-04-21 12:27:27 +03:00
usb fs mostly working
This commit is contained in:
@@ -31,11 +31,10 @@ arch_headers = mips/arch.hh mips/nanonote/jz4740.hh mips/nanonote/board.hh
|
||||
boot_threads = init udc
|
||||
programs = nanonote-gpio buzzer metronome lcd
|
||||
|
||||
all: test $(addsuffix .elf,$(addprefix fs/,$(programs)))
|
||||
all: test
|
||||
|
||||
test: iris.raw mips/nanonote/server/usb-server mips/nanonote/sdram-setup.raw
|
||||
test: iris.raw mips/nanonote/server/usb-server mips/nanonote/sdram-setup.raw $(addsuffix .elf,$(addprefix fs/,$(programs)))
|
||||
echo "reboot 0xa$(shell /bin/sh -c '$(OBJDUMP) -t iris.elf | grep __start$$ | cut -b2-8')" | nc localhost 5050
|
||||
.PHONY: test
|
||||
|
||||
mips/nanonote/server/usb-server: mips/nanonote/server/usb-server.ccp mips/nanonote/server/Makefile.am mips/nanonote/server/configure.ac
|
||||
$(MAKE) -C mips/nanonote/server
|
||||
@@ -59,10 +58,11 @@ mips/init.o: TARGET_FLAGS = -I/usr/include
|
||||
boot-programs/init.o: TARGET_FLAGS = -I/usr/include
|
||||
$(addsuffix .elf,$(boot_threads)): TARGET_FLAGS = -I.
|
||||
$(addsuffix .elf,$(boot_threads)): LDFLAGS = -EL
|
||||
$(addprefix fs/,$(addsuffix .elf,$(programs))): LDFLAGS = -EL
|
||||
$(addprefix boot-programs/,$(addsuffix .cc,$(boot_threads))): devices.hh keys.hh
|
||||
boot-programs/lcd.o: boot-programs/charset.data
|
||||
source/lcd.o: source/charset.data
|
||||
|
||||
boot-programs/charset.data: boot-programs/charset
|
||||
source/charset.data: source/charset
|
||||
$< > $@
|
||||
|
||||
%.o:%.S Makefile Makefile.arch mips/arch.hh
|
||||
@@ -78,7 +78,15 @@ server:
|
||||
servers:
|
||||
while : ; do $(MAKE) server ; done
|
||||
|
||||
ARCH_CLEAN_FILES = $(boot_sources) $(addsuffix .elf,$(boot_threads)) $(arch_headers) devices.hh keys.hh mips/*.o mips/nanonote/*.o boot-programs/charset.data iris.elf iris.raw mips/nanonote/sdram-setup.elf mips/nanonote/sdram-setup.raw
|
||||
monitor:
|
||||
stty -F /dev/ttyS0 raw 9600
|
||||
cat /dev/ttyS0
|
||||
|
||||
setup:
|
||||
x-terminal-emulator -e make monitor
|
||||
x-terminal-emulator -e make servers
|
||||
|
||||
ARCH_CLEAN_FILES = $(boot_sources) $(addsuffix .elf,$(boot_threads)) $(arch_headers) devices.hh keys.hh mips/*.o mips/nanonote/*.o source/charset.data iris.elf iris.raw mips/nanonote/sdram-setup.elf mips/nanonote/sdram-setup.raw
|
||||
|
||||
.PRECIOUS: mips/arch.hh mips/nanonote/jz4740.hh mips/nanonote/board.hh
|
||||
.PHONY: server
|
||||
.PHONY: test all monitor server servers setup
|
||||
|
||||
@@ -1883,13 +1883,13 @@ void cdelay (unsigned cs):
|
||||
#define UDC_TESTMODE REG8 (UDC_BASE + 0x0f) // USB test mode 8-bit
|
||||
|
||||
#define UDC_CSR0 REG8 (UDC_BASE + 0x12) // EP0 CSR 8-bit
|
||||
#define UDC_INMAXP(ep) REG16 (UDC_BASE + 0x100 + 0x10 * (ep) + 0x10) // EP1-2 IN Max Pkt Size 16-bit
|
||||
#define UDC_INCSR(ep) REG16 (UDC_BASE + 0x100 + 0x10 * (ep) + 0x12) // EP1-2 IN CSR LSB 8/16bit
|
||||
#define UDC_INCSRH(ep) REG8 (UDC_BASE + 0x100 + 0x10 * (ep) + 0x13) // EP1-2 IN CSR MSB 8-bit
|
||||
#define UDC_OUTMAXP(ep) REG16 (UDC_BASE + 0x100 + 0x10 * (ep) + 0x14) // EP1 OUT Max Pkt Size 16-bit
|
||||
#define UDC_OUTCSR(ep) REG16 (UDC_BASE + 0x100 + 0x10 * (ep) + 0x16) // EP1 OUT CSR LSB 8/16bit
|
||||
#define UDC_OUTCSRH(ep) REG8 (UDC_BASE + 0x100 + 0x10 * (ep) + 0x17) // EP1 OUT CSR MSB 8-bit
|
||||
#define UDC_OUTCOUNT(ep) REG16 (UDC_BASE + 0x100 + 0x10 * (ep) + 0x18) // bytes in EP0/1 OUT FIFO 16-bit
|
||||
#define UDC_INMAXP REG16 (UDC_BASE + 0x10) // EP1-2 IN Max Pkt Size 16-bit
|
||||
#define UDC_INCSR REG16 (UDC_BASE + 0x12) // EP1-2 IN CSR LSB 8/16bit
|
||||
#define UDC_INCSRH REG8 (UDC_BASE + 0x13) // EP1-2 IN CSR MSB 8-bit
|
||||
#define UDC_OUTMAXP REG16 (UDC_BASE + 0x14) // EP1 OUT Max Pkt Size 16-bit
|
||||
#define UDC_OUTCSR REG16 (UDC_BASE + 0x16) // EP1 OUT CSR LSB 8/16bit
|
||||
#define UDC_OUTCSRH REG8 (UDC_BASE + 0x17) // EP1 OUT CSR MSB 8-bit
|
||||
#define UDC_OUTCOUNT REG16 (UDC_BASE + 0x18) // bytes in EP0/1 OUT FIFO 16-bit
|
||||
|
||||
#define UDC_FIFO(ep) REG32 (UDC_BASE + 0x20 + 4 * (ep))
|
||||
#define UDC_FIFO8(ep) REG8 (UDC_BASE + 0x20 + 4 * (ep))
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <shevek/server.hh>
|
||||
#include <shevek/args.hh>
|
||||
#include <shevek/dir.hh>
|
||||
#include <shevek/error.hh>
|
||||
#include "devices.hh"
|
||||
|
||||
struct client
|
||||
@@ -70,15 +71,15 @@ struct data:
|
||||
void get_device (unsigned vendor, unsigned product, unsigned tries)
|
||||
void poll ()
|
||||
|
||||
static std::string files ("fs")
|
||||
struct Name:
|
||||
char name[16]
|
||||
std::string full
|
||||
Name (std::string const &n):
|
||||
full = n
|
||||
full = files + '/' + n
|
||||
memset (name, 0, 16)
|
||||
memcpy (name, n.data (), n.size () > 16 ? 16 : n.size ())
|
||||
static std::vector <Name> dir
|
||||
static std::string files (".")
|
||||
unsigned lock (0)
|
||||
|
||||
void data::poll ():
|
||||
@@ -101,6 +102,12 @@ void data::poll ():
|
||||
break
|
||||
case Directory::GET_SIZE:
|
||||
unsigned long long size = dir.size ()
|
||||
std::cerr << "sending dir size\n"
|
||||
std::cerr << Directory::GET_SIZE << '\n'
|
||||
char *str = (char *)&size
|
||||
for unsigned i = 0; i < 8; ++i:
|
||||
std::cerr << " " << (unsigned)(str[i] & 0xff)
|
||||
std::cerr << '\n'
|
||||
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
|
||||
std::cerr << "unable to send size to device: " << usb_strerror () << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
@@ -115,6 +122,7 @@ void data::poll ():
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
std::cerr << "sending filename\n"
|
||||
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_NAME, 0, 0, dir[buffer[1]].name, 16, timeout) != 16:
|
||||
std::cerr << "unable to send name to device: " << usb_strerror () << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
@@ -123,13 +131,17 @@ void data::poll ():
|
||||
return
|
||||
continue
|
||||
case Directory::LOCK_RO:
|
||||
std::cerr << "lock\n"
|
||||
if !lock++:
|
||||
std::cerr << "freezing file list\n"
|
||||
shevek::dir d (files)
|
||||
dir.clear ()
|
||||
for shevek::dir::const_iterator i = d.begin (); i == d.end (); ++i:
|
||||
dir.push_back (Name (i->name))
|
||||
for shevek::dir::const_iterator i = d.begin (); i != d.end (); ++i:
|
||||
if !i->name.empty () && i->name[0] != '.':
|
||||
dir.push_back (Name (i->name))
|
||||
continue
|
||||
case Directory::UNLOCK_RO:
|
||||
std::cerr << "unlock\n"
|
||||
if !lock:
|
||||
std::cerr << "unlocking without lock" << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
@@ -139,19 +151,22 @@ void data::poll ():
|
||||
if !--lock:
|
||||
dir.clear ()
|
||||
continue
|
||||
case Directory::GET_FILE_RO:
|
||||
unsigned f = buffer[0] >> 16
|
||||
if f >= dir.size ():
|
||||
case String::GET_PAGE:
|
||||
if buffer[1] >= dir.size ():
|
||||
std::cerr << "reading invalid file" << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
std::ifstream file (dir[f].full.c_str ())
|
||||
file.seekg (buffer[1] << 12)
|
||||
unsigned pos = buffer[0] >> 16
|
||||
std::cerr << "getting data from " << pos << '\n'
|
||||
std::ifstream file (dir[buffer[1]].full.c_str ())
|
||||
file.seekg (pos << 12)
|
||||
char page[1 << 12]
|
||||
memset (page, 0, 1 << 12)
|
||||
file.read (page, 1 << 12)
|
||||
shevek::dump (std::string (page, 32), std::cerr)
|
||||
std::cerr << "sending bulk\n"
|
||||
for unsigned i = 0; i < (1 << 12); i += 64:
|
||||
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, &page[i], 64, timeout) != 64:
|
||||
std::cerr << "unable to send file to device: " << usb_strerror () << std::endl
|
||||
@@ -160,15 +175,33 @@ void data::poll ():
|
||||
handle = NULL
|
||||
return
|
||||
continue
|
||||
case String::GET_SIZE:
|
||||
if buffer[1] >= dir.size ():
|
||||
std::cerr << "reading invalid file size" << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
std::ifstream file (dir[buffer[1]].full.c_str ())
|
||||
file.seekg (0, std::ios_base::end)
|
||||
unsigned long long size = file.tellg ()
|
||||
std::cerr << "sending file size " << size << "\n"
|
||||
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, String::GET_SIZE, 0, 0, (char *)&size, 8, timeout) != 8:
|
||||
std::cerr << "unable to send size to device: " << usb_strerror () << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
continue
|
||||
default:
|
||||
std::cerr << "invalid request" << std::endl
|
||||
std::cerr << "invalid request " << buffer[0] << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
// If the code reaches this point, break out of the loop. The loop continues if a continue statement is reached.
|
||||
break
|
||||
(shevek::absolute_time () + shevek::relative_time (1, 0)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
(shevek::absolute_time () + shevek::relative_time (0, 100000000)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
|
||||
struct client : public shevek::server <client, data *>::connection:
|
||||
static Glib::RefPtr <client> create ():
|
||||
@@ -225,7 +258,7 @@ void data::get_device (unsigned vendor, unsigned product, unsigned tries):
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
continue
|
||||
(shevek::absolute_time () + shevek::relative_time (1, 0)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
(shevek::absolute_time () + shevek::relative_time (0, 100000000)).schedule (sigc::mem_fun (*this, &data::poll))
|
||||
return
|
||||
if i + 1 < tries:
|
||||
//std::cerr << "failed to find device, still trying...\n"
|
||||
@@ -277,6 +310,21 @@ void data::boot (unsigned entry):
|
||||
return
|
||||
std::cerr << "(re)booted NanoNote\n"
|
||||
|
||||
static void dump_devices ():
|
||||
std::cerr << std::hex << "String: " << String::ID
|
||||
std::cerr << "\nWString: " << WString::ID
|
||||
std::cerr << "\nDevice: " << Device::ID
|
||||
std::cerr << "\nParent: " << Parent::ID
|
||||
std::cerr << "\nKeyboard: " << Keyboard::ID
|
||||
std::cerr << "\nBuzzer: " << Buzzer::ID
|
||||
std::cerr << "\nDisplay: " << Display::ID
|
||||
std::cerr << "\nSetting: " << Setting::ID
|
||||
std::cerr << "\nDirectory: " << Directory::ID
|
||||
std::cerr << "\nWDirectory: " << WDirectory::ID
|
||||
std::cerr << "\nFilesystem: " << Filesystem::ID
|
||||
std::cerr << "\nStream: " << Stream::ID
|
||||
std::cerr << "\n"
|
||||
|
||||
int main (int argc, char **argv):
|
||||
usb_init ()
|
||||
std::string port ("5050")
|
||||
@@ -285,5 +333,6 @@ int main (int argc, char **argv):
|
||||
}
|
||||
shevek::args args (argc, argv, opts, 0, 0, "device server for testing Iris on NanoNote", "2009")
|
||||
data d (port)
|
||||
dump_devices ()
|
||||
shevek::loop ()
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user