To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.pbforthOpen lugnet.robotics.rcx.pbforth in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / pbFORTH / 362
361  |  363
Subject: 
Taking the plunge
Newsgroups: 
lugnet.robotics.rcx.pbforth
Date: 
Mon, 22 May 2000 15:32:32 GMT
Reply-To: 
sjm@IHATESPAMjudgement.com
Viewed: 
1616 times
  
OK I'm about to nervously take the plunge. My code assembles and
I'm about to push it off the cliff and see if it flies.

If any one feels bored please feel free to review the following
and make comments. Finding bugs by inspection is always easier.

I'm a little shakey on the bclr instruction, mostly how gas
interprets it. In particular how does the following work when
the actual register lives at 0xffdc?

    BCLR    #6,@0xDC:8          ;clear the RDRF flag

This is from RX@ so it must work but I can't figure it out. Oops
I just found it in TFM. 8 bit absolute assumes a high address byte
of 0xff.

(Sheesh gcc optimizes poorly on this platform.)

---------------------- serial.asm -------------------------------

; define the serial registers.
; The interrupt vectors are defined elsewhere
.equ S_MR,         0xffd8
.equ S_BRR,        0xffd9
.equ S_CR,         0xffda
.equ S_TDR,        0xffdb
.equ S_SR,         0xffdc
.equ S_RDR,        0xffdd

.balign 2

serialBuffer: .space 16
.balign 2

serialIn:  .word  serialBuffer
serialOut: .word  serialBuffer+1

rx_handler:
; interrupt land is not part of Forth land so using the Forth
; register mnemonics makes no sense. The only rule for sharing
; registers is that we need to restore them when we are done.
push r1
push r2
push r3

; Read the input data from the UART
mov.b @S_RDR,r1l

; Clear the receive interrupt bit. Aren't we primitive!!
bclr    #6,@S_SR:8

; Check whether there is room in the buffer
mov.w @serialIn,r3
mov.w @serialOut,r2
cmp.w r2,r3
beq serialCleanup   ; no room. bail.

; There's room. Store the data and increment the pointer
mov.b r1l,@r3
adds    #1,r3

; Check for ring buffer wrap
mov.w #serialBuffer+16,r2
cmp.w r2,r3
bne noWrap          ; pointer is still in buffer
mov.w #serialBuffer,r3
noWrap:
; in eithor case update the pointer in memory:
mov.w r3,@serialIn

serialCleanup:
pop r3
pop r2
pop r1

        rts

; This is our initialization word. Before we invoke this
; the original code is in control

M_CODE(24,``"SETUP_RECEIVE_INTERRUPTS"'',serialSetup,_FLINK)
; we return the data structure address
        mov.w   rTOS,@-rDSP
        mov.w   #serialBuffer, rTOS

; install the handler
        mov.w   #rx_handler,rA
        mov.w   rA,@RXI_VECTOR

; clear any stale interrupts
bclr    #6,@S_SR:8

; Enable receive interrupts
mov.b @S_CR,rAh
and #0x50,rAh
mov.b rAh,@S_CR

        M_NEXT()



1 Message 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