chiark / gitweb /
detection on master board
authorian <ian>
Sun, 25 Dec 2005 23:14:03 +0000 (23:14 +0000)
committerian <ian>
Sun, 25 Dec 2005 23:14:03 +0000 (23:14 +0000)
detpic/detect.asm
detpic/detect.inc
detpic/mascan.asm
detpic/morse.messages
detpic/program.asm
detpic/variables.asm

index f26a45b2211bd09fce67a1084d0c073988d1ebad..6ebbd1aee35ee52c680f19b554ae9d3b4d95530a 100644 (file)
@@ -369,7 +369,7 @@ new_i2c_outmsg
                        ; C     xx xx xx xx  xx 00 xx xx
                        ; D     xx xx xx xx  xx xx 04 05
 ;----------            ; E     xx xx xx xx  xx 02 xx xx
-backgroundloop_reversers
+backgroundloop_reversers_core macro
        rr_fw   PORTA   ; W     xx xx 01 xx  03 xx xx xx (now)
        and_wff scana   ; a     xx xx 01 xx  03 xx xx xx (cumulative)
        mov_fw  PORTD   ; D     xx xx xx xx  xx xx 04 05 (now)
@@ -378,10 +378,13 @@ backgroundloop_reversers
        bc_f    buf0,2  ; buf0  MM zz zz ss  zz 00 zz zz (cumulative)
        bt_f_if0 PORTE,2 ;                      02       (now)
        bc_f    buf0,4  ; buf0  MM zz zz 02  zz ss zz zz (cumulative)
+       endm
+backgroundloop_reversers
+       backgroundloop_reversers_core
        backgroundloop_again backgroundloop_reversers
 
 ;----------            ; buf0  MM zz zz 02  zz 00 zz zz
-i2csu_read_begin_reversers
+read_begin_calc_buf0_reversers macro
        mov_fw  scana   ; W     xx xx 01 xx  03 xx xx xx
        and_lw  0x28    ; W     zz zz 01 zz  03 zz zz zz
        ior_wff buf0    ; buf0  MM zz 01 02  03 00 zz zz
@@ -389,13 +392,37 @@ i2csu_read_begin_reversers
        mov_fw  scand   ; W     xx xx xx xx  xx xx 04 05
        and_lw  0x03    ; W     zz zz zz zz  zz zz 04 05
        ior_wfw buf0    ; W     MM zz 01 02  03 00 04 05
+       endm
 
+i2csu_read_begin_reversers
+       read_begin_calc_buf0_reversers
        call    i2cs_read_data
 
        rcall   new_i2c_outmsg
 
        bra     i2csu_read_begin_either_tail
 
+;======================================================================
+; FOR MASTER
+
+;----------
+backgroundloop_master
+       backgroundloop_reversers_core
+       bra     backgroundloop_master
+
+;----------
+read_detection_head_master
+       read_begin_calc_buf0_reversers
+       bra_n   read_detection_head_master_badmore
+       set_f   scana
+       set_f   scand
+       mov_ff  buf0_startval, buf0
+       return
+
+;-----
+read_detection_head_master_badmore
+       panic   morse_DM
+
 ;======================================================================
  include final.inc
 
index 0b84d60d7f4608d8b8439d10cb0e97b19d29a108..a8822232912ecb6f9635c5796ef97ae8be2b8764 100644 (file)
@@ -1,5 +1,7 @@
  extern detect_local_init
  extern detect_slave_init
  extern slave_add_short_message
+ extern read_detection_head_master
+ extern backgroundloop_master
  extern backgroundloop_reversers
  extern backgroundloop_detectors
index 1a2f804fe44af633e069901b0d495cdf95b34a60..69c316f926aa11d228668d9a0e177674be5b92dd 100644 (file)
@@ -18,7 +18,8 @@ cbyte res     1
        ;       ???? ???1       reading halted due to lack of buffer space:
 cbyte_halted equ 0 ; also set briefly while we decide what to do next
 
-wslave res     1       ; slave we need to write to
+wslave                 res 1 ; slave we need to write to
+outmsg_targetlen       res 1 ; 
 
 ;======================================================================
 ; HANDLING OF I2C EVENTS
@@ -211,28 +212,26 @@ nextslave_nowrite
        cmp_fw_ifle outmsg_targetlen
        return ; target len < actual len, do not add anything
        ; ok, there's space, go ahead:
+       bc_f    cbyte, cbyte_halted
 
+       mov_lw  ste_size
+       add_wff cslot           ; cslot -> next ste_flags
        mov_lfsr slavetable, 1  ; FSR1H -> slavetable
-       mov_ff  cslot, FSR1L    ; FSR1 -> current ste_flags
-       mov_lw  ste_size        ; W = ste_size
-nextslave_loop
-       add_wff FSR1L           ; FSR1 -> next ste_flags
-       bt_f_if0 INDF1, stf_present
-       bra     nextslave_loop
-
-nextslave_reloop_resume
-       mov_ff  FSR1L, cslot    ; cslot -> new ste_flags
+       mov_fw  cslot, FSR1L    ; FSR1 -> new ste_flags
+
        bt_f_if1 POSTDEC1, stf_sentinel ; FSR1 -> ste_slave
-       bra     nextslave_reloop
-       ; no wrap around:
+       bra     nextslave_looparound
+       ; Ok, we have a slave:
 
        mov_fw  INDF1           ; W = new slave number
-       bc_f    cbyte, cbyte_halted
        goto    i2cm_read_start
 
-nextslave_reloop
-       mov_lfsr slavetable + ste_size + ste_flags
-       bra     nextslave_reloop_resume
+nextslave_looparound
+       ; now we do our own detection
+       mov_lw  (slavetable + ste_flags) & 0xff ; select our own slot
+       mov_wf  cslot
+       call    read_detection_head_master
+       goto    i2cmu_read_got_byte
 
 ;----------------------------------------
 i2cmu_done
@@ -280,13 +279,74 @@ i2c_consider_restartread
 ; INITIALISATION
 
 mascan_init
-       add_lw  -maxpic/2       ; at 9600, about 1ms per char;
-                               ; we reckon on about 2 pics per ms.  So if
-                               ; we have at least maxpic/2 then we won't
-                               ; run out before we have scanned them all
-                       coincidentally is about 1 pic   cmp_fw_ifle 
-                       mov_fw  outmsg_end
-                       sub_wfw 
+       mov_lw  slavetable & 0xff
+       mov_wf  cslot
+       clr_f   cbyte
+       clr_f   wslave
+
+       mov_lw  2
+       mov_lfsr slavetable, 0          ; FSR0 -> slavetable
+       load_tblptr pic2detinfo         ; TBLPTR* -> pic2detinfo
+       clr_f   t                       ; t = loop counter
+mascan_init_loop
+       tblrd_postinc_fixup             ; TABLAT = EOOOOSSS
+       mov_fw  TABLAT                  ; W = EOOOOSSS, N = E
+
+       tblrd_postinc_fixup             ; TABLAT = DSSSSSSS, N (still) = E
+       bra_nn  mascan_init_ifabsent
+
+       mov_ff  t, POSTINC0             ; ste_slave = slave
+       mov_wf  u                       ; u = 1OOOOSSS
+       and_lw  0x78
+       bra_nz  mascan_bad_detinfo0
+       ; ok                            ; u = 10000SSS
+
+       mov_fw  TABLAT                  ; W = DSSSSSSS
+       and_lw  0x80                    ; W = D0000000
+       mov_wf  POSTINC0                ; ste_flags = D0000000
+
+       mov_fw  TABLAT                  ; W = DSSSSSSS
+       bc_w    7                       ; W = 0SSSSSSS = first
+       add_lw  -0xf8                   ; W = first - 0xf8 = detbasel
+       mov_wf  POSTINC0                ; detbasel
+
+       clr_f   POSTINC0                ; lastd0
+       clr_f   POSTINC0                ; lastd1
+       clr_f   POSTINC0                ; lastd2
+       set_f   POSTINC0                ; unused
+
+       mov_fw  u                       ; W = 10000SSS
+       xor_lw  b'10011000' ^ 0x80      ; W = detmsgh
+       mov_wf  POSTINC0                ; detmsgh
+
+mascan_init_ifabsent
+       inc_f   t                       ; next slave
+       bt_f_if0 t, maxpics_ln2
+       bra     mascan_init_loop
+       ; we've read the whole flash table
+
+ if slavetable = 0x400
+       bt_f_if1 FSR0H, 0
+       bra     mascan_bad_toomany
+ endif
+
+       clr_f   POSTINC0                ; ste_slave
+       mov_lw  (1<<stf_detect)|(1<<stf_sentinel)
+       mov_wf  POSTINC0                ; ste_flags
+       ; rest of final entry, and rest of table, is undefined
+
+       ; at 9600, it's about 1ms per char.
+       ; we allow 1ms to scan 2 pics via i2c.
+       ; so our target len is (no of pics)/2
+       ; plus 2 bytes of slop
+       rl_fw   t
+       add_lw  2
+       mov_wf  outmsg_targetlen
+
+       return
+
+mascan_bad_detinfo0 panic morse_DF
+mascan_bad_toomany panic morse_DG
 
 ;======================================================================
 ; PROCESSING OF INCOMING BYTES - EXTRA (NON-DETECTION)
index 550f8bc7d03491be30eddbc1b26224ad2f9054c4..c4b4cd9cd9d439f9dd947c2158988e4de0ade590 100644 (file)
@@ -81,6 +81,9 @@ DQ    FSR2L,::outmsg_end              ; previous slave read incomplete
 DR     FSR2L,::outmsg_end              ; slave read overrun
 DX     ::t                             ; slave received wrong message byte
 DB     detect:message_buffer           ; slave_add_short_message overrun
+DF     ::t                             ; slave pic2detinfo[0] invalid bits
+DG     ::t                             ; too many slaves in pic2detinfo
+DM     ::buf0                          : master has MM bit set in buf0
 
 # Messages for specific peripherals:
 # R - Reversers (polarity)
index 4aeb81d55a6f70b9ec00abb65e8ee178174c6196..a60fe729040d76dc77de6899db39670acc960d6f 100644 (file)
@@ -36,6 +36,8 @@ vector_reset
        bs_f    INTCON, GIEH
        bs_f    INTCON, GIEL
 
+       bt_f_if1 idloc1,idloc1_master
+       goto    backgroundloop_master
        bt_f_if1 idloc1,idloc1_boarddet
        goto    backgroundloop_detectors
        goto    backgroundloop_reversers
index b1edb4f291fb46bb0300d96ad27f5d08809f3fd0..0a655aae1603ff38e1203d68e878544b4de5a0f3 100644 (file)
@@ -78,7 +78,6 @@ ste_detmsgh   equ 7 ; dk 1 001 1 000 being 1 001 Y SSS
 ; flags in ste_flags:
 stf_detect     equ 7 ; Gk  this is a detectors board
 stf_sentinel   equ 6 ; Gk  sentinel slot at end of table
-stf_detpresent equ 5 ; dk  this board has some detectors (or slot is sentinel)
 
  include final.inc