From 582dfdbeb1908be338fca634b880c9a58148c9c6 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 25 Dec 2005 18:08:45 +0000 Subject: [PATCH] i2cm_write stuff; fixes to needwrite etc. --- detpic/mascan.asm | 88 +++++++++++++++++++++++++++++++++++--------- detpic/reverse.asm | 3 +- detpic/serout.asm | 7 ++-- detpic/variables.asm | 4 -- 4 files changed, 76 insertions(+), 26 deletions(-) diff --git a/detpic/mascan.asm b/detpic/mascan.asm index 92ce973..1a2f804 100644 --- a/detpic/mascan.asm +++ b/detpic/mascan.asm @@ -15,6 +15,10 @@ cbyte res 1 ; M0B1 0000 we're expecting more detection byte 1 ; M010 0000 we're expecting more detection byte 2 ; 1000 0000 we're expecting an extra byte + ; ???? ???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 ;====================================================================== ; HANDLING OF I2C EVENTS @@ -37,12 +41,6 @@ i2cmu_write_next_byte bs_f STATUS, Z return - bra_nz write_another_slave - - - - return - ;---------------------------------------- i2cm_intrl ; handles i2c interrupt using i2cm_interrupt[_definite], @@ -200,17 +198,20 @@ i2c_arrange_next_byte ; DECIDING WHICH SLAVE TO ADDRESS ;... i2c_arrange_something -i2cmu_done ; figure out what to do next - which pic to address, etc. - mov_fw needwrite_slave - bra_nz arrange_write + bs_f cbyte, cbyte_halted + + tst_f_ifnz wslave ; anyone asked to write ? + bra arrange_write +nextslave_nowrite + ; no writing needed, we consider reading: + neg_fw outmsg_begin + add_wfw outmsg_end + and_lw outbuf_size - 1 + cmp_fw_ifle outmsg_targetlen + return ; target len < actual len, do not add anything + ; ok, there's space, go ahead: - ; add calls to needwrite_ here: - call needwrite_polarity - call needwrite_points - ; end of list of calls to needwrite_ - - ; no writing needed, we have to read: mov_lfsr slavetable, 1 ; FSR1H -> slavetable mov_ff cslot, FSR1L ; FSR1 -> current ste_flags mov_lw ste_size ; W = ste_size @@ -223,16 +224,69 @@ nextslave_reloop_resume mov_ff FSR1L, cslot ; cslot -> new ste_flags bt_f_if1 POSTDEC1, stf_sentinel ; FSR1 -> ste_slave bra nextslave_reloop + ; no wrap around: 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 -fixme do not i2cm_read_start if no room in buffer -fixme check that we don't accidentally skip reading a slave +;---------------------------------------- +i2cmu_done + ; So we've done one write. + bs_f cbyte, cbyte_halted + + tst_f_ifnz wslave ; anyone asked in the meantime ? + bra arrange_write + + ; Anyone else to write to ? + ; add calls to needwrite_ here: + call needwrite_polarity + call needwrite_points + ; end of list of calls to needwrite_ + + ; no, if we're here, no-one wants to write + bra nextslave_nowrite + +;---------------------------------------- +i2c_needwrite +; Informs mascan that we need to write to some slave. +; Some time after this, mascan will call getwritebyte_ +; and this must yield at least one byte to write. +; W slave that we must write to + mov_wf wslave + bt_f_if0 cbyte, cbyte_halted + return ; we're currently doing something +;... +;---------- +arrange_write +; wslave slave to write to + bc_f cbyte, cbyte_halted + mov_fw wslave + mov_wf cwslave + clr_f wslave + goto i2cm_write_start + +;---------------------------------------- +i2c_consider_restartread + bt_f_if0 cbyte, cbyte_halted + return + bra nextslave_nowrite + +;====================================================================== +; 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 ;====================================================================== ; PROCESSING OF INCOMING BYTES - EXTRA (NON-DETECTION) diff --git a/detpic/reverse.asm b/detpic/reverse.asm index 1e57c37..236e01e 100644 --- a/detpic/reverse.asm +++ b/detpic/reverse.asm @@ -199,9 +199,8 @@ polarity_needwrite_loop mov_fw FSR1L add_lw -polarity_cmds - mov_wf needwrite_slave pop - return + goto i2c_needwrite near_getwritebyteyes code ;---------------------------------------------------------------------- diff --git a/detpic/serout.asm b/detpic/serout.asm index 7dbd6d2..33d9b2b 100644 --- a/detpic/serout.asm +++ b/detpic/serout.asm @@ -58,7 +58,8 @@ serialtx_intrl tx_justsent_noacknmra inc_f outmsg_begin bc_f outmsg_begin, outbuf_szln2 - goto led_green + call led_green ; we're transmitting + goto i2c_consider_restartread tx_bufempty ; maybe we send an NMRADONE @@ -66,7 +67,7 @@ tx_bufempty bra_nz tx_acknmra_send ; nothing at all to do: bc_f PIR1, TXIE - goto led_black + goto led_black ; we're not transmitting tx_acknmra_insert sub_wff acknmra ; we're acking these now @@ -95,7 +96,7 @@ portb_read tx_fcdisable bc_f PIR1, TXIE bs_f INTCON, RBIE - goto led_red + goto led_red ; flow control forces us not to transmit ;---------------------------------------------------------------------- serialtxfc_init diff --git a/detpic/variables.asm b/detpic/variables.asm index 90db760..b1edb4f 100644 --- a/detpic/variables.asm +++ b/detpic/variables.asm @@ -27,11 +27,7 @@ isr_high_save_fsr0 res 2 ; for isrh_fsr0_{save,restore} xdebug res 8 -; for writing to slaves: cwslave res 1 ; slave we're currently actually writing to -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 -- 2.30.2