chiark / gitweb /
working on i2c driving
authorian <ian>
Thu, 22 Dec 2005 00:58:17 +0000 (00:58 +0000)
committerian <ian>
Thu, 22 Dec 2005 00:58:17 +0000 (00:58 +0000)
detpic/mascan.asm
detpic/morse.messages
detpic/program.asm

index f1d4f25a2f6290ea73665873f02af8fc5c34e2d8..65a16f1ee0663c4785b06fddf11ef805b43f919e 100644 (file)
@@ -5,8 +5,9 @@
 
  udata_acs
 
+b      res     1       ; byte just read
 cslot  res     1       ; current slave in slave table, points to flags byte
-main   res     1
+cbyte  res     1
        ; one of the following:
        ;       0000 0000       we're expecting the first byte
        ;       
@@ -16,19 +17,28 @@ main        res     1
        ;       MM zz B2 B1 zz zz zz II
        ;
        ;       main byte from slave
-; X0BB0000
-                       ; where X is 1 iff we're expecting an `extra byte'
+; M0BB0000
+                       ; where M is 1 iff we're expecting an `extra byte'
                        ; otherwise NN is the detection byte we're expecting
 
 sc             res     1
 sc_extra       equ     7 ; we're 
 
 slavetable_section udata 0x280
-slavetable res maxpics * 2
-       ; each entry is:
-       ;  1 byte slave number
-       ;  1 byte flags
-       ;       00DD0000        where D is 1 iff a detectors board
+
+ste_szln2      equ     3
+       ; each entry is a number of bytes, at these offsets:
+ste_slave      equ     0 ; slave number
+ste_flags      equ     1 ; flags (stf_...)    cslot normally points here
+ste_detbasel   equ     2
+ste_lastd0     equ     3
+ste_lastd1     equ     4
+ste_lastd2     equ     5
+ste_detmsgh    equ     7
+ste_size       equ     (1<<ste_szln2)
+slavetable res maxpics * ste_size
+
+stf_detect     equ     7
 
  code
 ;======================================================================
@@ -50,16 +60,226 @@ i2cmu_read_got_byte
 ;
 ; See detect.asm head comment for protocol info, in particular
 ; the meaning of these bytes.
-       mov_wf  t               ; remember the byte for a moment
-       mov_lw  slavetable >> 8
-       mov_wf  FSR1H
-       mov_ff  cslot, FSR1L
+                               ; W =           received byte
+       mov_wf  b               ; W = b =       received byte
+
+       mov_lfsr slavetable, 1
+       mov_ff  cslot, FSR1L    ; FSR1 ->       slave's flags
 
        tst_f_ifnz cbyte
        bra     read_got_notfirst
        ; this is a first (head) byte:
 
-       and_wfw POSTINC1, 
+       bt_f_if0 POSTINC1, stf_detect ; FSR1 -> detbasel
+       bra     read_got_first_reversers
+read_got_first_detectors
+       and_lw  0xb0            ; W =           M0BB0000
+       mov_wf  cbyte           ; cbyte =       M0BB0000
+       mov_fw  POSTINC1        ; W = detbasel; FSR1 -> lastd0
+       rcall   read_prep_detectbyte
+       goto    addmsgs_dethead
+
+;----------
+read_got_first_reversers
+       bt_f_if1 b, 6
+       bra     read_got_bad_first_reversers
+       and_lw  0x80            ; W =           M0000000
+       mov_wf  cbyte           ; cbyte =       M0000000
+       mov_fw  POSTINC1        ; W = detbasel; FSR1 -> lastd0
+       rcall   read_prep_detectbyte
+       goto    addmsgs_revhead
+
+;-----
+read_got_bad_first_reversers panic morse_MR
+
+;----------
+read_got_detectors_b1
+       bc_f    cbyte, 4        ; cbyte =       M0B00000
+       mov_fw  POSTINC1        ; W = detbasel; FSR1 -> lastd0
+       inc_f   FSR1L           ; FSR1 -> lastd1
+       add_lw  8               ; W = detbasel+8
+       rcall   read_prep_detectbyte
+       goto    addmsgs_all
+
+;----------
+read_got_detectors_b2
+       bc_f    cbyte,5         ; cbyte =       M0000000
+       mov_fw  POSTDEC1        ; W = detbasel; FSR1 -> flags
+       bs_f    FSR1L, 2        ; FSR1L ->      lastd2
+       add_lw  16              ; W = detbasel+16
+       rcall   read_prep_detectbyte
+       goto    addmsgs_all
+
+;----------
+read_got_detectbyte_something
+       xor_wfw INDF1           ; lastd<n> =    ?d??dddd
+       mov_lw  0x07
+       ior_wff FSR1L           ; FSR1L ->      detmsgh
+       return ; to addmsgs_<something>
+
+;----------
+read_prep_detectbyte
+;  W           adjusted detbase l
+;  cbyte       set for next byte to read
+;  b           received byte
+;  FSR1 ->     lastd<n>
+;  TOS ->      goto addmsgs_<something>
+;  NOS         return address for i2cmu_read_got_byte
+       mov_wf  t               ; t =           adj.detbasel
+       mov_fw  b               ; W =           ?d??dddd
+       xor_wfw INDF1           ; lastd<n> =    ?C??CCCC, Z iff same
+       bra_nz  read_got_detectbyte_something
+       xor_wfw INDF1           ; lastd<n> =    ?d??dddd
+       ; there's nothing to do
+       pop
+;...
+;----------------------------------------
+i2c_arrange_next_byte
+       tst_f_ifnz cbyte
+       goto    i2cm_read_another
+;...
+;----------------------------------------
+i2c_arrange_something
+; figure out what to do next - which pic to address, etc.
+       panic   morse_UG
+
+;----------------------------------------
+read_got_notfirst
+       bt_f_if1 cbyte, 4
+       bra     read_got_detectors_b1
+       bt_f_if1 cbyte, 5
+       bra     read_got_detectors_b2
+       ; it must be an extra byte
+
+       bt_f_if0 b, 7           ; any more ?
+       bc_f    cbyte, 7
+       bc_f    b, 7
+       call    process_got_extra
+       bra     i2c_arrange_next_byte
+
+;----------------------------------------
+process_got_extra
+       mov_fw  b
+loopback_read_byte
+;...
+;  W           message
+       xor_lw  0x00 ^ 0x20
+       bra_z   cdu_got_pointed
+       xor_lw  0x20 ^ 0xb0
+       bra_z   slave_got_aargh
+       panic   morse_MX
+
+;========================================
+
+addmsg_testbit macro bit
+       bt_f_if1 w, bit
+       rcall   addmsg
+       endm
+
+addmsg_return macro dummy_bit
+       return
+       mov_lw  dummy_bit ; makes disassembly a bit clearer than a nop
+       endm
+
+addmsg_ignore macro dummy_bit
+       nop
+       nop
+       endm
+
+addmsg_padding macro dummy_bit
+       nop
+       mov_lw  dummy_bit
+       endm
+
+addmsgs_section code 0x2100 + 6*4
+
+addmsgs_dethead        addmsg_testbit  6
+               addmsg_ignore   7
+               addmsg_testbit  0
+               addmsg_testbit  1
+               addmsg_testbit  2
+               addmsg_testbit  3
+               addmsg_return   4
+
+addmsgs_all    addmsg_testbit  5
+               addmsg_testbit  6
+               addmsg_testbit  7
+               addmsg_testbit  0
+               addmsg_testbit  1
+               addmsg_testbit  2
+               addmsg_testbit  3
+               addmsg_testbit  4
+               addmsg_return   5
+
+               addmsg_padding  6
+               addmsg_padding  7
+
+addmsgs_revhead        addmsg_testbit  0
+               addmsg_testbit  1
+               addmsg_testbit  2
+               addmsg_testbit  3
+               addmsg_testbit  4
+               addmsg_testbit  5
+               addmsg_return   6
+
+;----------
+addmsg
+;  TOS - 4 ->  bt_f_if1 w, <some bit>
+; other conditions set up by read_prep_detectbyte
+; and read_got_detectbyte_something
+;  t           adj.detbasel
+;  
+       rr_fw   TOSL            ; W =           0???bbb0
+       and_fw  0x0e            ; W =           0000bbb0
+       rr_w                    ; W =           00000bbb
+       set_f   FSR0L           ; FSR0L =       11111111
+       and_wff FSR0L           ; FSR0L =       11111bbb
+       clr_f   FSR0H           ; FSR0 -> bitnum2bit[b]
+       add_wff t               ; t =           detect msg low byte
+       mov_fw  INDF1           ; W =           1 001 0 SSS
+       mov_wf  u               ; u =           1 001 0 SSS
+       mov_fw  b               ; W =           ?d??dddd
+stuff here
+       and_wfw INDF0           ; W =           .....d..
+
+       xor_wfw
+
+       bt_w_if1 INDF1,
+
+
+
+
+read_got_detectbyte_allsame
+       mov_wf  INDF1           ; lastd<n> =    ?d??dddd
+
+       pop     ; skip return address
+read_done_byte
+
+
+
+       and_lw  0x80            ; W =           M0BB0000 / M0000000 ie M0BB0000
+
+       ; this is a first (head) byte from a detectors board:
+
+                               
+       and_lw  0xb0            ; W =           M0BB0000
+       
+read_got_
+       mov_fw  b
+       xor_wf  PREINC1, 
+
+       mov_wf  b
+
+       mov_
+       and_lw  
+
+       
+                               ; W = b =       MdBBdddd / 
+       and_wfw INDF1           ; flags, =      10110000 / 10000000
+       mov_wf  cbyte           ; cbyte =       M0BB0000 / M0000000
+
+       bt_f_
+       
        
 
        bt_f_if1 cbyte, 4
index 8a02152244a0e5d0f7faf59354a32544273696a1..cd704f39d896b8b56665b9a768e62d097c68ae94 100644 (file)
@@ -28,6 +28,10 @@ HO                           ; host RS232 read overrun
 HF                             ; host RS232 framing error
 HN                             ; host sent too much NMRA - buffers full
 
+# Regarding communications by master with slaves
+MX                             ; slave (or intern) sent bad extra byte
+MR     mascan::b,mascan::cslot ; reversers set byte with zz bit set
+
 # Problematic interrupts
 IH     INTCON,INTCON3,PIR1,PIR2,PIR3 ; Interrupt source not found (high pri.)
 IL     INTCON,INTCON3,PIR1,PIR2,PIR3 ; Interrupt source not found (low pri.)
@@ -48,6 +52,7 @@ UM
 UE
 UC
 UI
+UG
 UX
 
 # Messages for i2clib, S*
index 5eb052276c669f9ec7ebe7b3db6174307ed288e6..a5ef99d82bb39888d2942a6bf3fe8c3b5c47f193 100644 (file)
@@ -223,15 +223,9 @@ message_for_master
 ; handles it as an incoming message from the notional `slave 0'.
 ;  W           message         unchanged
 ;  GIEH                set             set
-       bt_f_if1 idloc1,idloc1_master
-       goto    loopback_read_byte
+       bt_f_if0 idloc1,idloc1_master
        goto    slave_add_short_message
+       goto    loopback_read_byte
 
 ;======================================================================
-; UNIMPLEMENTED STUFF
-
-;----------
-loopback_read_byte
-       panic   morse_UL
-
  include final.inc