# Unimplemented things
UEC
UER
-UCT
-UCI
-UCP
# Messages for i2clib, S*
SM i2clib+panic:st,:sspstat,:sspcon1,:sspcon2 ; m.,i., ctrlr bad state
PF ::t ; Flash mentions point not on board
PX ; Host sent >2-byte POINT command
PM ; Firing point when master/CDU busy
+PC ; POINTED when already charging
+PA ; POINTED when already firing
+PQ ; we're confused about CDU charged
;======================================================================
; VARIABLES, HARDWARE, ETC
;
-; Idle Idle Firing Charging
-; (slave) (master) (master)
-; Timer 3 Off Off On, counting up Off
-; pointmsg undefined 0x00 message from master message
+; Timer 3 pointmsg pointslave cducharging
+;
+; S Idle Off undefined undefined undefined
+; S Firing Counting up 100PPPPP undefined undefined
+; M Idle Off 00000000 0000 0000 0x00
+; M Firing Counting up 100PPPPP 0000 0000 0x00
+; M Telling Off 100PPPPP 00SS Sss0 0x00
+; M Told Off 100PPPPP 0000 0000 0x00
+; M Charging Off 100PPPPP 0000 0000 >0
+;
+; notes: firing see ie, slave*2 Counts down
+; timeout detect.asm in ticks
+
+cdu_timeout equ 200 ; ms
ptix2latbit equ 0x300 ; has to be a multiple of 0x100
ptix2latbit_section udata ptix2latbit
; for unused point, 0x00 and 0x00
udata_acs
-pointslave res 1 ; 00SS Sss0 ie slave*2 !
+pointslave res 1
pointmsg res 1
+cducharging res 1
udata 0x340
slave2ptinfo res maxpics
bt_f_if0 STATUS, Z ; right slave ?
return
; yes:
- mov_fw pointslave
+ clr_f pointslave ; we're writing now, excellent
+ mov_fw pointmsg
goto i2c_getwritebyte_yes
;======================================================================
; CDU
-near_gots code
+;--------------------
+cdu_init
+ clr_f pointslave
+ clr_f pointmsg
+ clr_f cducharging
+ return
+
+;--------------------
+cdu_tick
+ tst_f_ifnz cducharging
+ dec_f_ifnz cducharging ; so, decrement only if it was nonzero
+ return ; return if we either didn't decrement,
+ ; or didn't reach zero
+
+ bt_f_if0 pointmsg, 7
+ bra cdu_charged_not_charging
+ ; ok:
-cdu_tick panic morse_UCT
-cdu_init panic morse_UCI
-; For master pic only. Sorts out the CDU's pin.
+ clr_f pointmsg
+ ; cducharging is already zero, from above
+ mov_lw b'00101000' ; CHARGED
+ goto serial_addbyte
+
+cdu_charged_not_charging panic morse_PQ
-got_pointed panic morse_UCP
+near_gots code
+;--------------------
+got_pointed
+ tst_f_ifnz cducharging
+ bra pointed_already_charging
+ bt_f_if0 pointmsg, 7
+ bra pointed_butnot_firing
+ mov_lw cdu_timeout / 10 ; time in ms, converted to 10ms ticks
+ mov_wf cducharging
+ mov_lw b'00100000' ; POINTED
+ goto serial_addbyte
+
+pointed_butnot_firing panic morse_PA
+pointed_already_charging panic morse_PC
;======================================================================
include final.inc