New hardware suggestion - Pi econet server

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
User avatar
IanS
Posts: 717
Joined: Mon Aug 31, 2009 6:02 pm
Contact:

Re: New hardware suggestion - Pi econet server

Post by IanS » Wed Sep 19, 2018 5:37 pm

johnkenyon wrote:
Wed Sep 19, 2018 2:37 pm
The collision detect circuit uses half a LM319 - you need the other half to handle the incoming clock and received data, so there's no additional silicon required there. If you don't have explicit detection of a collision, then you have to detect collisions by implication - e.g. timeout waiting for an acknowledgement, and even then you don't know if the timeout occurred because of a collision or the far end being to busy.

The "clock present" detection is a definite candidate for deletion - I can't see much difficulty using software to emulate this function.
There are two LM319's on a normal Econet module, two comparators in each. One chip is used for Clock and Data recovery. The other is used for collision detection.

User avatar
flynnjs
Posts: 806
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: New hardware suggestion - Pi econet server

Post by flynnjs » Wed Sep 19, 2018 6:13 pm

USB Econet uses 2x SIP491 (1 for clock, 1 for data) and 1x LM339 (collision detect)

gazzaD
Posts: 35
Joined: Sun Jun 18, 2017 11:37 am
Contact:

Re: New hardware suggestion - Pi econet server

Post by gazzaD » Mon Sep 24, 2018 10:28 am

It's been partially done using an Arduino DUE board

https://github.com/stardot/ArduinoFilestore

The DUE is no longer available from the official store, but the versions available from the Chinese vendors on eBay seem to work just as well.
Gareth

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

Re: New hardware suggestion - Pi econet server

Post by myelin » Mon Sep 24, 2018 8:24 pm

flynnjs wrote:
Mon Sep 17, 2018 6:54 pm
The USB Econet dongle works. But there's been lack of enthusiasm to finish
the host software. We have something mostly working on Linux+Windows
but none of those involved would attempt anything on riscos.

I could make dongles available to anyone willing to commit to doing
something on the host software side.
Would it be possible to open source the host software (or all the software)? That would make it much easier to contribute to. (My selfish motive here is that I designed my own USB Econet interface hardware and never wrote any software for it, and I'd love to be able to work together on that.)
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: 477
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: New hardware suggestion - Pi econet server

Post by myelin » Thu Oct 04, 2018 5:02 pm

This conversation gave me a bit of energy to pick up my own USB Econet project and get it a bit closer to working. It's still far far behind flynnjs's original one and gazzaD's Arduino Filestore, but the raw output side of it seems to be going now -- the microcontroller sends bytes to the CPLD, which handles zero stuffing and getting everything out onto the Econet line in sync with the clock etc.

If I were designing something to go on a Pi, I'd probably use a small 3.3V FPGA (Lattice MachXO2 probably) rather than the CPLD on this board; as that would give a bit more room for the Econet side of things, plus a small buffer, so the Pi wouldn't need to keep feeding in bytes every 40us like on the current board.

One thing I keep wondering about is whether it's possible to just bit bang the whole thing on a microcontroller; 200kHz isn't that fast. I figure it's pretty important to set up the data output as soon as possible after the falling clock edge, though, to handle longer cables. Maybe it might be possible to hack something up with SPI, switching between 8 and 9 (maybe 10?) bit mode depending on the zero stuffing state.

I really like the TinyFPGA suggestion earlier in the thread; on that chip there's room to implement the whole system including Filestore.
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
flynnjs
Posts: 806
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: New hardware suggestion - Pi econet server

Post by flynnjs » Fri Oct 05, 2018 6:56 pm

myelin wrote:
Thu Oct 04, 2018 5:02 pm
Maybe it might be possible to hack something up with SPI, switching between 8 and 9 (maybe 10?) bit mode depending on the zero stuffing state.
The CPLD on my board does convert between SPI and econet by bitstuffing and unstuffing.
On RX, it obtains byte sync by usng on the opening flags and the econet clock gets
passed through to the SPI slave (USB microcontroller). The start/stop flags are used to
create a /SS line. Very large econet frames get sent in multiple USB frames. Userland
detect end of econet frame by getting a USB fragment of less than the max fragment size
(and a 0 byte frame if a precise multiple)
On TX, the microcontroller asserts a transmit request line to the CPLD and the
CPLD transmits the start flag and asserts the /SS line obtain data from the micro.

All this works, hardware, CPLD firmware, USB microcontroller software.
I have portable user mode library which uses libusb to send and receive
econet frames, tested working.
Every time I ask for some help finishing a bit of code to port between raw
econet frames and AUN there's a stoney silence.

This might be a winter project but I have others on the go too :roll:
Last edited by flynnjs on Fri Oct 05, 2018 6:59 pm, edited 1 time in total.

User avatar
danielj
Posts: 6691
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: New hardware suggestion - Pi econet server

Post by danielj » Fri Oct 05, 2018 7:06 pm

I'd love to help, but it's beyond my skillset I think :( Is the code on github?

d.

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

Re: New hardware suggestion - Pi econet server

Post by myelin » Fri Oct 05, 2018 7:22 pm

flynnjs wrote:
Fri Oct 05, 2018 6:56 pm
The CPLD on my board does convert between SPI and econet by bitstuffing and unstuffing.
On RX, it obtains byte sync by usng on the opening flags and the econet clock gets
passed through to the SPI slave (USB microcontroller). The start/stop flags are used to
create a /SS line. Very large econet frames get sent in multiple USB frames. Userland
detect end of econet frame by getting a USB fragment of less than the max fragment size
(and a 0 byte frame if a precise multiple)
That's really clever; this way you can avoid having to buffer too much on the CPLD side. Do you pause the SPI clock to get the microcontroller to skip the stuffed zero bits?

I had to jump through hoops to share a buffer between the transmit and receive sides (i.e. there's a 9-bit buffer for the serial comms to the microcontroller, and an 8-bit buffer for the Econet side). A GPIO line from the microcontroller selects the line direction, which works out OK because Econet is half duplex anyway. The whole thing runs off the 24MHz serial clock.
flynnjs wrote:
Fri Oct 05, 2018 6:56 pm
On TX, the microcontroller asserts a transmit request line to the CPLD and the
CPLD transmits the start flag and asserts the /SS line obtain data from the micro.
Very nice. As with reception, I guess you could just pause the SPI clock for one cycle when transmitting a stuffed zero bit.

Now I want to redo my own design to work like this; it's much smarter :)
flynnjs wrote:
Fri Oct 05, 2018 6:56 pm
All this works, hardware, CPLD firmware, USB microcontroller software.
I have portable user mode library which uses libusb to send and receive
econet frames, tested working.
Every time I ask for some help finishing a bit of code to port between raw
econet frames and AUN there's a stoney silence.

This might be a winter project but I have others on the go too :roll:
I think the circle of people interested in the details of how Econet works is pretty small, especially folks who understand AUN too. I'd be happy to help, but because of my employment contract, I can only contribute if it's open source (Apache, MIT, BSD, GPL and a few other licenses).

I started looking at the Econet-to-AUN thing a while back (as part of my unfinished attempt to add Econet support to Arculator). How are we supposed to handle scout frames? Econet's four-way handshake verifies that there's an active receiver there before sending the actual packet, and failure to respond to the scout frame is a different error to failing to ack the data frame. Is it safe to just auto-ack every scout frame and then abort the data frame if no ack comes back over UDP from the destination machine?
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
sydney
Posts: 2259
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne
Contact:

Re: New hardware suggestion - Pi econet server

Post by sydney » Fri Oct 05, 2018 8:31 pm

danielj wrote:
Fri Oct 05, 2018 7:06 pm
I'd love to help, but it's beyond my skillset I think :( Is the code on github?

d.
Ditto. Every time Jason posts about it i think I should have a go but I wouldn't even know where to start

JonC
Posts: 684
Joined: Wed May 14, 2014 9:19 pm
Location: Wakefield
Contact:

Re: New hardware suggestion - Pi econet server

Post by JonC » Sat Oct 06, 2018 11:38 am

If it's a question of funds, I'm more than happy to contribute to something like this which helps everyone. But if it's skills as others have said, I'm out of my depth there.
Jon
Image

User avatar
Lardo Boffin
Posts: 1321
Joined: Thu Aug 06, 2015 6:47 am
Contact:

Re: New hardware suggestion - Pi econet server

Post by Lardo Boffin » Sat Oct 06, 2018 11:52 am

JonC wrote:
Sat Oct 06, 2018 11:38 am
If it's a question of funds, I'm more than happy to contribute to something like this which helps everyone. But if it's skills as others have said, I'm out of my depth there.
Same here! Money is about the only thing I can offer on this one.
BBC model B 32k issue 4, 16k sideways RAM, Watford 12 ROM board, Acorn 6502 coproc
BBC model B 32k issue 7, turboMMC, Opus Challenger 3 512k, Pi 3 coproc
USA Model B
BBC Master, Datacentre + HDD, pi co-proc, econet

matt_nottm
Posts: 113
Joined: Sat Feb 11, 2017 11:54 am
Contact:

Re: New hardware suggestion - Pi econet server

Post by matt_nottm » Sat Oct 06, 2018 1:40 pm

Ditto, I would be happy to contribute cash.

User avatar
flynnjs
Posts: 806
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: New hardware suggestion - Pi econet server

Post by flynnjs » Sat Oct 06, 2018 6:21 pm

myelin wrote:
Fri Oct 05, 2018 7:22 pm
That's really clever; this way you can avoid having to buffer too much on the CPLD side. Do you pause the SPI clock to get the microcontroller to skip the stuffed zero bits?
Yes, the CPLD keeps track of where the stuffed bits need to be added/dropped and
then the micro isn't clocked during the extra data bit so it is lost. On the transmit
side the CPLD, being master, pauses the SPI clock while it sends an extra bit.
To get this all to work, some logic is on the rising econet clock and some is on
the falling. Unfortunately the XC9500 CPLDs don't have dual edge FF so there is
one bit of code which has to gate the econet clock with some combinatorial,
which on proper high speed synchronous designs is a big no-no..
but it's a cheap hack that works OK here :mrgreen:

I decided that a microcontroller doing USB and HDLC stuff/unstuff and bit bang
could be tricky so offloaded the serial stuff. The good news is that the CPLD bit
could just be connected to the SPI port on a Pi if one didn't want to use it via USB.

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

Re: New hardware suggestion - Pi econet server

Post by myelin » Tue Oct 09, 2018 10:18 pm

flynnjs wrote:
Sat Oct 06, 2018 6:21 pm
Yes, the CPLD keeps track of where the stuffed bits need to be added/dropped and
then the micro isn't clocked during the extra data bit so it is lost. On the transmit
side the CPLD, being master, pauses the SPI clock while it sends an extra bit.
To get this all to work, some logic is on the rising econet clock and some is on
the falling. Unfortunately the XC9500 CPLDs don't have dual edge FF so there is
one bit of code which has to gate the econet clock with some combinatorial,
which on proper high speed synchronous designs is a big no-no..
but it's a cheap hack that works OK here :mrgreen:
I got around this by passing a 12MHz clock from the microcontroller to the CPLD, so it has a nice quick clock to use for synchronizing everything :) Of course then I ended up having to trigger something on the falling edge of that clock... can't win here!
flynnjs wrote:
Sat Oct 06, 2018 6:21 pm
I decided that a microcontroller doing USB and HDLC stuff/unstuff and bit bang
could be tricky so offloaded the serial stuff. The good news is that the CPLD bit
could just be connected to the SPI port on a Pi if one didn't want to use it via USB.
That might end up working really nicely... I think on the Pi you can just start an SPI transaction and give it a buffer, rather than having to keep feeding in bytes or clearing them out of the 1-byte buffer like on a microcontroller.

I got my board reading a broadcast packet from an A3000 today and passing it over the serial port to the microcontroller. That big endian CRC situation (mentioned by firthmj a while back) is definitely pretty odd! I was wondering where the F0B8 number (in the MC6854 datasheet) came from -- it's 1D0F (the standard CRC-CCITT residue when you preset with FFFF) reversed.
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: 477
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: New hardware suggestion - Pi econet server

Post by myelin » Sun Oct 21, 2018 7:16 am

flynnjs wrote:
Fri Oct 05, 2018 6:56 pm
Every time I ask for some help finishing a bit of code [...]
FYI something you might like, depending how your CRC implementation works: I figured out how to modify Lammert Bies' code to make a table based Econet CRC algorithm, that takes bytes in host order and returns the CRC residue (i.e. the complement of the host-order CRC word), so you don't need to do any byte reversal.
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: 3294
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: New hardware suggestion - Pi econet server

Post by jgharston » Sun Oct 21, 2018 1:23 pm

myelin wrote:
Fri Oct 05, 2018 7:22 pm
How are we supposed to handle scout frames? Econet's four-way handshake verifies that there's an active receiver there before sending the actual packet, and failure to respond to the scout frame is a different error to failing to ack the data frame. Is it safe to just auto-ack every scout frame and then abort the data frame if no ack comes back over UDP from the destination machine?
You don't hndle scout frames, you handle scout... um... transactions. See Econet over IP and [url=http://beebwiki.mdfs.net/Econet_packet]Econet packet[url].

An Econet transaction is:
Send: Scout frame with packet header
Receive: Scout acknowledge frame
Send: Data frame with packet data
Receive: Data acknowledge frame

An EconetOverIP transaction is:
Send: Data packet with data
Receive: ACK packet or NAK packet or timeout

I don't have the AUN manual to hand, but this results in only a subset of the Econet Status return code being returned.
All Immediate calls return EconetStatus_NotListening, except Immediate_MachinePeek which returns EconetStatus_Ok.
Broadcasts return EconetStatus_Ok
Data transmissions uses a delay/timeout/retry protocol documented in the PRM 5a. Off the top of my head:
Line Jammed: never returned
No clock: never returned
Net Error: if the physical Ethernet interface is misfunctioning
Not listening: Econet returns this if Scout gets no ScoutAck
No reply: Econet returns this if Data gets no DataAck
You need to check PRM5a to determine what state returns NotListening and what state returns NoReply.

Code: Select all

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

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

Re: New hardware suggestion - Pi econet server

Post by jgharston » Sun Oct 21, 2018 1:39 pm

Ok, a bit of Googling finds the AUN manual online. This is the transmission methodology for Data packets (ie, not Broadcast, not Immediate):

Code: Select all

If count > 1
	The maximum elapsed timeout period in seconds (T) requested by the application is computed as:
T = (Count × Delay) / 100
On receipt of reject messages, the sender will retransmit the data frame 10 times after 1 centisecond timeouts, then:
If T < 5
	T × 10 retransmissions will occur, each after 10 centisecond timeouts;
Else
	If the destination station is not on the same network as the sender
	exactly 50 retransmissions will occur, each after (T × 100) / 50 centisecond timeouts;
Else
	If the retry delay < 25 centiseconds
	exactly 50 retransmissions will occur;
Else
	(T × 4) retransmissions will occur, each after a 25 centisecond timeout.
(This provides some optimisation for simultaneous loading of software from a local file serer, whilst protecting against excessive overload at gateway stations caused by rapid retransmission).
If no response is received at all then:
	If T < 5
	1 retransmission will occur, after a 5 second timeout;
Else
	T / 5 retransmissions will occur, each after 5 second timeouts.
Else
	The sender will transmit exactly once. The transmission status will not change until a positive acknowledgement or a reject message has been received, or a 5 second timeout has elapsed.
As a receiver, if you receive a packet and you have a reception buffer open that is large enough to receive it, you acknowledge it with an ACK packet. Otherwise (no buffer open, buffer open but too small), you acknowledge it with a NAK packet.

Code: Select all

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

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

Re: New hardware suggestion - Pi econet server

Post by myelin » Wed Oct 24, 2018 12:18 am

jgharston wrote:
Sun Oct 21, 2018 1:23 pm
You don't hndle scout frames, you handle scout... um... transactions. See Econet over IP and [url=http://beebwiki.mdfs.net/Econet_packet]Econet packet[url].
I see... so if one were to build an Econet-to-AUN bridge, the trick would be to immediately acknowledge every scout frame coming in from the Econet side, then send an AUN data packet once enough data has been read, and acknowledge the Econet data frame or not depending on whether an ACK shows up on the Econet side.

i.e.:

When an Econet station wants to contact an Ethernet station:

* Receive from Econet: scout frame
* Send to Econet: scout ack frame
* Receive from Econet: data frame
* Send to Ethernet: AUN data frame
* Receive from Ethernet: AUN ack or nak (or nothing)
* Send to Econet: data ack frame, or nothing

When an Ethernet station wants to contact an Econet station:

* Receive from Ethernet: AUN data frame
* Send to Econet: scout frame
* Receive from Econet: scout ack frame, or nothing (in which case send a NAK on Ethernet, or ignore)
* Send to Econet: data frame
* Receive from Econet: data ack frame
* Send to Ethernet: AUN ack frame
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: 3294
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: New hardware suggestion - Pi econet server

Post by jgharston » Wed Oct 24, 2018 8:17 am

Something like that, yes. There's various documents about Econet over IP here. RiscIX.txt goes into fairly deep detail, and OverIPsrc is Philip Blundell's Econet/IP code.

Code: Select all

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

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

Re: New hardware suggestion - Pi econet server

Post by myelin » Wed Oct 24, 2018 5:04 pm

Progress update: it now reads frames from the Econet, verifies the CRC, and dumps them to the USB serial port. Time to start seeing if I can integrate Gareth's ArduinoFilestore.
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