QL network protocol

Nagging hardware related question? Post here!
Post Reply
User avatar
gertk
Hardware Hero
Posts: 41
Joined: Mon Aug 19, 2013 10:00 pm

QL network protocol

Post by gertk »

Tinkering with another topic... The QL network connector.

So far I found out that the data rate it is not 100 kbit/sec but 90 kbit/sec and it uses quite UART friendly 8-N-1 serial protocol.
With some sniffer code on the mbed I have already deduced some of the information but since the bog-standard QL has only a few network commands there is not much information to be found. Toolkit2 enhances the network functions but there is no protocol overview of what is sent over the network and what the QL is expecting from, for example, a QL acting as a a server.

The network connector might be used as an enhancement in controlling the Microdrive emulator or even be used as a seperate device.

An example what is produced by issueing the command SAVE NETO_0 (broadcasting the current program in memory)

Code: Select all

10 PRINT "Hello world!"
Sniffed data:

Code: Select all

destination 0
source 1
serial 0
packet type 1
data length 24
data checksum 217
header checksum 243

0000: 00 31 30 20 50 52 49 4e 54 20 22 48 65 6c 6c 6f ?10 PRINT "Hello
0010: 20 77 6f 72 6c 64 21 22 0a                       world!"?       
There is still a null byte at the start of the data. The QL uses fixed levels to indicate starting/stopping and occupying the network but it confuses the uart a bit (or byte) :D

Question: is there any information to be found on this subject ? Is there a list of what TK2 is sending/receiving/expecting ?

Gert


User avatar
tofro
Font of All Knowledge
Posts: 3112
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: QL network protocol

Post by tofro »

Gert,

this is what the Toolkit 2 Manual says on the network protocol
QL Network Protocols
Standard QL Handshake

The Standard QL handshaking network protocol is compatible with the Sinclair Spectrum protocol. It comprises 11 phases

sender receiver
a) scout

1) gap waiting for 3ms for
activity, if activity
occurs: restart

2) wait waiting for activity
(a scout)

3) scout send a scout of wait for 530us
duration < 530us, if
contention occurs:
restart

b) header

4) hactiv set net active 22us wait for active

5) hbytes for each byte 11.2us for each byte wait for
start (inactive) bit, start (inactive) bit,
8*11.2us data bits, read 8 data bits, if
5*11.2us stop (active) fails: restart
bits

6) hackw wait for 2.5ms for set net active 22us
active, if not active:
restart

7) hackbt wait for start bit, send 11.2us start bit
read 8 data bits, 8 data bits 00000001
if error: restart

c) data

8) dactiv set net active 22us wait for active

9) dbytes for each byte 11.2us for each byte wait for
start (inactive) bit, start (inactive) bit,
8*11.2us data bits, read 8 data bits, if
5*11.2us stop (active) fails: restart
bits

10) dackw wait for 2.5ms for set net active 22us
active, if not active:
restart

11) dackbt wait for start bit, send 11.2us start bit
read 8 data bits, 8 data bits 00000001
if error: restart

The entire protocol is synchronised by a period of inactivity at least 2.8ms long.

The header is eight bytes long in the following format:

destination station number
sending station number
block number (high byte)
block number (low byte)
block type (0 normal, 1=last block of file)
number of bytes in block (0 to 255)
data checksum
header checksum

If the number of bytes in a block is 0, 256 data bytes are actually sent.

The checksums are formed by simple addition: if there are two single bit errors in the most significant bit (the most common type of error) within one block, then the errors will pass undetected. If the block number received in a header is not equal to the block number required, then the header and data block are acknowledged but ignored.

The protocol is not proof against a failure on the last block transmitted where the receiver has accepted the block, but the sender has missed the acknowledge. In this case the sender will keep re-transmitting the block until it times out (about 20s).

Toolkit II Broadcast

Toolkit II has a special version of this protocol for network broadcast. This has an extended scout to allow time for the receiver to interrogate the IPC without missing the scout, and it has an active acknowledge / not acknowledge. The protocol has been defined in such a way that future network drivers can be more flexible than the Toolkit II driver.

sender receiver
a) scout

1) gap waiting for 3ms for
activity, if activity
occurs: restart

2) wait waiting for activity
(a scout) every 20ms
check IPC for BREAK

3) scout send a scout of wait for 530us
duration < 530us, if
contention occurs:
restart

4) scext send a scout extension
of 5ms active
b) header

5) hbytes for each byte 11.2us for each byte wait for
start (inactive) bit, start (inactive) bit,
8*11.2us data bits, read 8 data bits, if
5*11.2us stop (active) fails: nack
bits

6) hwait leaving net active,
wait 1ms

c) data

7) dbytes for each byte 11.2us for each byte wait for
start (inactive) bit, start (inactive) bit,
8*11.2us data bits, read 8 data bits if
5*11.2us stop (active) fails: nack
bits

8) dack inactivate net and within 500us set net
wait 1ms for active: active and wait 5ms,
if fails, restart do any processing
required and when ready
for next packet,
inactivate and restart

d) Not acknowledge

9) nack wait for inactive wait for 2.8us of active
or inactive, if inactive:
restart

10) nackw wait 500us for active: wait 200us for active, if
timeout is ok, active active: restart, if inactive
is fail activate 500us (nack)

A broadcast acknowledge is 5ms active followed by more than 400us inactive. A broadcast not acknowledge is no response or 5ms active followed by 200us to 300us inactive, followed by more than 200us active.

Toolkit II Server Protocol

The Toolkit II server protocol is physically the same as the Standard QL protocol, but the header has been slightly changed to improve the checksum, to allow blocks of up to 1000 bytes to be sent and to distinguish server transactions. A server header cannot be confused with a standard header.
Another source of information might be the Minerva (unintended pun) sources - There's quite some comments in there that might help you understand the details.

Regards,
Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
RWAP
RWAP Master
Posts: 2893
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: QL network protocol

Post by RWAP »

The other thing to look at is Simon Goodwin's DIY Toolkit sources and manuals - especially his Flexynet driver.


User avatar
gertk
Hardware Hero
Posts: 41
Joined: Mon Aug 19, 2013 10:00 pm

Re: QL network protocol

Post by gertk »

Ok, lots of 'food for thought'
I will look into it...
Thanks


Post Reply