TI5 ; for iwj
X test-sofar:ch ; bad character received from host
+# Unimplemented things
+UP ; unimplemented point timer setting
+
ZM i2clib:st,:sspstat,:sspcon1,:sspcon2 ; for testing
ZS i2clib:st,:sspstat,:sspcon1,:st_orig ; for testing
DR FSR2L,:outmsg_end ; slave read overrun
# Messages for specific peripherals
-PS FSR0L ; POLARITY message too short
-PL FSR0L ; POLARITY message too long
+RS FSR0L ; POLARITY message too short
+RL FSR0L ; POLARITY message too long
+
+PB points:pointmsg ; Firing point when already busy
;======================================================================
; POINTS
+
+; Idle Firing
+; Timer 3 Off On, counting up
+; pointmsg undefined message from master
+
+ udata_acs
+pointmsg res 1
+
+ udata 0x300
+ptix2latbit res maxpoint * 2 ; bit and LAT*
+
+ code
+
+pt_timer13_prescale equ 0
+pt_timer13_inithigh equ 0
+
+;----------
+point_timer_init
+ mov_lw (1<<RD16) | (1<<T3ECCP1) | pt_timer13_prescale ; Fcy; !TMR3ON
+ mov_wf T3CON
+ bc_f PIR2, TMR3IF
+ bs_f PIE2, TMR3IE
+ bc_f IPR2, TMR3IP
+ mov_lw pt_timer13_inithigh
+ mov_wf TMR3H ; we just leave this here, since we never read TMR3L
+ return
+
+;----------
+point_do_here
+; On slave, called during i2c receive, ie High ISR
+; On master, called during serial receive, ie Low ISR
+; W fire point msg undefined
+ bt_f_if1 T3CON, TMR3ON
+ bra point_clash
+
+ mov_wf pointmsg ; pointmsg = SS zz zz pp pp pp pp pp
+ rcall point_set_pin
+
+ set_f TMR3L
+ bs_f T3CON, TMR3ON
+ panic morse_UP
+ return
+
+;----------
+; Sets the pin appropriately:
+; If we were idle, sets it H (to fire) unless pt0 in which case L
+; If we were firing, sets it L (to stop) unless pt0 in which case H
+point_set_pin
+ mov_lw ptix2lat >> 8
+ mov_wf FSR0H ; FSR0H -> table
+ rl_w pointmsg ; W = point addr, Z iff pt0
+ mov_wf FSR0L ; FSR0 -> &LAT* [Z still iff pt0]
+ bt_f_if1 T3CON, TMR3ON ; Were we firing ? [Z still iff pt0]
+ btg_f STATUS, Z ; Z iff (pt0 xor were_firing)
+ bra_z point_set_pin_l
+point_set_pin_h
+ mov_fw POSTINC0 ; W = bit, FSR0 -> &LAT*
+ mov_ff INDF0, FSR0L ; W = bit, FSR0L -> LAT*
+ set_f FSR0H ; FSR0 -> LAT*, W = bit (still)
+ ior_wff INDF0 ; pin = H
+ return
+
+point_set_pin_l
+ com_fw POSTINC0 ; W = ~bit, FSR0 -> &LAT*
+ mov_ff INDF0, FSR0L ; W = ~bit, FSR0L -> LAT*
+ set_f FSR0H ; FSR0 -> LAT*, W = bit (still)
+ ior_wff INDF0 ; pin = H
+ return
+
+;----------
+point_clash
+ panic morse_PB
+
+
+
+
+ bt_f_if0
+
+
+
+
+ bra_z point_do_if_pt0
+point_do_ifnot_pt0
+ rcall point_pin_h
+point_do_endif_pt0_set_timer
+ mov_lw
+
+point_do_if_pt0
+ rcall point_pin_l
+
+
+
+point_pin_l
+
+
+ rl_w
+
+ bt_f_if0
+
+ add_lw (ptix2lat >> 8) - 0x80
+
+
+
+; We use FSR1 so we have to save it
+ mov_ff FSR1L, fsr1l_save ; we assume FSR1H is zero, since on
+ ; W SS zz zz pp pp pp pp pp
+
+;----------------------------------------------------------------------
+points_init
+; Initialises tables for points
+; Clears TRIS* bits for all points and sets each pin to `not triggering'
+points_init
+
+
;
; Expected layout of data at data_points in flash:
; 4 bytes for each point number
; bytes 1-3 are not defined if number is not assigned
; address of data_points is guaranteed to be multiple of 256
+
+
+
+
udata_acs
udata 0x300