To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 335
334  |  336
Subject: 
The IR FIX -- was: Re: Is IR considered broken?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Mon, 26 Jul 1999 08:18:57 GMT
Viewed: 
1301 times
  
In lugnet.robotics.rcx.legos, Mark Falco writes:
The precompiled tm-and-ir, kinda works for me.  It is pretty good at
receiving data, but the transmitted message often has garbage.  When I

I had the same problem.

3. If it is broken is anyone actively working on fixing it?  If not I'll
take a stab at it.
4. If others have working code that uses IR, can you post it?

Here's the fix: enclode the old handler code in #ifdef TRASH,
use the new #else part. I'll say a few things about the motivation below.

(If you prefer to patch, download
http://www.informatik.hu-berlin.de/~mueller/rt/mindstorm/direct-ir.patch
it's based on LegOS 0.1.7 but should work w/ the latest snapshort as well.)

#ifdef TRASH
__asm__("
_dir_tx_handler:
                ; r6 saved by ROM

                mov.w   r0,@-r7

                mov.w @_dir_tx_read,r0          ; dir_tx_read -> r0
                mov.w @_dir_tx_end,r6

                cmp.w r0,r6                     ; transmission finished?
                beq  0f

                  mov.b @r0+,r6l                ; *(ptr++) -> r6
                  mov.b r6l,@0xdb:8             ; r6 -> transmit data register

                  bclr  #0x7,@0xdc:8            ; clear transmit buffer empty
flag

                  bra 1f

;; Frank: here seems to be a mistake in the assember: it jumps past the
;; move instruction at label 1. Hence, dir_tx_read is never incremented
;; fix: use the c handler below

                0:bclr  #0x7,@0xda:8            ; disable transmission irq

              1:mov.w r0,@_dir_tx_read          ; store new pointer

                mov.w @r7+,r0
                rts
        ");
#else
void dir_tx_c(void) {
  if (dir_tx_read<dir_tx_end) {
    S_TDR = *(unsigned char *) dir_tx_read++;
    S_SR &= ~SSR_TRANS_EMPTY;
  }
  else
    S_CR &= ~SCR_TX_IRQ;
}

__asm__("
_dir_tx_handler:
                ; r6 saved by ROM

                mov.w   r0,@-r7                 ; save all registers
                mov.w   r1,@-r7
                mov.w   r2,@-r7
                mov.w   r3,@-r7
                mov.w   r4,@-r7
                mov.w   r5,@-r7

                jsr     _dir_tx_c               ; call scheduler

                mov.w   @r7+,r5                 ; restore all registers
                mov.w   @r7+,r4
                mov.w   @r7+,r3
                mov.w   @r7+,r2
                mov.w   @r7+,r1
                mov.w   @r7+,r0

                ; r6 will be restored by ROM

                rts                             ; return
        ");
#endif

OK, and here a few words:

1) the original assembler code is correct but the translation by the
   H8 assembler is not. See the comment in the assembler code:
   The branch is not executed correctly. I suspect a bug in the
   calculation of relative branch offsets in the assembler
   but that's just a wild guess.

2) the fix simly wraps code the save registers around a C-handler
   with the same functionality. This works fine (no relative branches).

3) Notice 8N1 is the setting, and NOT 8O1 as seen in firmdl. Firmdl
   actually uses odd parity. LegOS uses NO parity. If you use tm-and-ir
   as a test, make sure you set 8N1 2400 baud, only then will you see
   your "Hello".



Message is in Reply To:
  is IR considered broken?
 
The precompiled tm-and-ir, kinda works for me. It is pretty good at receiving data, but the transmitted message often has garbage. When I compile it myself using the latest legOS snapshot, it always transmits garbage, others seem to have seen the (...) (25 years ago, 12-Jul-99, to lugnet.robotics.rcx.legos)

6 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR