HostFS and microcontrollers?

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

HostFS and microcontrollers?

Post by myelin » Wed Jun 21, 2017 12:19 am

I'm still working on the firmware to get an ATMEGA32U4 working as a USB-serial bridge for UPURS, but once I get that working, I'm really looking forward to trying out HostFS:UPURS, and then seeing if I can implement the host side of it in the microcontroller itself. Has anyone else done something like this?

I'm excited about the possibility of putting ADFS and DFS floppy images, ADFS hard disk images, and tape images on an SD card and having the microcontroller serve them up (with PAGE=&E00) to a BBC or Electron.

Update: I got this to work (code to run on an ATMEGA32U4 is up on GitHub) but I couldn't get it running 100% reliably. YMMV -- 8bitkick has had much better luck! (see further down in this thread)
Last edited by myelin on Mon Mar 05, 2018 1:40 am, edited 1 time in total.
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
jgharston
Posts: 3211
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: HostFS and microcontrollers?

Post by jgharston » Wed Jun 21, 2017 12:38 am

I've written serial HostFS clients for various microcontrollers, but have only written hosts for full-blown computers. Sounds like an interesting project.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
sweh
Posts: 1955
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: HostFS and microcontrollers?

Post by sweh » Wed Jun 21, 2017 11:44 pm

myelin wrote:I'm still working on the firmware to get an ATMEGA32U4 working as a USB-serial bridge for UPURS, but once I get that working, I'm really looking forward to trying out HostFS:UPURS, and then seeing if I can implement the host side of it in the microcontroller itself. Has anyone else done something like this?
I thought about this, at one point, but never even started writing code. A related thought I had was that the communication needn't be _serial_. We have at least 8 I/O ports (potentially 9 or 10, depending) so we could do something slightly smarter; eg have 4 pins to transmit a nibble at a time and 4 pins for handshaking (CTS/RTS or whatever else). It'd require rewriting of the code but HostFS:UPURS has that segmented and keeps MartinB's routines mostly untouched. It's probably just two functions that'd need replacing.
Rgds
Stephen

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Thu Jun 22, 2017 4:41 am

sweh wrote:I thought about this, at one point, but never even started writing code. A related thought I had was that the communication needn't be _serial_. We have at least 8 I/O ports (potentially 9 or 10, depending) so we could do something slightly smarter; eg have 4 pins to transmit a nibble at a time and 4 pins for handshaking (CTS/RTS or whatever else). It'd require rewriting of the code but HostFS:UPURS has that segmented and keeps MartinB's routines mostly untouched. It's probably just two functions that'd need replacing.
I'd be curious to see a timing analysis for something like this, for a BBC or Electron talking to, say, a 16MHz AVR. I've started thinking this through before, but none of my ideas turn out to be that much better (and are definitely less convenient) than straight serial, unless I can use a CPLD to time things exactly, in which case I may as well put it on the 1MHz Bus instead :) Hopefully it's just that my ideas aren't very good -- I would definitely implement such a thing if someone can come up with a relatively efficient handshaking protocol!
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
jgharston
Posts: 3211
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: HostFS and microcontrollers?

Post by jgharston » Thu Jun 22, 2017 2:36 pm

sweh wrote:I thought about this, at one point, but never even started writing code. A related thought I had was that the communication needn't be _serial_. We have at least 8 I/O ports (potentially 9 or 10, depending) so we could do something slightly smarter;
The "serial"-ness of the Serial Host really just refers to the fact that it uses a single data transmission port, as opposed to the hardware Tube that uses four ports. I've used the same serial host/clients with a single data port via back-to-back parallel ports, Z80+8255 plugged into BBC+6522. In retrospect it's probably a confusing name, but it seemed the logical name back in 1993-ish.

I've written all the Serial Clients with the actual I/O code severly compartmentalised, the 'SendData' and 'ReadData' routines, so it can be chopped out and replaced to talk with other hardware. With most single-port communication it just requires the EQUates changing, to change the data port address and the status register bits.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Sun Jul 09, 2017 12:15 am

sweh wrote:We have at least 8 I/O ports (potentially 9 or 10, depending) so we could do something slightly smarter; eg have 4 pins to transmit a nibble at a time and 4 pins for handshaking (CTS/RTS or whatever else). It'd require rewriting of the code but HostFS:UPURS has that segmented and keeps MartinB's routines mostly untouched. It's probably just two functions that'd need replacing.
I got frustrated trying to make the microcontroller communicate perfectly with the UPURS routines, and hacked together my ideal communication system using a CPLD instead, with the microcontroller talking to the CPLD using SPI, and the CPLD connected as an Electron cartridge (and a BBC 1MHz bus device eventually, once I make a board for it). This lets me do proper handshaking; to HostFS it just appears as a very fast serial port, with well-behaved TxRDY and RxRDY signals, and bytes never go missing. Theoretical bandwidth is 1.2 MB/s from PC to AVR, a little under 500 kB/s from AVR to CPLD, and as fast as the Electron can read from its bus (still working out the timing on that one) from CPLD to RAM.

In an initial test without properly configuring the AVR's SPI port, it loads Codename: Droid (for comparison with MMFS/MGC) in 13 seconds. Adding some timing to TubeHost, it looks like it maxes out around 12400 bytes/s (~80 us/byte) in send_data_to_memory in MODE 6, and around 6000 bytes/s (~167 us/byte) in MODE 2.

Commenting out most of the flow control code in ReadData brings it up to 17760 bytes/s in MODE 6 and 8930 bytes/s in MODE 2.

Code/HDL: https://github.com/google/myelin-acorn- ... sd_adapter
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Mon Jul 10, 2017 4:00 pm

I wrote a fast-path version of WaitLoadIO that ignores flow control (i.e. just polls RxStatus for RxRDY, then reads RxData) and only handles esc+esc and esc+&Bx, and with that I'm seeing around 29 kB/s in MODE 2 and 39 kB/s in MODE 6, on an Electron. Finally faster than MMFS with my memory-mapped SPI port :)

Without getting really specific (like handling the 'esc' combinations in the external micro) this is about as good as I can do. It's at the point where program load time is no longer dominated by reading data into memory, so I'm pretty happy with it.
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
davidb
Posts: 2192
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: HostFS and microcontrollers?

Post by davidb » Mon Jul 10, 2017 4:07 pm

That's effectively instant loading, so well done! :)

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Fri Nov 10, 2017 11:30 pm

BTW I finally made a circuit board for this -- thread here.
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Thu Feb 22, 2018 6:48 pm

myelin wrote:I'm still working on the firmware to get an ATMEGA32U4 working as a USB-serial bridge for UPURS, but once I get that working, I'm really looking forward to trying out HostFS:UPURS, and then seeing if I can implement the host side of it in the microcontroller itself. Has anyone else done something like this?

I'm excited about the possibility of putting ADFS and DFS floppy images, ADFS hard disk images, and tape images on an SD card and having the microcontroller serve them up (with PAGE=&E00) to a BBC or Electron.
I'm interested in this too, especially since I saw my Arduino MKR1000 mounts nicely onto a BBC micro ashtray (assuming the cover got pushed in during the 80s... like happened on mine). I was wondering if you could have MicroPython running on the MCU host, or given it has WiFi onboard, serving some MODE 7-ified webpages or even uef/disk images from sth... physical layer I was thinking the simpler user port route - just add level shifters - although your fast serial implementation looks very cool...
BBC_Micro_plus_MKR.JPG

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Thu Feb 22, 2018 7:06 pm

8bitkick wrote:I'm interested in this too, especially since I saw my Arduino MKR1000 mounts nicely onto a BBC micro ashtray (assuming the cover got pushed in during the 80s... like happened on mine). I was wondering if you could have MicroPython running on the MCU host, or given it has WiFi onboard, serving some MODE 7-ified webpages or even uef/disk images from sth... physical layer I was thinking the simpler user port route - just add level shifters - although your fast serial implementation looks very cool...
Yep, that should absolutely work. I still have a couple of PCBs left if you'd like one -- PM me your address and I'll drop one in the mail.

The user port route works fairly well, especially if you're using the ATMEGA32U4, which runs at 5V and accepts TTL levels on its inputs (but can also produce 3.3V outputs for USB), although I had synchronization issues with HostFS:UPURS / UPURSFS; I'm not sure if that was due to a bug in my code or not.

Back to the interface using my board:

The interface is pretty simple on the MCU side. Here's the core loop; it's just a two-byte SPI transaction, with one status byte and one data byte.

Byte 1:

- the MCU sets bit 1 if it has a byte to send, and sets bit 0 if its buffer has room to accept a byte.
- the CPLD sets bit 1 if it has a byte to send, and sets bit 0 if its buffer has room to accept a byte.

Byte 2:

- the MCU sends a data byte from its buffer if it told the CPLD it had a byte to send and the CPLD said it had buffer space.
- the CPLD sends a data byte from its buffer if it told the MCU it had a byte to send and the MCU said it had buffer space.

So anything you can layer over the top of that is fair game. One thing I'm working on is expanding it to have two serial ports, with the AVR identifying as a dual serial port USB device, and the CPLD having a pair of buffers. This uses pretty much all the logic in the CPLD.
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Sat Mar 03, 2018 1:09 am

myelin wrote: The user port route works fairly well, especially if you're using the ATMEGA32U4, which runs at 5V and accepts TTL levels on its inputs (but can also produce 3.3V outputs for USB), although I had synchronization issues with HostFS:UPURS / UPURSFS; I'm not sure if that was due to a bug in my code or not.
OK I made a start with the MKR1000 ... your comments in upurs_usb_port.ino helped a lot with the flow control timing.

The code below is a basic setup in which the BBC boots into Host:UPURS, and the Arduino is connected to the BBC user port ready to serve pre-canned data on receiving a OSFILE load command. The structure is in there to parse / handle more commands and reading sweh's TubeHost should be possible. The detail of maintaining a proper filesystem is still to do... EDIT- I tidied up formatting and comments a bit...

With this setup, when the BBC boots you can type:

Code: Select all

MODE 0
*LOAD A 3000
And the result should be a successful 20K transfer to the BBC:
owl.jpg

The code is below. Next steps are to fill out more OS functions, and ultimately connect to an SD card or Internet via WiFi!

Code: Select all

// Arduino Host
//
//
// HostFS ported from Sweh
// github.com/sweharris/TubeHost/blob/master/TubeHost
//
// Arduino-UPURS I/O from Myelin
// github.com/google/myelin-acorn-electron-hardware/blob/master/upurs_usb_port/upurs_usb_port.ino


// --- Serial comms options ---

// UPURS uses inverted logic because it expects the User Port pins to be wired
// (with a series resistor and a diode from GND) straight to pins at RS232
// levels (+13V = 0, -13V = 1).

// Arduino MRK1000 uses hardware SERCOM instead of software serial for additional UART instances
// so inversion must be done externally in hardware

#define USE_ARDUINO_MKR // We assume RX & TX signals are inverted externally as we can't use SofwareSerial. 
                        // NB Must use 5v <> 3.3v level shifter with Arduino MKR


#include <Arduino.h>
#include "wiring_private.h"

// SERIAL WIRE DEFINES 
#define RXD_PIN 0   // Serial receive 
#define TXD_PIN 1   // Serial transmit
#define RTS_PIN 3   // active-high output Requesting them To Send. We are always ready so this stays high
#define CTS_PIN 4   // active-high input tells us we're Cleared To Send. (Using 4 as we can attach interrupt)


// TUBE HOST COMMAND DEFINES
// mdfs.net/Software/Tube/Serial/Protocol

#define ESCAPE        0x7F
#define OSRDCHIO      0x00 // Cy A
#define OSCLI         0x02 // string 0x0D                   0x7F or 0x80
#define OSBYTELO      0x04 // X A                           X
#define OSBYTEHI      0x06 // X Y A                         Cy Y X
#define OSWORD        0x08 // A in_length block out_length  block
#define OSWORD0       0x0A // block                         0xFF or 0x7F string 0x0D
#define OSARGS        0x0C // Y block A                     A block
#define OSBGET        0x0E // Y                             Cy A
#define OSBPUT        0x10 // Y A                           0x7F
#define OSFIND        0x12 // 0x00 Y                        0x7F
#define OSFIND        0x12 // A string 0x0D                 A
#define OSFILE        0x14 // block string 0x0D A           A block
#define OSGBPB        0x16 // block A                       block Cy A
#define OSFSC         0x18 // X Y A                         0xFF Y X or 0x7F
 
int long timer = 0;

// FILESYSTEM (fudged for now)
const int owlLogo [4546] = {0,773,7,1,15,1,31,1,0,3,15,1,255,4,0,3,254,1,255,4,0,4,224,1,248,1,254,1,255,1,0,15,3,1,0,3,1,1,31,1,127,1,255,2,0,3,255,5,0,3,224,1,252,1,255,3,0,5,128,1,192,1,224,1,0,12,1,1,7,1,31,1,63,1,0,3,63,1,255,4,0,3,252,1,255,4,0,4,192,1,240,1,252,1,254,1,0,14,1,1,3,1,0,3,1,1,31,1,255,3,0,3,255,5,0,3,192,1,252,1,255,3,0,6,128,1,224,1,0,12,3,1,15,1,63,1,127,1,0,3,63,1,255,4,0,3,248,1,255,4,0,4,128,1,224,1,248,1,252,1,0,13,1,1,7,1,15,1,0,3,7,1,127,1,255,3,0,3,255,5,0,3,128,1,240,1,254,1,255,2,0,7,128,1,0,12,7,1,31,1,127,1,255,1,0,3,255,5,0,3,240,1,255,4,0,5,192,1,240,1,248,1,0,13,3,1,7,1,15,1,0,3,7,1,127,1,255,3,0,3,254,1,255,4,0,4,224,1,252,1,254,1,255,1,0,7,128,1,0,7,1,1,0,4,15,1,63,1,255,2,0,3,255,5,0,3,224,1,254,1,255,3,0,5,128,1,224,1,240,1,0,256,63,2,127,3,63,1,31,1,15,1,255,24,128,2,192,2,224,1,252,1,255,2,3,1,7,2,15,2,127,1,255,26,240,1,248,4,240,1,224,1,192,1,0,8,127,2,255,2,127,2,63,1,31,1,255,22,254,1,252,1,0,2,128,2,0,4,7,1,15,4,7,1,3,2,255,24,224,1,240,3,248,1,255,3,0,2,1,2,3,1,31,1,255,26,254,2,255,6,0,4,128,1,241,1,255,2,15,1,31,3,63,1,255,27,192,1,224,4,192,1,128,1,0,1,1,2,3,2,1,2,0,2,255,7,127,1,255,16,252,2,254,1,252,3,248,1,240,1,0,8,31,1,63,4,31,1,15,1,7,1,255,24,128,1,192,3,224,1,252,1,255,2,3,3,7,1,15,1,63,1,255,26,248,2,252,2,248,1,240,2,224,1,0,256,7,1,0,7,255,2,31,1,0,5,255,3,31,1,3,3,7,1,255,30,254,2,255,3,224,1,128,1,0,3,255,1,254,1,224,1,0,5,128,1,0,15,7,1,1,1,0,6,255,2,63,1,0,5,255,2,254,1,0,5,240,1,192,1,0,22,255,1,63,1,3,1,0,5,255,3,3,1,0,4,255,5,127,1,63,2,255,27,248,1,224,1,192,1,224,2,255,3,63,1,15,1,7,2,15,1,255,28,254,1,252,1,248,2,255,3,192,1,0,4,254,1,248,1,128,1,0,21,31,1,7,1,0,6,255,3,0,5,255,2,240,1,0,5,192,1,0,15,3,1,0,7,255,1,127,1,15,1,0,5,255,3,15,1,3,1,1,1,0,2,255,35,240,1,128,1,0,2,128,1,255,1,254,1,224,1,0,5,128,1,0,265,1,1,7,1,15,1,31,1,63,1,127,1,0,1,63,1,255,6,63,1,255,21,248,1,224,1,255,5,248,1,0,2,252,1,248,1,240,1,224,1,128,1,0,37,3,1,15,1,31,1,63,1,127,2,0,1,127,1,255,6,0,1,254,1,255,6,0,2,192,1,240,1,252,1,254,1,255,2,0,32,63,1,31,1,15,1,3,1,0,4,255,4,127,1,15,1,0,2,255,6,15,1,3,1,255,38,224,1,128,1,255,4,254,1,224,1,0,2,240,2,224,1,128,1,0,34,1,1,3,1,0,2,7,1,63,1,127,1,255,3,0,1,255,7,0,1,248,1,255,6,0,3,224,1,240,1,248,1,252,2,0,32,127,2,63,1,15,1,1,1,0,3,255,5,63,1,0,2,255,6,63,1,7,1,255,8,248,1,255,7,0,1,240,1,254,1,255,5,0,3,192,1,224,1,240,1,248,1,252,1,0,256,127,3,63,1,31,1,15,1,3,1,0,1,255,7,127,1,255,13,252,1,248,1,192,2,128,3,0,34,3,1,7,1,0,4,31,1,255,3,0,2,3,1,31,1,255,36,128,2,192,1,252,1,255,4,0,4,248,1,255,3,0,5,128,1,192,1,240,1,0,24,1,2,0,6,255,4,127,1,31,1,15,1,1,1,255,18,254,2,252,1,248,1,224,1,0,38,3,1,15,1,31,1,0,4,127,1,255,3,3,2,7,1,127,1,255,28,254,2,255,6,0,3,240,1,255,4,0,4,224,1,252,1,255,2,0,6,128,1,192,1,0,24,7,1,3,2,1,2,0,3,255,5,127,1,63,1,7,1,255,15,252,3,248,1,240,2,192,1,128,1,0,265,7,1,0,6,63,1,252,1,0,6,255,1,0,7,128,1,0,32,15,1,31,2,63,1,31,2,15,1,7,1,255,25,252,1,224,3,248,1,255,3,31,1,7,1,3,1,7,1,15,1,255,26,248,1,252,5,248,1,240,1,0,40,31,1,0,7,240,1,0,47,63,1,127,6,31,1,255,25,240,1,192,1,128,2,224,1,255,3,63,1,31,1,15,2,63,1,255,26,224,1,240,2,248,1,240,2,224,1,192,1,0,39,3,1,63,1,0,6,255,1,192,1,0,6,248,1,0,264,1,1,7,1,15,1,31,1,63,2,127,2,255,16,240,1,252,1,255,6,0,4,128,2,192,2,0,24,3,1,0,7,255,2,63,1,3,1,0,4,255,4,3,1,1,1,0,2,255,7,127,1,255,28,224,1,128,2,0,1,255,2,254,1,128,1,0,4,224,1,128,1,0,102,15,1,3,1,0,6,255,3,15,1,0,4,255,4,15,1,7,1,3,1,1,1,255,29,254,2,252,1,255,4,128,1,0,3,255,2,248,1,0,5,128,1,0,34,1,1,3,2,7,2,31,1,127,1,255,22,0,1,192,1,224,1,240,1,248,2,252,1,248,1,0,256,63,2,31,1,7,1,3,1,0,3,255,5,127,1,3,1,0,1,255,7,7,1,255,8,240,1,255,7,0,1,128,1,254,1,255,5,0,3,192,1,240,1,248,1,252,1,254,1,0,32,127,2,63,1,15,1,3,1,0,3,255,6,1,1,0,1,255,6,224,1,0,1,255,1,254,2,248,1,224,1,0,38,1,1,7,1,15,1,31,1,63,1,0,2,63,1,255,5,0,2,255,6,0,2,128,1,240,1,254,1,255,3,0,6,128,2,0,5,1,2,3,1,0,2,7,1,31,1,127,1,255,3,0,1,63,1,255,6,0,2,248,1,255,5,0,4,192,1,224,1,240,1,248,1,0,24,1,1,0,7,255,3,63,1,15,1,3,1,0,2,255,6,15,1,0,1,255,5,254,1,128,1,0,1,252,1,248,2,224,1,128,1,0,38,7,1,31,1,63,1,127,1,255,1,0,1,3,1,255,6,31,1,255,21,254,1,192,1,255,5,248,1,0,2,248,1,240,1,224,1,192,1,0,266,3,1,15,1,0,4,1,1,127,1,255,2,3,1,1,1,3,1,15,1,255,28,254,2,255,6,0,3,192,1,255,4,0,5,248,1,255,2,0,7,192,1,0,72,63,4,31,1,15,1,7,1,1,1,255,24,192,2,224,1,240,1,255,4,7,2,15,1,31,1,255,28,248,4,240,1,224,1,192,1,0,79,1,1,7,1,0,4,3,1,63,1,255,2,0,1,1,2,7,1,255,36,0,2,128,1,192,1,255,4,0,4,128,1,252,1,255,2,0,7,192,1,0,256,31,1,63,2,127,3,63,1,31,1,255,26,224,1,192,3,240,1,255,3,31,1,15,3,63,1,255,25,224,1,240,1,248,3,252,1,255,2,0,7,255,1,0,72,63,1,0,7,255,1,63,1,7,1,1,2,0,3,255,7,127,1,255,21,254,2,252,1,255,1,252,1,192,1,0,5,248,1,0,78,1,1,0,6,1,1,255,1,15,1,31,2,63,2,127,1,255,28,240,1,224,1,192,2,128,2,255,2,15,1,7,1,3,2,1,2,255,24,224,1,240,1,248,4,240,2,0,256,15,1,7,1,1,1,0,5,255,3,63,1,0,4,255,4,127,1,7,1,3,1,1,1,255,37,128,1,0,2,255,5,127,1,63,2,255,16,240,1,252,1,255,6,0,3,128,1,192,2,224,2,0,72,63,1,31,1,7,1,0,5,255,3,127,1,0,4,255,3,254,1,0,4,248,1,240,1,192,1,0,79,1,1,3,1,7,1,15,3,31,1,127,1,255,27,252,1,248,2,255,4,192,1,0,3,255,1,252,1,240,1,128,1,0,20,255,1,63,1,15,1,0,5,255,4,0,4,255,2,254,1,224,1,0,4,224,1,128,1,0,266,3,1,15,1,31,1,63,1,0,2,15,1,255,5,3,1,15,1,255,21,254,1,255,16,0,1,225,1,255,6,127,1,255,22,223,1,255,8,240,1,252,1,255,6,0,2,248,1,255,5,0,3,128,1,240,1,252,1,254,2,0,13,1,1,3,1,7,1,0,2,1,1,31,1,127,1,255,3,0,2,255,6,0,2,128,1,248,1,254,1,255,3,0,5,128,1,192,1,224,1,0,11,1,1,15,1,63,1,127,1,255,1,0,2,31,1,255,5,0,2,240,1,255,5,0,4,224,1,240,1,248,1,254,1,0,12,1,1,3,1,15,2,0,2,7,1,63,1,255,4,0,2,255,6,0,2,128,1,240,1,254,1,255,3,0,6,128,1,192,1,0,7,1,1,0,3,7,1,31,1,127,1,255,2,0,2,127,1,255,5,31,1,127,1,255,21,240,1,255,5,252,1,224,1,0,1,240,1,224,2,192,1,128,1,0,34,1,1,0,3,3,1,31,1,127,1,255,2,0,2,127,1,255,5,0,2,192,1,252,1,255,4,0,4,128,1,192,1,240,2,0,256,127,4,63,1,31,1,15,1,7,1,255,24,224,1,192,2,224,1,248,1,255,3,31,1,15,3,127,1,255,27,254,1,248,2,252,1,255,4,1,1,0,2,1,1,7,1,255,35,0,2,128,1,192,1,240,1,255,3,15,2,31,2,127,1,255,27,240,3,248,1,254,1,255,3,0,1,1,2,3,1,15,1,255,27,254,5,252,1,248,1,224,1,0,8,31,5,15,1,7,1,1,1,255,23,254,1,224,4,192,2,128,1,0,1,1,1,3,2,1,2,0,3,255,6,127,1,31,1,255,17,254,2,252,2,248,1,240,1,192,1,0,48,3,4,1,2,0,2,255,6,127,1,63,1,255,16,248,1,252,2,248,2,240,1,224,1,128,1,0,256,1,1,0,7,255,1,31,1,0,6,255,2,31,1,3,1,1,2,3,1,31,1,255,34,227,1,128,1,0,2,128,1,225,1,255,3,127,1,63,2,127,1,255,27,252,1,240,1,224,2,240,1,252,1,255,2,63,1,7,1,3,2,7,1,31,1,255,28,254,2,255,4,195,1,0,4,195,1,255,4,63,1,127,1,255,28,248,1,224,1,192,2,224,1,248,1,255,1,252,1,0,6,128,1,0,23,127,1,15,1,0,6,255,2,0,6,248,1,192,1,0,22,7,1,0,7,255,2,0,6,255,1,248,1,0,70,7,1,0,7,255,1,127,1,0,6,254,1,224,1,0,272,7,1,15,1,31,1,63,2,127,1,31,1,255,28,248,1,224,1,192,1,255,5,127,1,15,2,255,30,252,1,248,1,255,5,135,1,1,1,0,1,255,37,240,1,192,1,128,1,255,5,127,1,31,2,255,29,254,1,248,1,240,1,255,5,15,1,3,1,1,1,255,16,252,1,255,7,0,1,128,1,224,1,248,1,252,1,254,2,255,1,0,140,1,2,3,2,0,1,7,1,63,1,255,5,127,1,255,7,192,1,252,1,255,6,0,2,128,1,192,1,224,1,240,1,248,2,0,256,127,1,63,2,31,1,15,1,3,1,0,2,255,7,15,1,255,16,192,1,224,1,255,6,15,1,31,1,255,30,252,1,254,1,255,6,0,1,1,1,223,1,255,37,128,1,192,1,251,1,255,5,31,1,63,1,255,30,240,1,248,1,255,6,1,1,3,1,31,1,255,28,248,1,255,1,254,2,252,1,248,1,224,1,128,1,0,137,3,2,1,2,0,4,255,4,127,1,31,1,7,1,0,1,255,7,30,1,255,6,248,1,0,1,248,2,240,1,224,1,192,1,0,275,15,1,3,1,1,2,0,4,255,6,127,1,63,1,255,24,192,1,0,3,128,1,255,4,127,1,63,2,127,1,255,27,248,1,224,3,240,1,255,3,15,1,7,1,3,2,7,1,255,28,254,1,252,1,254,1,255,4,129,1,0,4,255,4,127,1,63,1,127,1,255,28,248,1,224,1,192,2,240,1,255,3,0,6,254,1,255,1,0,7,192,1,0,150,1,1,15,1,0,6,255,2,0,6,224,1,254,1,0,288,15,1,3,1,0,6,255,2,31,1,0,5,255,3,63,1,15,2,7,2,255,28,252,1,248,1,252,1,254,1,255,3,3,1,0,3,1,1,255,35,224,1,128,3,192,1,255,3,127,1,31,1,15,1,31,1,63,1,255,27,252,1,248,1,240,2,252,1,255,3,7,1,1,3,3,1,255,24,240,1,248,1,252,1,254,2,255,3,0,7,192,1,0,130,1,1,3,5,63,1,255,23,128,1,192,1,240,2,248,3,240,1,0,296,3,1,1,1,0,6,255,3,63,1,15,1,0,3,255,5,127,1,0,2,255,7,127,1,255,30,248,1,224,1,255,6,15,1,7,1,255,31,254,1,255,6,1,1,0,1,255,7,127,1,255,30,240,1,224,1,255,6,31,1,15,1,255,16,0,1,248,1,255,6,0,3,192,1,224,1,240,1,248,2,0,112,1,1,0,7,255,2,127,1,31,1,3,1,0,3,255,5,0,3,255,3,254,1,240,1,0,3,240,1,224,1,128,1,0,325,63,1,31,2,15,1,7,1,3,1,0,2,255,7,63,1,255,16,224,2,248,1,255,5,3,1,7,1,15,1,255,29,252,1,254,1,255,6,0,3,255,5,63,1,127,1,255,30,192,1,224,1,240,1,255,5,7,1,15,1,31,1,255,29,252,2,255,6,0,3,254,1,255,4,0,4,224,1,252,1,255,2,0,7,128,1,0,100,3,1,31,1,127,1,255,1,0,4,255,4,0,4,240,1,254,1,255,2,0,6,128,1,192,1,0,336,255,1,3,1,0,6,255,4,127,2,63,1,31,1,255,25,224,1,128,2,192,1,224,1,255,3,63,1,31,1,15,1,31,1,127,1,255,27,252,1,240,2,248,1,252,1,255,3,3,1,1,3,7,1,255,35,128,1,0,3,192,1,255,3,127,1,63,1,31,1,63,1,255,27,192,2,224,1,240,2,252,1,255,2,0,6,240,1,255,1,0,7,128,1,0,72,1,1,3,5,1,1,0,1,255,24,224,1,240,1,248,2,240,2,224,1,192,1,0,344,15,1,3,1,0,6,255,3,1,1,0,4,255,4,15,1,7,1,3,2,255,29,254,1,252,1,254,1,255,4,0,4,255,5,127,1,63,1,127,1,255,28,224,1,192,2,224,1,255,4,31,1,7,2,15,1,255,28,254,1,252,3,255,4,1,1,0,3,255,24,240,1,252,1,254,1,255,5,0,5,128,2,192,1,0,72,63,1,31,1,3,1,0,5,255,3,0,5,255,1,254,1,240,1,0,5,128,1,0,367,1,1,0,7,255,2,127,1,63,1,15,1,1,1,0,2,255,6,3,1,0,1,255,7,63,1,255,8,129,1,255,22,248,1,255,6,191,1,3,1,255,8,240,1,255,7,31,1,255,22,128,1,255,7,127,1,255,8,3,1,255,22,248,1,255,7,7,1,255,8,240,1,255,7,0,1,224,1,254,1,255,5,0,3,192,1,224,1,248,2,252,1,0,53,1,2,3,1,0,2,7,1,63,1,127,1,255,3,0,1,63,1,255,6,0,2,248,1,255,5,0,4,192,1,224,1,240,2,0,384,31,1,15,2,7,2,3,1,0,2,255,7,63,1,255,16,240,2,248,1,254,1,255,4,1,2,3,1,15,1,255,30,254,2,252,1,248,1,240,1,192,1,0,8,31,3,15,2,7,1,1,1,0,1,255,7,127,1,255,16,240,3,252,1,255,4,3,2,7,1,31,1,255,28,252,1,254,1,255,6,0,3,192,1,255,4,0,4,128,1,248,1,255,2,0,7,128,1,0,24,3,4,1,1,0,3,255,6,63,1,15,1,255,15,254,1,248,3,240,1,224,1,192,1,128,1,0,393,7,1,0,6,1,1,255,1,3,1,0,4,3,1,255,4,127,1,63,1,127,1,255,27,252,1,224,2,192,1,128,2,0,1,254,1,0,31,15,1,0,6,7,1,255,1,15,1,1,1,0,3,7,1,255,34,248,1,192,1,128,3,0,2,255,2,31,1,15,2,7,2,3,1,255,24,192,1,224,1,240,2,248,2,255,2,0,7,255,1,0,32,255,1,0,6,255,1,224,1,0,6,192,1,0,394,1,1,3,1,7,1,15,2,31,2,255,28,248,1,240,2,255,4,0,4,254,1,252,1,224,1,0,38,1,1,7,1,15,2,31,3,127,1,255,27,254,1,248,1,240,2,255,3,254,1,0,4,252,1,248,1,224,1,0,13,1,1,0,7,255,1,127,1,31,1,1,1,0,4,255,4,1,1,0,3,255,5,127,1,63,2,255,16,224,1,252,1,254,1,255,5,0,4,128,2,192,2,0,3,1,1,3,3,7,1,15,1,63,1,255,14,252,1,255,7,0,2,192,1,224,1,240,1,248,3,0,283,7,1,31,1,127,1,255,2,0,2,255,6,0,2,252,1,255,5,0,3,128,1,224,1,248,1,252,1,254,1,0,12,3,1,7,1,15,1,31,1,0,2,31,1,127,1,255,4,0,2,255,6,0,2,192,1,248,1,254,1,255,3,0,6,128,1,192,1,0,7,1,1,0,3,15,1,63,1,127,1,255,2,0,2,255,6,63,1,255,22,195,1,255,8,248,1,255,7,0,2,255,6,0,3,240,1,252,1,254,1,255,2,0,7,128,1,0,6,1,1,3,1,0,2,3,1,31,1,127,1,255,3,0,1,1,1,255,6,127,1,255,22,135,1,255,8,248,1,254,1,255,6,0,2,255,6,0,3,224,1,248,1,252,1,254,1,255,1,0,32,31,2,15,1,7,1,1,1,0,3,255,5,127,1,3,1,0,1,255,7,7,1,255,8,224,1,248,1,255,6,7,1,63,1,255,21,192,1,255,5,252,1,128,1,0,1,240,2,224,1,192,1,0,276,1,4,0,4,255,5,127,1,63,1,15,1,255,16,254,4,252,2,248,1,224,1,0,8,31,1,63,2,31,2,15,1,7,1,1,1,255,23,252,1,224,3,192,2,128,1,0,2,3,3,1,2,0,3,255,6,127,1,31,1,255,16,254,2,252,2,248,1,240,1,224,1,192,1,0,8,255,1,127,1,63,2,31,1,15,1,7,1,1,1,255,22,254,1,248,1,128,1,192,2,128,2,0,3,3,1,7,2,3,1,1,2,0,2,255,7,63,1,255,16,254,1,252,1,248,2,240,2,224,1,128,1,1,1,0,7,255,2,127,3,63,1,15,1,7,1,255,21,254,1,252,1,240,1,0,1,128,2,0,45,1,1,0,7,255,3,127,2,63,1,31,1,7,1,255,24,0,3,128,1,240,1,255,3,0,5,224,1,252,1,255,1,0,7,128,1,0,280,3,1,0,7,255,1,127,1,0,6,255,1,248,1,0,30,63,1,3,1,0,6,255,2,0,6,240,1,0,23,3,1,0,7,255,1,63,1,0,6,254,1,224,1,0,30,127,1,7,1,0,6,255,1,252,1,0,6,192,1,0,23,7,1,0,7,255,1,127,1,0,6,252,1,192,1,0,30,255,1,15,1,0,6,255,1,252,1,0,6,128,1,0,63,1,1,0,7,255,1,15,1,0,6,255,2,31,1,7,1,3,3,1,1,255,24,192,1,224,1,240,2,248,2,240,2,0,608,255,1,127,1,31,1,3,1,0,4,255,4,0,4,255,3,248,1,0,4,224,1,192,1};

// ==========================================================================
// SECTION: Arduino Serial port 
// ==========================================================================


// Fast GPIO access for MKR1000 
#ifdef USE_ARDUINO_MKR

inline void digitalWrite_fast(int pin, bool val) {  if (val)  
      PORT->Group[g_APinDescription[pin].ulPort].OUTSET.reg = (1ul << g_APinDescription[pin].ulPin);
   else     
      PORT->Group[g_APinDescription[pin].ulPort].OUTCLR.reg = (1ul << g_APinDescription[pin].ulPin);}

inline int digitalRead_fast(int pin) {
   return !!(PORT->Group[g_APinDescription[pin].ulPort].IN.reg & (1ul << g_APinDescription[pin].ulPin));}

#define CTS_IS_ACTIVE (digitalRead_fast(CTS_PIN) == HIGH) 

// Using SAMD21 SERCOM for UART instances
Uart SerialBBC (&sercom3, RXD_PIN, TXD_PIN, SERCOM_RX_PAD_1, UART_TX_PAD_0); // Create the new UART instance assigning it to pin 0 and 1
void SERCOM3_Handler() {
  SerialBBC.IrqHandler();
}
#endif USE_ARDUINO_MKR



// Keep track of CTS timing with this interrupt handler (micros() OK if we're quick about it....)
volatile unsigned long CTS_since = 0;
void CTSchanged() {CTS_since = micros();} 

void setup_serial() {
  
  // Using SAMD21 SERCOM for UART instances
  #ifdef USE_ARDUINO_MKR 
  pinPeripheral(RXD_PIN, PIO_SERCOM); //Assign RX function to pin 0
  pinPeripheral(TXD_PIN, PIO_SERCOM); //Assign TX function to pin 1
  #endif USE_ARDUINO_MKR
  
  // SET UP SERIAL
  Serial.begin(115200);
  SerialBBC.begin(115200);
 
  pinMode(RTS_PIN, OUTPUT);
  digitalWrite(RTS_PIN, HIGH);        
  pinMode(CTS_PIN, INPUT);
  attachInterrupt(digitalPinToInterrupt(CTS_PIN), CTSchanged, RISING); 
}


// Implement hardware flow control by monitoring CTS
void raw_write(byte byteOut) {
   while (
          !(
            CTS_IS_ACTIVE &&                // We must be clear to send
            (micros() - CTS_since > 3) &&   // for at least 3us
            (micros() - CTS_since < 20)     // and last successful byte transfer <20us ago
           )
         ){};                               // Otherwise wait for this condition
   SerialBBC.write(byteOut); SerialBBC.flush();
      
   if (CTS_IS_ACTIVE) {
     CTS_since = micros()+3;}
}

int long raw_read() {while (SerialBBC.available() == 0){};return SerialBBC.read();}


// ==========================================================================
// SECTION: Serial I/O routines for communication with Client
// ==========================================================================

int long read_addr() {uint32_t addr = 0;for( int a = 0; a < 4; a++ ){addr = addr * 256 + raw_read();}return addr;}

void send_byte(byte byteOut) {raw_write(byteOut);if (byteOut==ESCAPE) {raw_write(ESCAPE);};}

void send_cmd(byte byteOut) {raw_write(ESCAPE);raw_write(byteOut);}

void send_addr(uint32_t addr) {send_byte(addr >> 24);send_byte((addr >> 16) & 0xFF);send_byte((addr >> 8) & 0xFF);send_byte(addr & 0xFF);}


String read_string() {
  byte nextByte = 0; int index = 0; char filename[12];
  while (nextByte != 0x0D){
    if (nextByte != 0) {filename[index++] = nextByte;}
    nextByte = raw_read();
  }
  return filename;
}

void sendLogo() {
  for(int n=0; n < 4546; n=n+2) {
    int value = owlLogo[n];
    int runlength = owlLogo[n+1];
    for(int x=0; x < runlength; x++) {
                send_byte(value);
    }
  }
}

// ==========================================================================
// SECTION: OSFSC
// ==========================================================================


void runOSFSC() {
  byte X = raw_read(); byte Y = raw_read(); byte A = raw_read();
  switch (A)
  {/*
    case 0: // OPT Handler
    case 1: // Check EOF
    case 2: // *Handler
    case 3: // Unrecognised * command handler
    case 4: // *RUN handler
    case 5: // *CAT handler
    case 6: // Shutdown files
    case 7: // Give file handle ranges
    case 8: // *ENABLE checker */
    
    case 255: // BOOT (See https://github.com/sweharris/TubeHost )
    send_byte(255); send_byte(0);send_byte(X);
    break;
    
    default:
    Serial.print("Unhandled OSFSC A=");
    Serial.print(A, HEX);
    break;
    
  }  // end of switch
}

// ==========================================================================
// SECTION: OSFILE
// ==========================================================================


void runOSFILE() {
  uint32_t end  = read_addr();
  uint32_t save = read_addr();
  uint32_t exec = read_addr();
  uint32_t load = read_addr();
  String filename = read_string();
  byte A = raw_read();

  switch (A) {

    case 255: // LOAD
    timer = micros();
    
    send_cmd(0xE0);  // Load data response
    send_addr(load); // Address to load to 
    sendLogo();      // Data;
    send_cmd(0xB0);  // End 
    
    timer = micros() - timer;
    Serial.print("*LOAD ");
    Serial.print(filename);
    Serial.print(" took ");
    Serial.println(timer, DEC);
    break;
    
    default:
    Serial.print("Unhandled OSFILE A=");
    Serial.print(A, HEX);
    break;
    
  }  // end of switch
  
  // Send results
  send_byte(1);    // File found; directories aren't possible
  send_addr(end);
  send_addr(save);
  send_addr(exec);
  send_addr(load);
}

// Replace with jump table
void runCommand (const byte inByte) {
  switch (inByte) {
    case OSFSC: runOSFSC();
    break;
    
    case OSFILE: runOSFILE();
    break;
    
    default: {
      Serial.print("Unhandled command 0x");
      Serial.print(inByte, HEX);
    }
    break;
  }  // end of switch
}


// ==========================================================================
// SECTION: SETUP & MAIN
// ==========================================================================
void setup() {
  setup_serial();
}

void loop() {
  // if serial data available, process it
  if (SerialBBC.available () && (raw_read() == ESCAPE)) {
    int nextByte = raw_read();
    if (nextByte != ESCAPE) {runCommand (nextByte);}; // run command if it's not an escaped escape
  }
}  
Last edited by 8bitkick on Sun Mar 04, 2018 12:26 am, edited 2 times in total.

User avatar
BigEd
Posts: 2091
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: HostFS and microcontrollers?

Post by BigEd » Sat Mar 03, 2018 5:15 am

That's a milestone - great work!

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Sat Mar 03, 2018 4:19 pm

BigEd wrote:That's a milestone - great work!
Myelin already started and cracked the timing for the hardware flow control which helped! He mentions sync issues above which are a bit worrying - I added in an interrupt routine to help track CTS changes which might fix this. It seems fine on one large transfer... not tested much else yet.

Re efficiency, real world I got ~6kB/sec load with UPURS. During a file load the BBC CTS duty cycle is about 50% receiving ~100 byte bursts (UPURSFS buffer is set to 96 bytes I think). I might well not be doing things optimally here... might be better to back off a bit...
Screen Shot 2018-03-03 at 7.46.28 AM.png

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Mon Mar 05, 2018 12:45 am

wifi.JPG
Bit more progress... I have the wifi up on the Arduino host!

Not the first time Beeb has had wifi (usually via serial to a term I think?)... combining with TubeHost could be a bit more powerful. Web pages / FTP sites could appear as a virtual drive you can navigate around.

I am thinking wget would act a bit like *TYPE? Requesting text only versions of pages from Google cache / stripping most tags to make them a more beeb friendly.

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Mon Mar 05, 2018 1:38 am

8bitkick wrote:Myelin already started and cracked the timing for the hardware flow control which helped! He mentions sync issues above which are a bit worrying - I added in an interrupt routine to help track CTS changes which might fix this. It seems fine on one large transfer... not tested much else yet.
It's good to hear that it's been working for you! If you want to throw your code up on GitHub, I'll see if it fixes the issues I was having. Some possibilities:

- Your CTS interrupt fixed things (I'm hoping for this one!)

- The timing situation is different: your code is running directly on the MCU so it has lower latency than my setup (Perl script running on macOS, talking to the MCU over a USB-serial connection).

- The MKR1000 at 48MHz is catching CTS transitions better than my 16MHz ATMEGA32U4.

- The problem is still there but requires more messing around to trigger. For me, it would usually happen partway through loading a game, except usually 4-5 files would successfully load before something went wrong.

I have a board made up with an ATSAMD21E18A, which appears to be the same as the core of the ATSAMW25 module, so if I'm lucky I'll be able to burn the Arduino bootloader in there and run your code, and try this out :)
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Mon Mar 05, 2018 2:58 am

myelin wrote: If you want to throw your code up on GitHub, I'll see if it fixes the issues I was having.
https://github.com/8bitkick/ArduinoHost

Lets hope so! My set up allowed for lower latency responses for all the reasons you mention, and a 32-bit MCU helps too for sure...

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Tue Mar 20, 2018 5:10 am

I updated ArduinoHost a little and also pointed it to bbcmicro.co.uk over wifi to give it some files (read only).

(With HTTP Range request you can specify read addresses of the ssd image to download. e.g. initially just reading 512 bytes of the DFS disc catalogue.... then subsequent *LOADs request the data range you need and relay stream direct to beeb .... )

Pretty cool streaming a game from the bbcmicro.co.uk website to a BBC Micro :D
IMG_5635.jpg
Still lots to implement though...

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Tue Mar 20, 2018 7:33 am

.ssd access via wifi, with an off-the-shelf Arduino board plus a level shifter, and the UPURS version of HostFS.

Now *that* is pretty amazing :)
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

dominicbeesley
Posts: 639
Joined: Tue Apr 30, 2013 11:16 am
Contact:

Re: HostFS and microcontrollers?

Post by dominicbeesley » Tue Mar 20, 2018 1:01 pm

I'm impressed!

I just ported JGH's version of TubeHost to the 6809, I may have to try that with this set up.

I think it might be a good time, now there's interest, to try and combine the jgh and upurs versions of the HostFs client. As far as I can tell there's not much in it other than (for some unfathomable reason) the upurs one uses a different escape character making the actual servers incompatible only in the escape char. The rest looks easily merge-able.

Out of interest do you use &9B or &7F as <esc> on your controller?

D

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Tue Mar 20, 2018 2:38 pm

dominicbeesley wrote: Out of interest do you use &9B or &7F as <esc> on your controller?

D
Thanks! Still *lots* to implement but it works!!

7F (I’m communicating with UPURSFS)... it’s a #define though.
Last edited by 8bitkick on Tue Mar 20, 2018 2:50 pm, edited 1 time in total.

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Tue Mar 20, 2018 2:48 pm

myelin wrote:.ssd access via wifi, with an off-the-shelf Arduino board plus a level shifter, and the UPURS version of HostFS.

Now *that* is pretty amazing :)
:D

The trickiest bit was getting the timing right on UPURS...! I've done a bit of testing now, it's pretty stable at least in my set-up.

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Tue Mar 20, 2018 6:41 pm

Nitpicky request... can you put a license on your github repo? I'd love to mess with and hopefully help with this code, but corporate rules dictate that it have a recognizable/standard open source license (Apache 2.0 matches my project's license, but GPL, MIT, BSD are all also fine -- anything compatible is good) before I do so :)

I'm very curious to port your interrupt technique back to my atmega32u4 code, and see if that fixes the problems I was having before!
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Tue Mar 20, 2018 6:56 pm

myelin wrote:Nitpicky request... can you put a license on your github repo? I'd love to mess with and hopefully help with this code, but corporate rules dictate that it have a recognizable/standard open source license (Apache 2.0 matches my project's license, but GPL, MIT, BSD are all also fine -- anything compatible is good) before I do so :)

I'm very curious to port your interrupt technique back to my atmega32u4 code, and see if that fixes the problems I was having before!
License added!

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Tue Mar 20, 2018 7:12 pm

Thank you!
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

crj
Posts: 834
Joined: Thu May 02, 2013 4:58 pm
Contact:

Re: HostFS and microcontrollers?

Post by crj » Tue Mar 20, 2018 8:36 pm

Hang on... you're managing to bridge between Acorn filesystem operations and http fetches in 256Kbytes flash and 32Kbytes RAM, including the necessary IP and WiFi stacks? Or am I misconstruing?

Out of interest, how tight a fit is that?

I'm working on something it might be interesting to shoehorn such code into as a side attraction.

A question I contemplated when thinking about this, and couldn't come up with a good answer for: how do you get the URL of the .ssd into the Beeb? Typing it in by hand each time wouldn't be a whole bunch of fun.

Options I considered:
  • Have some kind of menu in local storage which embeds the URLs. (But what local storage, how did it get there, how is it updated, and why not download all the games while you're at it?)
  • Define a content-type for Acorn filesystem directories and persuade a few selected sites to support it
  • Create directories by screen-scraping unstructured web pages, such as the index.html that Apache dynamically generates
  • Embed a web browser (but even lynx is huge by Arduino standards)
  • Rely on the fact you're network-connected; run the bridge on another system
I leaned a little towards the final option, noted that it didn't require any further design in the short term and kicked it into the long grass. /-8

crj
Posts: 834
Joined: Thu May 02, 2013 4:58 pm
Contact:

Re: HostFS and microcontrollers?

Post by crj » Tue Mar 20, 2018 8:55 pm

PS: I've just remembered the other option I considered: give up entirely on choosing your SSD via the Beeb. Instead, use a remote system's UI to navigate to the ssd you want and mount it up ready for shift+break on the Beeb.

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Tue Mar 20, 2018 9:17 pm

Not sure how much work the host MCU has to do, and how much is performed by the CPU inside the WINC1500 module, but the code uses the WiFi101 Arduino library, and the .ssd URL is hardcoded into the source.
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

User avatar
8bitkick
Posts: 121
Joined: Thu Aug 11, 2016 4:45 pm
Location: California
Contact:

Re: HostFS and microcontrollers?

Post by 8bitkick » Tue Mar 20, 2018 9:22 pm

crj wrote:Hang on... you're managing to bridge between Acorn filesystem operations and http fetches in 256Kbytes flash and 32Kbytes RAM, including the necessary IP and WiFi stacks? Or am I misconstruing?
Arduino sketch uses 47456 bytes (18% of MKR1000) of Flash... UPURSFS ROM on the beeb handles the client side of things. I'd definitely be interested in your project. I liked the idea of the BBC having Internet apps of which the bbcmicro.co.uk ' web drive' is just the first example... a web browser would be awesome!

With HTTP Range request (which bbcmicro.co.uk apache server supports) so you can specify read addresses of the ssd image to download. e.g. initially just reading 512 bytes of the DFS disc catalogue.... then subsequent *LOADs request the data range you need and relay stream direct to beeb .... so not stored in the host MCU (buffered in wifi part in module as Myelin says)

My next step was to add the ability to search / browse bbcmicro.co.uk from the beeb and load any game. This can be done by doing an HTTP GET to the bbcmicro.co.uk site using the ?search query string, and stripping tags from the response to list games (might be a neater way that just returns json).

Rough plan in pseudocode below, assuming *webhost is already bbcmicro.co.uk... could be a pretty menu loaded straight from Arduino on boot...

Code: Select all

10 INPUT "What game to search for ",A$
20 *websearch A$ (or OSCLI equivalent)

    <Arduino does HTTP GET bbcmicro.co.uk/?search=A$>
    <Arduino disposes all incoming web data but extracts list of disc titles+URLs into an array>
    <Arduino pushes the numbered list of discs to BBC screen>
 
30 INPUT "Which disc ",N
40 *webmount N

    <Arduino downloads DFS catalog of the specified disc / mounts>

60 *!BOOT 
    
Last edited by 8bitkick on Tue Mar 20, 2018 9:43 pm, edited 1 time in total.

User avatar
myelin
Posts: 442
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: HostFS and microcontrollers?

Post by myelin » Tue Mar 20, 2018 9:32 pm

Some possibly-off-topic digging I just did in the internals of the Arduino WiFi101 library: It looks like the WINC1500 chip handles things from the sockets layer on down.

Here's the socket driver from WiFi101: https://github.com/arduino-libraries/Wi ... e/socket.c

Note the hif_send(...) calls everywhere. Those call into driver/source/m2m_hif.c, and boil down to various nm_* calls (nm_write_reg, nm_bsp_sleep, nm_write_block, etc).

The nm_* functions are defined in drive/source/nmbus.c, which is commented as containing the NMC1000 bus API implementation. The NMC1000 is a WiFi SoC made by Newport Media, acquired by Atmel in 2014.

I think that's the bottom of the rabbit hole... the ATWINC1500 module is probably an ATSAMD21 and an NMC1000 (maybe packaged together or combined into a single chip).
SW/EE from New Zealand, now in Mountain View, CA, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

Post Reply