@ macro
endm
-D macro v
- mov_lw v
+;----------------------------------------
+; For adding a byte to the debug buffer.
+; Not for use in High ISR. In all cases:
+;
+; STATUS any trashed
+; all others any preserved
+
+ ifndef NDEBUG
+;----------
+Dv macro ; sorry, but assembler's dw directive isn't case-sensitive
+;
+; W message byte preserved
+;
call debugbyte
endm
+;----------
+Dl macro debug_literal_value
+;
+; W any literal value as specified
+;
+ mov_lw debug_literal_value
+ Dv
+ endm
+
+;----------
+Df macro debug_register_file_address
+;
+; W any value from specified memory location
+;
+ mov_fw debug_register_file_address
+ Dv
+ endm
+ else
+Dv macro
+ endm
+Dl macro debug_literal_value
+ endm
+Df macro debug_register_file_address
+ endm
+ endif
+
;----------------------------------------
; For entering and leaving Low ISR, saving and restoring STATUS and W
; See above under <something>_intrl, and {master,slave}_interrupt_low
; must be Off:
pin_vl p0_booster_shutdown
- D 0x81
- bt_f_if1 xdebug+6, 0
- bs_f xdebug+6, 1
+ Dl 0x81
goto cdu_on
;----------
;
; See i2clib.asm for documentation of the interface to this file.
- ; include /usr/share/gputils/header/p18f458.inc
- ; radix dec
- ; include ../iwjpictest/insn-aliases.inc
+ include /usr/share/gputils/header/p18f458.inc
+ radix dec
+ include ../iwjpictest/insn-aliases.inc
- ; include ../iwjpictest/clockvaries.inc
- ; include panic.inc
- ; include morse+auto.inc
- ; include i2clib.incm
+ include ../iwjpictest/clockvaries.inc
+ include panic.inc
+ include morse+auto.inc
+ include i2clib.incm
- include common.inc
;======================================================================
; NOTATION
;----------
i2cm_interrupt
- D 0x50 ;!P
bt_f_if0 PIR1, SSPIF
return
; We have an interrupt:
;...
i2cm_interrupt_definite
- D 0x51 ;!P
mov_ff SSPSTAT, sspstat
mov_ff SSPCON1, sspcon1
mov_ff SSPCON2, sspcon2
and_wfw sspcon1
bra_nz m_event_bad
- mov_fw st ;!P
- call debugbyte ;!P
-
; No ? Well, then the I2C should be idle now:
mov_fw sspcon2
- call debugbyte ;!P
and_lw ~((1<<ACKSTAT) | (1<<ACKDT)) ; those two are ok if set
bra_nz m_event_bad
; OK...
include program+externs.fin
include i2clib.inc
- include variables+vars.fin
-
end
- extern QQ_detect_slave_init
- extern QQ_i2csu_read_begin
- extern QQ_i2csu_read_another
-
;######################################################################
; i2clib.inc - I2C LIBRARY - DECLARATIONS AND DOCUMENTATION
;
code
;----------------------------------------
i2cmu_write_next_byte
- D 0x61
- mov_fw cwslave
- call debugbyte
+ Dl 0x91
; add calls to getwritebyte_<foo> here:
- D 0x62
- mov_lfsr 0x5f+2, 0
- mov_fw INDF0
- call debugbyte
call polarity_getwritebyte
- D 0x63
- mov_lfsr 0x5f+2, 0
- mov_fw INDF0
- call debugbyte
call points_getwritebyte
- D 0x64
- mov_lfsr 0x5f+2, 0
- mov_fw INDF0
- call debugbyte
; end of list of calls to getwritebyte_<foo>
; so, no-one wants this slave:
bs_f STATUS, Z
i2cm_intrl @
; handles i2c interrupt using i2cm_interrupt[_definite],
; according to the rules for <something>_intrl.
- D 0x60
+ Dl 0x90
bt_f_if0 PIR1, SSPIF
return
call i2cm_interrupt_definite
; W = received byte
mov_wf b ; W = b = received byte
- D 0x70
- mov_fw cslot
- call debugbyte
- mov_fw cbyte
- call debugbyte
- mov_fw b
- call debugbyte
+ Dl 0x90
+ Df cslot
+ Df cbyte
+ Df b ; also restores b to W
+
mov_lfsr slavetable, 1
mov_ff cslot, FSR1L ; FSR1 -> slave's flags
mov_fw POSTINC1 ; W = detbasel; FSR1 -> lastd0
rcall read_got_detectbyte_prep ; b = 0d00dddd
; u = 0C00CCCC
- ;mov_ff b, xdebug+5
bt_f_if1 b, 6 ; b bit .d......
bs_f b, 4 ; b = 0d0ddddd
; ^ ^ copies of same bit
add_lw 5 ; W = adjdetbasel
bs_f FSR1L, 2 ; FSR1L -> lastd1
bc_f cbyte, 4 ; cbyte = M0B00000
- mov_ff xdebug+4, xdebug+5
- mov_ff xdebug+3, xdebug+4
- mov_ff b, xdebug+3
rcall read_got_detectbyte_prep
goto addmsgs_all
; FSR1 -> lastd<n>
;
mov_wf u ; u = [C0]*
- D 0x74
- mov_fw FSR1L
- call debugbyte
- mov_fw u
- call debugbyte
- xor_wff INDF1 ; lastd<n> = [d0]*
+
+ Dl 0x74
+ Df FSR1L
+ Df u ; also restores u to W
+
+ xor_wff INDF1 ; lastd<n> = [d0]*
; to force test of repeated detection notification,
; comment out previous line
mov_lw 0x07
; NOS return address for i2cmu_read_got_byte
;
mov_wf t ; t = adjdetbasel
- D 0x73
- mov_fw INDF1
- call debugbyte
+ Dl 0x73
+ Df INDF1
mov_fw b ; W = [d0]*
- call debugbyte
+ Dv
xor_wfw INDF1 ; W = [C0]*, Z iff same
; where C set iff change to that detection segment
bra_nz read_got_detectbyte_prep_ifsomething
bra nextslave_looparound
; Ok, we have a slave:
- D 0x71
+ Dl 0x91
mov_fw INDF1 ; W = new slave number
goto i2cm_read_start
nextslave_looparound
- bt_f_if1 xdebug+6,2
- goto boom2
-
- bt_f_if1 xdebug+6,1
- bs_f xdebug+6,2
-
; now we do our own detection
mov_lw (slavetable + ste_flags) & 0xff ; select our own slot
mov_wf cslot
- D 0x72
+ Dl 0x72
call read_detection_head_master
goto i2cmu_read_got_byte
-boom2
- panic morse_TI1
-
;----------------------------------------
i2c_needwrite @
; Informs mascan that we need to write to some slave.
; TOS - 4 -> bt_f_if1 u, b'bbb'
; TOSL ???bbb00
; other conditions on entry and exit as for entry to addmsgs_<kind>, above
- ;dec_f_ifz xdebug+7
- ;bra boom
- D 0x75
- mov_fw TOSL
- call debugbyte
+ Dl 0x75
+ Df TOSL
rr_fw TOSL ; W = 0???bbb0
rr_w ; W = 00???bbb
ior_lw 0xf8 ; W = 11111bbb
bt_f_if0 STATUS, Z
mov_lw 0x08 ; train: W = 0 000 0 000; none: W = 0 000 1 000
xor_wfw INDF1 ; W = 1 001 Y SSS (det msg high byte)
- call debugbyte
+ Dv
call serial_addbyte
- ;bt_f_if1 xdebug+6, 0
- ;bra boom
-
mov_fw v ; W = 0 SSSSSSS (det msg low byte)
- call debugbyte
+ Dv
goto serial_addbyte_another
addmsg_bad panic morse_DJ
-boom
- panic morse_TI5
;======================================================================
include final.inc
;--------------------
cdu_on @
- clr_f xdebug+0
pin_h p0_cdu_enable
return
; Master-specific initialisation.
call memory_erase
clr_f flags
- set_f xdebug+7
- clr_f xdebug+6
call serial_init
call i2cm_init
call serialtxbuf_init
call power_polarising_init
call power_fault_init
call watchdog_init
- clr_f xdebug+0
return
-boom3
- panic morse_TI3
-
;----------------------------------------
master_interrupt_low @
enter_interrupt_low
- D 0x80
- mov_lfsr 0x5f+2, 0
- mov_fw INDF0
- xor_lw 0x40
- bra_nz boom3
+ Dl 0x80
call tick_intrl
- D 0x01
call nmra_serialrx_intrl
- D 0x02
call power_fault_intrl
- D 0x03
call serialtxfc_intrl
- D 0x04
call serialtx_intrl
- D 0x05
call points_local_intrl
- D 0x06
call i2cm_intrl
- bs_f xdebug+0, 5
panic morse_IL
;----------------------------------------------------------------------
call serial_addbyte
mov_fw t
bra_n command_ping_bad
- mov_wf xdebug+6
goto serial_addbyte_another
command_ping_bad panic morse_HP
cwslave res 1 ; slave we're currently actually writing to
; undefined except in <something>_needwrite
-qqtrislat_start equ 0x50
-qqtrislat_section udata qqtrislat_start
-qqtrislat res 15
-
-qqTRISA equ qqtrislat_start + 1
-qqTRISB equ qqtrislat_start + 2
-qqTRISC equ qqtrislat_start + 3
-qqTRISD equ qqtrislat_start + 4
-qqTRISE equ qqtrislat_start + 5
-
-qqLATA equ qqtrislat_start + 7
-qqLATB equ qqtrislat_start + 8
-qqLATC equ qqtrislat_start + 9
-qqLATD equ qqtrislat_start + 0xa
-qqLATE equ qqtrislat_start + 0xb
-
;----------------------------------------------------------------------
; NON-ACCESS-BANK SECTIONS (TABLES)