;====================================================================== ; MASTER - SCANNING ETC. include common.inc ;---------------------------------------------------------------------- udata_acs b res 1 ; byte just read cslot res 1 ; current slave in slave table, points to flags byte cbyte res 1 ; one of the following: ; 0000 0000 we're expecting the first byte ; 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 ;---------------------------------------------------------------------- slavetable_section udata 0x280 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<_intrl. bt_f_if0 PIR1, SSPIF return call i2cm_interrupt_definite intrl_handled_nostack ;---------------------------------------- i2cmu_done panic morse_MD ;---------------------------------------- i2cmu_write_next_byte panic morse_UI ;====================================================================== ; PROCESSING OF INCOMING BYTES ;---------------------------------------- i2cmu_read_got_byte ; Beforehand At call ; State Reading Reading-Wait ; W data from slave ; ; See detect.asm head comment for protocol info, in particular ; the meaning of these bytes. ; 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: 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 = ?d??dddd mov_lw 0x07 ior_wff FSR1L ; FSR1L -> detmsgh return ; to addmsgs_ ;---------------------------------------- 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 rcall 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 ;---------- read_prep_detectbyte ; W adjusted detbase l ; cbyte set for next byte to read ; b received byte ; FSR1 -> lastd ; TOS -> goto addmsgs_ ; NOS return address for i2cmu_read_got_byte mov_wf t ; t = adj.detbasel mov_fw b ; W = ?d??dddd xor_wfw INDF1 ; lastd = ?C??CCCC, Z iff same bra_nz read_got_detectbyte_something xor_wfw INDF1 ; lastd = ?d??dddd ; there's nothing to do pop ;... ;---------------------------------------- i2c_arrange_next_byte tst_f_ifnz cbyte goto i2cm_read_another ;... ;====================================================================== ; DECIDING WHICH SLAVE TO ADDRESS ;... i2c_arrange_something ; figure out what to do next - which pic to address, etc. panic morse_UG ;====================================================================== ; GENERATION OF DETECTION MESSAGES FOR HOST - MAD BT_F_IF1 TABLES 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, ; 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 and_wfw INDF0 ; W = .....d.., Z iff detect bt_f_if1 STATUS, Z bs_f u, 3 ; u = 1 001 Y SSS mov_fw u rcall serial_addbyte mov_fw t goto serial_addbyte_another ;====================================================================== include final.inc