;----------------------------------------
; MASTER - Access bank variables and other sections
-; values for ste_revcmd:
+polarities_commanded_buffer_section udata 0x5f
+polarities_commanded_buffer res maxpics+1
+ ; Each byte is:
; 11RRRRRR reverse command for slave, waiting to write
; 00000001 this is not a reversers pic
; 00000000 we have written any relevant command
+ ; 01000000 sentinel
;======================================================================
; LOCAL REVERSERS
; and so on until f for bit 5. (See polarity_do_here, below.)
;
; we accumulate (`gather') the `g' bits in t.
- mov_lfsr slavetable + ste_revcmd, 1
+ mov_lfsr polarities_commanded_buffer, 1
mov_fw POSTINC0 ; W = 10010RRR
mov_wf t ; t = 10010ggg
xor_lw b'10001000' ; t = 00011ggg
; FSR1 -> pic we've just filled
;...
board_next_loop
- mov_lw ste_size
- add_wff FSR1L ; FSR1 -> pic after one we're testing
- if ste_szln2 + maxpics_ln2 == 8
- bra_c board_next_none
- else
- error "reliance on carry flag for incrementing FSR1 fails"
- endif
- dec_fw INDF1 ; W = 1??????? existing reverse command
+ dec_fw PREINC1 ; FSR1 -> pic after one we're testing
+ ; W = 1??????? existing reverse command
; 00000000 not a reversers pic
- ; ffffffff no existing command
+ ; 11111111 no existing command
+ ; 00111111 sentinel
bra_z board_next_loop ; not a reversers pic
-
- bt_f_if0 INDF1, 7 ; 1....... existing command
- ; 0....... no existing command
- inc_f polarities_waiting
+ bra_nn board_next_none ; sentinel
return
;----------
pop ; that disposes of the call to `board'
call power_polarising
- mov_lfsr slavetable + ste_revcmd, 1
- mov_fw INDF1 ; there's always a board 0, us:
- goto polarity_local_do
+
+ mov_fw polarities_commanded_buffer ; there's always a board 0, us
+ call polarity_local_do
+ rcall needwrite_polarity ; does `return' because it will find one
+ return ; ... or maybe not if only 1 rev board
;----------
board_next_none_more_message
panic morse_RL
+;----------------------------------------------------------------------
+needwrite_polarity
+; <something>_needwrite will see if we need to talk to a slave
+; if not it will simply return
+; if we _do_, it will store the slave no. in needwrite_slave
+; and then pop and return
+; nb register usage may need to be adjusted for wiring into mascan i2cm_...
+ mov_lfsr polarities_commanded_buffer, 0
+polarity_needwrite_loop
+ rlc_fw PREINC1 ; W = 1RRRRRR? C=1 reverse command
+ ; W = 0000001? C=0 not a reversers pic
+ ; W = 0000000? C=0 no existing command
+ ; W = 1000000? C=0 sentinel
+ bra_nn polarity_needwrite_loop
+ bt_f_if0 STATUS, C
+ return ; we found the sentinel
+ ; we found a pic to tell to polarise:
+
+ mov_fw FSR1L
+ add_lw -polarities_commanded_buffer
+ mov_wf needwrite_slave
+ pop
+ return
+
+;----------------------------------------------------------------------
+polarity_master_init
+ panic morse_RIM
+ ; need to set up polarities_commanded_buffer
+
;======================================================================
include final.inc
xdebug res 8
-polarities_waiting res 1
- ; no of 11... entries in polarities_commanded_buffer, see reversers.asm
+needwrite_slave res 1 ; 0 means we don't need to write to any slave
+ ; non-0 means at least this slave
+ ; and perhaps others
qqtrislat_start equ 0x50
qqtrislat_section udata qqtrislat_start
-qqtrislat_szln2 equ 4 ; ln2(buffer size)
-qqtrislat res 1<<qqtrislat_szln2
+qqtrislat res 15
qqTRISA equ qqtrislat_start + 1
qqTRISB equ qqtrislat_start + 2
ste_lastd0 equ 3 ; d } [o0]* ie every bit is either 0 (for an
ste_lastd1 equ 4 ; d } irrelevant bit) or o, meaning the
ste_lastd2 equ 5 ; d } previously seen detection data bit
-ste_revcmd equ 6 ; r see reverse.asm
ste_detmsgh equ 7 ; dk 1 001 1 000 being 1 001 Y SSS
; offset^ ^which module(s) use this data:
; G global - for use by any code
; d for master detection, see mascan.asm
; * varies per bit
-; r for polarity, see reverse.asm
; .k entry is constant, created during init'n
; flags in ste_flags:
stf_detect equ 7 ; Gk this is a detectors board