mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-04-21 12:27:27 +03:00
towards a usb file system
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
load = 0x80000000
|
||||
|
||||
ARCH_CXXFLAGS = -DNUM_THREADS=6
|
||||
ARCH_CXXFLAGS = -DNUM_THREADS=2
|
||||
ARCH_CPPFLAGS = -I. -Imips -Imips/nanonote -Wa,-mips32 -DNANONOTE -DUSE_SERIAL
|
||||
CROSS = mipsel-linux-gnu-
|
||||
OBJDUMP = $(CROSS)objdump
|
||||
@@ -28,7 +28,10 @@ LDFLAGS = --omagic -Ttext $(load)
|
||||
arch_iris_sources = mips/interrupts.cc mips/arch.cc
|
||||
boot_sources = mips/init.cc mips/nanonote/board.cc
|
||||
arch_headers = mips/arch.hh mips/nanonote/jz4740.hh mips/nanonote/board.hh
|
||||
boot_threads = init udc nanonote-gpio buzzer metronome lcd
|
||||
boot_threads = init udc
|
||||
programs = nanonote-gpio buzzer metronome lcd
|
||||
|
||||
all: test $(addsuffix .elf,$(addprefix fs/,$(programs)))
|
||||
|
||||
test: iris.raw mips/nanonote/server/usb-server mips/nanonote/sdram-setup.raw
|
||||
echo "reboot 0xa$(shell /bin/sh -c '$(OBJDUMP) -t iris.elf | grep __start$$ | cut -b2-8')" | nc localhost 5050
|
||||
@@ -53,6 +56,7 @@ mips/nanonote/sdram-setup.elf: LDFLAGS = --omagic -T mips/nanonote/sdram-setup.l
|
||||
mips/nanonote/threadlist.o: $(addsuffix .elf,$(boot_threads))
|
||||
mips/boot.o: TARGET_FLAGS = -DMEMORY_SIZE="32 << 20"
|
||||
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 boot-programs/,$(addsuffix .cc,$(boot_threads))): devices.hh keys.hh
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <shevek/mainloop.hh>
|
||||
#include <shevek/server.hh>
|
||||
#include <shevek/args.hh>
|
||||
#include "devices.hh"
|
||||
|
||||
struct client
|
||||
|
||||
@@ -69,18 +71,87 @@ struct data:
|
||||
|
||||
void data::poll ():
|
||||
while true:
|
||||
char buffer[2]
|
||||
int s = usb_control_msg (handle, USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, POLL, 0, 0, buffer, 8, timeout)
|
||||
if s < 1 || s > 2 || buffer[0] != '#':
|
||||
unsigned buffer[2]
|
||||
int s = usb_control_msg (handle, USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, POLL, 0, 0, (char *)buffer, 8, timeout)
|
||||
if s != 8:
|
||||
std::cerr << "unable to send poll message to device: " << usb_strerror () << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
if s != 1:
|
||||
std::cout << buffer[1] << std::flush
|
||||
else:
|
||||
break
|
||||
switch buffer[0] & 0xffff:
|
||||
case ~0 & 0xffff:
|
||||
// Log character.
|
||||
std::cout << (char)buffer[1] << std::flush
|
||||
continue
|
||||
case ~1 & 0xffff:
|
||||
// No event.
|
||||
break
|
||||
case Directory::GET_SIZE:
|
||||
unsigned long long size = dir.size ()
|
||||
if usb_control_msg (handle, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, Directory::GET_SIZE, 0, 0, (char const *)&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
|
||||
case Directory::GET_NAME:
|
||||
if buffer[1] >= dir.size ():
|
||||
std::cerr << "invalid file name requested" << std::endl;
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
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)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
continue
|
||||
case Directory::LOCK_RO:
|
||||
if !lock++:
|
||||
dir.load (files)
|
||||
continue
|
||||
case Directory::UNLOCK_RO:
|
||||
if !lock:
|
||||
std::cerr << "unlocking without lock" << std::endl
|
||||
usb_release_interface (handle, 0)
|
||||
usb_close (handle)
|
||||
handle = NULL
|
||||
return
|
||||
--lock
|
||||
continue
|
||||
case Directory::GET_FILE_RO:
|
||||
unsigned f = buffer[0] >> 16
|
||||
if f >= 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])
|
||||
file.seek (buffer[1] << 12)
|
||||
char page[1 << 12]
|
||||
memset (page, 0, 1 << 12)
|
||||
file.read (page, 1 << 12)
|
||||
for unsigned i = 0; i < (1 << 12); i += 64:
|
||||
if usb_bulk_write (handle, 1 | USB_ENDPOINT_OUT, p, 64) != 64:
|
||||
std::cerr << "unable to send file 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
|
||||
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))
|
||||
|
||||
struct client : public shevek::server <client, data *>::connection:
|
||||
|
||||
@@ -29,22 +29,6 @@ thread1:
|
||||
|
||||
.balign 0x1000
|
||||
thread2:
|
||||
.incbin "nanonote-gpio.elf"
|
||||
|
||||
.balign 0x1000
|
||||
thread3:
|
||||
.incbin "buzzer.elf"
|
||||
|
||||
.balign 0x1000
|
||||
thread4:
|
||||
.incbin "metronome.elf"
|
||||
|
||||
.balign 0x1000
|
||||
thread5:
|
||||
.incbin "lcd.elf"
|
||||
|
||||
.balign 0x1000
|
||||
thread6:
|
||||
|
||||
// Everything from here may be freed after kernel initialization.
|
||||
init_start:
|
||||
@@ -53,7 +37,3 @@ thread_start:
|
||||
.word thread0
|
||||
.word thread1
|
||||
.word thread2
|
||||
.word thread3
|
||||
.word thread4
|
||||
.word thread5
|
||||
.word thread6
|
||||
|
||||
Reference in New Issue
Block a user