Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #1536 > unrolled thread

Uthernet receive error: bytes swapped

Started byD Finnigan <dog_cow@macgui.com>
First post2015-02-28 20:23 +0000
Last post2015-03-07 17:31 +0000
Articles 15 — 6 participants

Back to article view | Back to comp.sys.apple2.programmer


Contents

  Uthernet receive error: bytes swapped D Finnigan <dog_cow@macgui.com> - 2015-02-28 20:23 +0000
    Re: Uthernet receive error: bytes swapped David Schmenk <dschmenk@gmail.com> - 2015-02-28 12:58 -0800
    Re: Uthernet receive error: bytes swapped a2retrosystems@gmail.com - 2015-02-28 16:20 -0800
      Re: Uthernet receive error: bytes swapped D Finnigan <dog_cow@macgui.com> - 2015-03-01 00:34 +0000
        Re: Uthernet receive error: bytes swapped a2retrosystems@gmail.com - 2015-02-28 17:17 -0800
        Re: Uthernet receive error: bytes swapped David Schmidt <schmidtd@my-deja.com> - 2015-02-28 21:58 -0500
    Re: Uthernet receive error: bytes swapped ol.sc@web.de (Oliver Schmidt) - 2015-03-01 14:33 +0000
      Re: Uthernet receive error: bytes swapped David Schmenk <dschmenk@gmail.com> - 2015-03-01 12:15 -0800
    Resolved!, was Re: Uthernet receive error: bytes swapped D Finnigan <dog_cow@macgui.com> - 2015-03-02 20:47 +0000
      Re: Resolved!, was Re: Uthernet receive error: bytes swapped gids.rs@sasktel.net - 2015-03-02 16:14 -0800
        Re: Resolved!, was Re: Uthernet receive error: bytes swapped D Finnigan <dog_cow@macgui.com> - 2015-03-06 00:30 +0000
          Re: Resolved!, was Re: Uthernet receive error: bytes swapped David Schmidt <schmidtd@my-deja.com> - 2015-03-05 20:53 -0500
            Re: Resolved!, was Re: Uthernet receive error: bytes swapped D Finnigan <dog_cow@macgui.com> - 2015-03-07 17:37 +0000
          Re: Resolved!, was Re: Uthernet receive error: bytes swapped David Schmenk <dschmenk@gmail.com> - 2015-03-06 07:21 -0800
            Re: Resolved!, was Re: Uthernet receive error: bytes swapped D Finnigan <dog_cow@macgui.com> - 2015-03-07 17:31 +0000

#1536 — Uthernet receive error: bytes swapped

FromD Finnigan <dog_cow@macgui.com>
Date2015-02-28 20:23 +0000
SubjectUthernet receive error: bytes swapped
Message-ID<dog_cow-1425155060@macgui.com>
Fellow Uthernet programmers, have you ever had this problem:

From time to time, the first 10-20 bytes of a received Ethernet frame are in
order, but then a single byte is doubled, and all byte pairs following this
duplicate are swapped?

It's an intermittent error for me, and I can't put my finger on whether it's
a hardware fault or a software fault.

-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [next] | [standalone]


#1537

FromDavid Schmenk <dschmenk@gmail.com>
Date2015-02-28 12:58 -0800
Message-ID<cb25ef0d-d6c4-437e-9a2f-8308d52463b2@googlegroups.com>
In reply to#1536
On Saturday, 28 February 2015 12:24:23 UTC-8, D Finnigan  wrote:
> Fellow Uthernet programmers, have you ever had this problem:
> 
> From time to time, the first 10-20 bytes of a received Ethernet frame are in
> order, but then a single byte is doubled, and all byte pairs following this
> duplicate are swapped?
> 
> It's an intermittent error for me, and I can't put my finger on whether it's
> a hardware fault or a software fault.
> 
> -- 
> ]DF$
> Apple II Book: http://macgui.com/newa2guide/
> Usenet: http://macgui.com/usenet/  <-- get posts by email!
> Apple II Web & Blog hosting: http://a2hq.com/

I had to dance around a little when reading the packet length. The CS9800 is pretty finicky when being accessed in 8 bit mode. Here is what I ended up with, and seems pretty stable:

//
// Return the length of awaiting packet, 0 otherwise
//
def peekfrmlen
    word len
    len = 0
    if peekiow(isq) & $3F == $04
        if peekio(rxdata_hi) & $01
            peekio(rxdata_lo)
	    len.1 = peekio(rxdata_hi)
	    len.0 = peekio(rxdata_lo)
	else
	    peekio(rxdata_lo)
	    pokepreg($0102, $0140) // Skip pkt
	fin
    fin
    return len
end

The rest:

https://github.com/dschmenk/PLASMA/blob/master/src/libsrc/uthernet.pla

[toc] | [prev] | [next] | [standalone]


#1538

Froma2retrosystems@gmail.com
Date2015-02-28 16:20 -0800
Message-ID<54409bfb-8a90-48be-9276-76339e6ba005@googlegroups.com>
In reply to#1536
On Saturday, February 28, 2015 at 3:24:23 PM UTC-5, D Finnigan wrote:
> Fellow Uthernet programmers, have you ever had this problem:
> 
> From time to time, the first 10-20 bytes of a received Ethernet frame are in
> order, but then a single byte is doubled, and all byte pairs following this
> duplicate are swapped?
> 
> It's an intermittent error for me, and I can't put my finger on whether it's
> a hardware fault or a software fault.
> 
> -- 
> ]DF$
> Apple II Book: http://macgui.com/newa2guide/
> Usenet: http://macgui.com/usenet/  <-- get posts by email!
> Apple II Web & Blog hosting: http://a2hq.com/

Hi David, do you see the same behavior in the Applewin emulator? Also is it random or repeatable in any fashion?

[toc] | [prev] | [next] | [standalone]


#1539

FromD Finnigan <dog_cow@macgui.com>
Date2015-03-01 00:34 +0000
Message-ID<dog_cow-1425170116@macgui.com>
In reply to#1538
a2retrosystems wrote:
> 
> Hi David, do you see the same behavior in the Applewin emulator?

No, because I don't use that emulator.

> Also is it
> random or repeatable in any fashion?

I've been having a problem receiving packets for the past week or two, but
it's only this morning that I looked closer at the problem. I think there's
two problems: one I think is with my checksum routine, so we'll forget about
it for now because I can probably solve that myself. The second is the
subject of this thread.

Anyway, I need to gather more data, but it's definitely happened more than
once. I don't know how to repeat it, so for now I'll classify it as random.

The location where the double byte occurs isn't always the same, but so far
it's never been in the Ethernet MAC header, it's always been around the
beginning few bytes of the IP header, right around the flags/fragment bytes.

It's almost like someone is "missing a beat" because you know you have to
read the high byte from the one location, then the low byte from the other
location and so on. It looks like somehow this pattern is getting messed up,
so the bytes start coming out in the wrong order.


-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [prev] | [next] | [standalone]


#1541

Froma2retrosystems@gmail.com
Date2015-02-28 17:17 -0800
Message-ID<013a784b-9d0b-44e8-99cf-1ceb87c9212d@googlegroups.com>
In reply to#1539
On Saturday, February 28, 2015 at 7:35:19 PM UTC-5, D Finnigan wrote:
> a2retrosystems wrote:
> > 
> > Hi David, do you see the same behavior in the Applewin emulator?
> 
> No, because I don't use that emulator.
> 
> > Also is it
> > random or repeatable in any fashion?
> 
> I've been having a problem receiving packets for the past week or two, but
> it's only this morning that I looked closer at the problem. I think there's
> two problems: one I think is with my checksum routine, so we'll forget about
> it for now because I can probably solve that myself. The second is the
> subject of this thread.
> 
> Anyway, I need to gather more data, but it's definitely happened more than
> once. I don't know how to repeat it, so for now I'll classify it as random.
> 
> The location where the double byte occurs isn't always the same, but so far
> it's never been in the Ethernet MAC header, it's always been around the
> beginning few bytes of the IP header, right around the flags/fragment bytes.
> 
> It's almost like someone is "missing a beat" because you know you have to
> read the high byte from the one location, then the low byte from the other
> location and so on. It looks like somehow this pattern is getting messed up,
> so the bytes start coming out in the wrong order.
> 
> 
> -- 
> ]DF$
> Apple II Book: http://macgui.com/newa2guide/
> Usenet: http://macgui.com/usenet/  <-- get posts by email!
> Apple II Web & Blog hosting: http://a2hq.com/

Was going to suggest trying in applewin to see if you can see the same issue with the softeware you are using. Also suggest running wireshark to see what is on the wire vs what your program is seeing.

[toc] | [prev] | [next] | [standalone]


#1542

FromDavid Schmidt <schmidtd@my-deja.com>
Date2015-02-28 21:58 -0500
Message-ID<mctv85$kob$1@dont-email.me>
In reply to#1539
On 2/28/2015 7:34 PM, D Finnigan wrote:
> I've been having a problem receiving packets for the past week or two, but
> it's only this morning that I looked closer at the problem. I think there's
> two problems: one I think is with my checksum routine, so we'll forget about
> it for now because I can probably solve that myself.

I found a bug in the checksum routine that came from ip65 - it got fixed 
it before the stack turned over to to Jonno Downes in 2009, though. 
There's that to use as well as the one I hijacked from Contiki if you 
run into trouble.

[toc] | [prev] | [next] | [standalone]


#1543

Fromol.sc@web.de (Oliver Schmidt)
Date2015-03-01 14:33 +0000
Message-ID<mcv7vp$9p6$1@news.albasani.net>
In reply to#1536
Hi,

>From time to time, the first 10-20 bytes of a received Ethernet frame are in
>order, but then a single byte is doubled, and all byte pairs following this
>duplicate are swapped?
>
>It's an intermittent error for me, and I can't put my finger on whether it's
>a hardware fault or a software fault.

I never noticed to have experienced that. I'd double-check to make
sure that I'd adhere to the (partly non-intuitive) read orders pointed
out in http://www.cirrus.com/en/pubs/appNote/an181.pdf

Regards,
Oliver

[toc] | [prev] | [next] | [standalone]


#1545

FromDavid Schmenk <dschmenk@gmail.com>
Date2015-03-01 12:15 -0800
Message-ID<cf6895af-fa80-4e20-ad85-091680ea8b5b@googlegroups.com>
In reply to#1543
On Sunday, 1 March 2015 06:33:30 UTC-8, Oliver Schmidt  wrote:
> Hi,
> 
> >From time to time, the first 10-20 bytes of a received Ethernet frame are in
> >order, but then a single byte is doubled, and all byte pairs following this
> >duplicate are swapped?
> >
> >It's an intermittent error for me, and I can't put my finger on whether it's
> >a hardware fault or a software fault.
> 
> I never noticed to have experienced that. I'd double-check to make
> sure that I'd adhere to the (partly non-intuitive) read orders pointed
> out in http://www.cirrus.com/en/pubs/appNote/an181.pdf

So wish I'd seen this app note when I started. Luckily I was able to see what the Contiki driver did, and replicate it to get my driver functional. This was kind of the behavior I was seeing before sorting out the packet receive.

> 
> Regards,
> Oliver

[toc] | [prev] | [next] | [standalone]


#1546 — Resolved!, was Re: Uthernet receive error: bytes swapped

FromD Finnigan <dog_cow@macgui.com>
Date2015-03-02 20:47 +0000
SubjectResolved!, was Re: Uthernet receive error: bytes swapped
Message-ID<dog_cow-1425329291@macgui.com>
In reply to#1536
First off, thanks to everyone for giving me a chance to talk about this
problem. I'm pretty sure it led me to the solution faster than if I hadn't
discussed it.

Wireshark has been a good friend of mine, and here's a screenshot detailing
what was happening:
http://macgui.com/gallery/showphoto.php?pic_id=3495

Click the image to get the full-size version. That's pretty well documented
in the picture, so I won't talk about it any more.

Both problems were caused by programmer error. As far as I can tell, there
was nothing wrong with the hardware.

The checksum error was caused by a loop that was running twice as long as it
should have. I am using an optimized checksum routine set for 20 byte IP
headers. I unrolled the loop using Merlin's LUP command. But instead of
doing LUP 10, because I'm accessing two bytes per iteration, I did LUP 20.
You can see where my thinking was mixed up there.

What's incredible is how the checksum routine still managed to give correct
results in so many cases. That's definitely one of those tricky bugs.


Ok, now on to the real issue of this thread: the doubled byte, followed by
the swapped bytes. My explanation of "missing a beat" is exactly what
happened. There was a condition in my receive loop where it was possible
that the same RXTX data register would be accessed twice in a row. This
caused the double byte, then on each successive iteration, the accesses to
the CS8900A were out of order, thus producing the swapped bytes. The cause
in my code was due to not properly updating the zero-page base address used
with indirect indexed Y addressing.

Again, this was an interesting bug because in most cases, the code worked
correctly, making it tricky to distinguish a hardware error from a software
error.

These bugs were getting me pretty upset, so I'm really glad to get them both
nailed. I'll be posting more details on my project later this month.
Obviously, it's a TCP/IP stack... ;-)

-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [prev] | [next] | [standalone]


#1547 — Re: Resolved!, was Re: Uthernet receive error: bytes swapped

Fromgids.rs@sasktel.net
Date2015-03-02 16:14 -0800
SubjectRe: Resolved!, was Re: Uthernet receive error: bytes swapped
Message-ID<27094031-e746-4e9d-a0a4-e81ef6f82c44@googlegroups.com>
In reply to#1546
> What's incredible is how the checksum routine still managed to give correct
> results in so many cases. That's definitely one of those tricky bugs.
> 


Maybe not so incredible.  Wouldn't 10 bytes of code followed by 10 bytes of 0's give the same checksum?

[toc] | [prev] | [next] | [standalone]


#1548 — Re: Resolved!, was Re: Uthernet receive error: bytes swapped

FromD Finnigan <dog_cow@macgui.com>
Date2015-03-06 00:30 +0000
SubjectRe: Resolved!, was Re: Uthernet receive error: bytes swapped
Message-ID<dog_cow-1425601864@macgui.com>
In reply to#1547
gids.rs wrote:
>> What's incredible is how the checksum routine still managed to give
>> correct
>> results in so many cases. That's definitely one of those tricky bugs.
>> 
> 
> 
> Maybe not so incredible.  Wouldn't 10 bytes of code followed by 10 bytes
> of
> 0's give the same checksum?

I don't know. This IP checksum routine was supposed to only cover the 20
byte IP header. If it was running twice as long, it was either checksumming
a bit of the data payload, or something else. I'm not really interested in
looking into exactly what it was doing, just surprised that it was giving
correct results in its broken state.

-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [prev] | [next] | [standalone]


#1549 — Re: Resolved!, was Re: Uthernet receive error: bytes swapped

FromDavid Schmidt <schmidtd@my-deja.com>
Date2015-03-05 20:53 -0500
SubjectRe: Resolved!, was Re: Uthernet receive error: bytes swapped
Message-ID<mdb1a6$bgi$1@dont-email.me>
In reply to#1548
On 3/5/2015 7:30 PM, D Finnigan wrote:
> I'm not really interested in
> looking into exactly what it was doing, just surprised that it was giving
> correct results in its broken state.

You know what they say... even a broken [analog] clock is right twice a day.

[toc] | [prev] | [next] | [standalone]


#1554 — Re: Resolved!, was Re: Uthernet receive error: bytes swapped

FromD Finnigan <dog_cow@macgui.com>
Date2015-03-07 17:37 +0000
SubjectRe: Resolved!, was Re: Uthernet receive error: bytes swapped
Message-ID<dog_cow-1425749863@macgui.com>
In reply to#1549
David Schmidt wrote:
> On 3/5/2015 7:30 PM, D Finnigan wrote:
>> I'm not really interested in
>> looking into exactly what it was doing, just surprised that it was giving
>> correct results in its broken state.
> 
> You know what they say... even a broken [analog] clock is right twice a
> day.

A great saying that is applicable in so many scenarios! :-)

I've had some time to think about what was going wrong. I haven't actually
looked at the source yet to confirm, but I know I was using indexed Y
addressing by starting Y at decimal 19, then working down to 0. Now with the
loop going on twice as long, Y was rolling over beyond 0 and was ending up
at $EC or $ED. That would put it at the end of the first page of the receive
buffer. Depending on the length of the packets received so far, that either
would have been a lot of zeros, or it would have been the tail of previous
packets.

It's a newbie mistake, but since it was giving correct results more often
than not, it was tricky.

-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [prev] | [next] | [standalone]


#1552 — Re: Resolved!, was Re: Uthernet receive error: bytes swapped

FromDavid Schmenk <dschmenk@gmail.com>
Date2015-03-06 07:21 -0800
SubjectRe: Resolved!, was Re: Uthernet receive error: bytes swapped
Message-ID<0e712315-fbcb-49de-a5db-ee0bc945efd7@googlegroups.com>
In reply to#1548
On Thursday, 5 March 2015 16:31:09 UTC-8, D Finnigan  wrote:
> gids.rs wrote:
> >> What's incredible is how the checksum routine still managed to give
> >> correct
> >> results in so many cases. That's definitely one of those tricky bugs.
> >> 
> > 
> > 
> > Maybe not so incredible.  Wouldn't 10 bytes of code followed by 10 bytes
> > of
> > 0's give the same checksum?
> 
> I don't know. This IP checksum routine was supposed to only cover the 20
> byte IP header. If it was running twice as long, it was either checksumming
> a bit of the data payload, or something else. I'm not really interested in
> looking into exactly what it was doing, just surprised that it was giving
> correct results in its broken state.
> 
> -- 
> ]DF$
> Apple II Book: http://macgui.com/newa2guide/
> Usenet: http://macgui.com/usenet/  <-- get posts by email!
> Apple II Web & Blog hosting: http://a2hq.com/

Are you sure it was giving correct results? Most TCP/IP headers can get away with a checksum of 0 (no checksum) so you don't need to spend time calculating them. If you are on a local network and not putting your Apple II on the internetz, this is probably a safe thing to do.

[toc] | [prev] | [next] | [standalone]


#1553 — Re: Resolved!, was Re: Uthernet receive error: bytes swapped

FromD Finnigan <dog_cow@macgui.com>
Date2015-03-07 17:31 +0000
SubjectRe: Resolved!, was Re: Uthernet receive error: bytes swapped
Message-ID<dog_cow-1425749545@macgui.com>
In reply to#1552
David Schmenk wrote:
> On Thursday, 5 March 2015 16:31:09 UTC-8, D Finnigan  wrote:
>> gids.rs wrote:
>> >> What's incredible is how the checksum routine still managed to give
>> >> correct
>> >> results in so many cases. That's definitely one of those tricky bugs.
>> >> 
>> > 
>> > 
>> > Maybe not so incredible.  Wouldn't 10 bytes of code followed by 10
>> > bytes
>> > of
>> > 0's give the same checksum?
>> 
>> I don't know. This IP checksum routine was supposed to only cover the 20
>> byte IP header. If it was running twice as long, it was either
>> checksumming
>> a bit of the data payload, or something else. I'm not really interested
>> in
>> looking into exactly what it was doing, just surprised that it was giving
>> correct results in its broken state.
>> 
> 
> Are you sure it was giving correct results?

Yes, I had my application print a + sign if the checksum came out to be 0,
and an @ if not.

I also have a test suite. Granted, it involves me manually entering the test
cases and verifying the result, but I trust it.

This problem came when I unrolled the loop. See, I had this checksum routine
verified correct by my test suite, but then I decided to unroll the loop,
and that's when I started getting these occasional errors.


> Most TCP/IP headers can get
> away with a checksum of 0 (no checksum) so you don't need to spend time
> calculating them. If you are on a local network and not putting your Apple
> II on the internetz, this is probably a safe thing to do.

I appreciate the advice, but I don't want to take any shortcuts in this
area.

I just completed and debugged the UDP checksum routine last week. Both
outgoing and incoming UDP datagrams have their checksum verified or computed
as necessary.

-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.sys.apple2.programmer


csiph-web