; Timer 3 point fire timer point fire timer
; ECCP - -
+;----------------------------------------------------------------------
+; Conventional routine names:
+;
+; <periph>_local_do Process a master-to-slave command to activate
+; a local peripheral (also called on master to
+; activate its own local peripherals)
+;
+; <periph>_local_init Initialises RAM tables for local peripheral
+; and arranges for pins to be set in appropriate
+; quiescent state. Configures pic built-in
+; peripherals.
+;
+; <periph>_local_intr Low ISR service routine.
+; Checks for, and clears, any relevant interrupt,
+; and returns with `return'.
+;
+; <periph>_master_do Called when an appropriate message has been
+; received from the host.
+;
;----------------------------------------------------------------------
; MACROS
+;----------------------------------------
+; For entering and leaving Low ISR, saving and restoring STATUS and W
+
enter_interrupt_low macro
mov_ff STATUS, isr_low_save_status
mov_wf isr_low_save_w
retfie
endm
+;----------------------------------------
+; For disabling all interrupts, to make a critical section:
+; (for use from main program and Low ISR only)
+
mask_int_high macro
bc_f INTCON,GIEH
endm
bs_f INTCON,GIEH
endm
+;----------------------------------------
+; For the fix specified in the silicon errata:
+; silicon revision B4 issue 4
+
tblrd_postinc_fixup macro
tblrd *+
dw 0xffff
dw 0xffff
endm
+;----------------------------------------
+; For setting up TBLPTR according to the picno
+
+load_perpic_tblptr macro flash_map_base, perpic_entry_size
+ movlw perpic_entry_size
+ mul_wf picno
+
+ mov_lw flash_map_base & 0xff
+ add_wfw PRODL
+ mov_wf TBLPTRL
+
+ mov_lw flash_map_base >> 8
+ addc_wfw PRODH
+ mov_wf TBLPTRH
+
+ clr_f TBLPTRU ; TBLPTR* -> our point data
+ endm
+
;----------------------------------------------------------------------
; PINSPECS stuff
;
clr_f TBLPTRH
clr_f TBLPTRL
- tblrd *+
- dw 0xffff ; silicon errata: B4 issue 4
+ tblrd_postinc_fixup
mov_fw TABLAT
return
rcall read_pic_no
mov_wf picno
- tblrd *+
- dw 0xffff
+ tblrd_postinc_fixup
mov_fw TABLAT
mov_wf idloc1
picno2ptmap equ 0x6100
bkptix2portnumbitnum equ 0x6000
pic2detinfo equ 0x6040
-picno2revbits equ 0x6080
+picno2revmasks equ 0x6080
maxpic_ln2 equ 5
maxpic equ 1 << maxpic_ln2
;======================================================================
; POINTS
+ include common.inc
+
+;----------------------------------------
+; LOCAL POINTS - Variables, hardware, etc.
+;
; Idle Firing
; Timer 3 Off On, counting up
; pointmsg undefined message from master
- include common.inc
-
- udata_acs
-pointmsg res 1
-
ptix2bitlat equ 0x300
udata ptix2bitlat
res maxpoint * 2 ; bit and LAT*
; for unused point, 0x00 and 0x00
- code
+ udata_acs
+pointmsg res 1
pt_timer13_prescale equ 0
pt_timer13_inithigh equ 0
+;======================================================================
+ code
+
;======================================================================
; LOCAL POINTS
-; Actually doing points (on slave, or master's own)
+; on slave, or master's own
-;--------------------
-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
+;----------------------------------------------------------------------
+; LOCAL POINTS - ACTUALLY DOING
;----------------------------------------
-point_do_here
+point_local_do
; On slave, called during i2c receive, ie High ISR
; On master, called during serial receive, ie Low ISR
; W fire point msg undefined
return
;----------------------------------------
-points_interrupt
-; Low priority; checks for, and clears, any relevant interrupt.
-; Then returns.
+points_local_intr
bt_f_if0 PIR2, TMR3IF
return
; OK, we're done:
point_spurious_intr
panic morse_PI
-;--------------------
+;----------
+point_set_pin
; 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 ptix2bitlat >> 8
mov_wf FSR0H ; FSR0H -> table
rl_fw pointmsg ; W = point addr, Z iff pt0
panic morse_PB
;----------------------------------------------------------------------
-points_init
+; LOCAL POINTS - INITIALISATION
+
+;----------------------------------------
+points_local_init
; Initialises tables for points
; Clears TRIS* bits for all points and sets each pin to `not triggering'
mov_lfsr ptix2bitlat, 0 ; FSR0 -> this bit and LAT*
- mov_lw maxpoint/8
- mul_wf picno
-
- mov_lw picno2ptmap & 0xff
- add_wfw PRODL
- mov_wf TBLPTRL
-
- mov_lw picno2ptmap >> 8
- addc_wfw PRODH
- mov_wf TBLPTRH
-
- clr_f TBLPTRU ; TBLPTR* -> our point data
+ load_perpic_tblptr picno2ptmap, maxpoint/8
mov_lw maxpoint/8
mov_wf t ; t = byte counter
point_initing_bad_point
panic morse_PF
-;----------------------------------------------------------------------
+;----------
+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
+
+;======================================================================
;cdu_init
; For master pic only. Sorts out the CDU's pin.
- extern points_interrupt
- extern points_init
- extern point_do_here
+ extern point_local_do
+ extern points_local_intr
+ extern points_local_init
;======================================================================
+; REVERSERS
+;----------------------------------------
+; LOCAL REVERSERS - Variables
-board0 res 1
-gather res 1
+ udata_acs
+maska res 1
+maske res 1
-polarities_waiting res 1
+;----------------------------------------
+; MASTER - Access bank variables and other sections
+
+board0 res 1
+gather res 1
+
+polarities_waiting res 1
; no of 11... entries in reversers_commanded_buffer
-reversers_commanded_buffer res 32
+ udata
+polarities_commanded_buffer res maxpic+1
; Each byte is:
- ; 11RRRRRRR reverse command for slave pic
- ; 000000001 this pic is not a reversers pic
- ; 000000000 have sent any relevant POLARITY
+ ; 11RRRRRRR reverse command for slave, waiting to write
+ ; 000000001 that pic is not a reversers pic
+ ; 000000000 we have written any relevant command
; 000000002 sentinel
+ code
+;======================================================================
+; LOCAL REVERSERS
+; on slave, or master's own
+
+;----------
+polarity_local_do
+; W here polarity msg PP PP v3 v0 v2 v1 v5 v4
+;
+; where PP bits are those specifying that this is a polarity message
+; v<num> is the reversal bits for point <num>
+;
+ mov_wf t ; t = PP PP v3 v0 v2 v1 v5 v4
+
+ mov_wf LATE ; W = kk kk kk kk kk kk o5 o4
+ xor_wfw t ; W = ?? ?? ?? ?? ?? ?? d5 d4
+ and_wfw maske ; W = zz zz zz zz zz zz d5 d4
+ xor_wff LATE ; LATA = kk kk kk kk kk kk v5 v4
+
+ bc_f t,2 ; t = SS SS v3 v0 v2 v1 zz v4
+ bt_f_if1 t,4 ; t : .. .. .. v0 .. .. .. ..
+ bs_f t,2 ; t = SS SS v3 v0 v2 v1 v0 v4
+
+ mov_wf LATA ; W = kk kk o3 kk o2 o1 o0 kk
+ xor_wfw t ; W = ?? ?? d3 ?? d2 d1 d0 ??
+ and_wfw maska ; W = zz zz d3 zz d2 d1 d0 zz
+ xor_wff LATA ; LATA = kk kk v3 kk v2 v1 v0 kk
+
+ ; where kk is a bit we must keep
+ ; o<n> is old reverse bit
+ ; d<n> is old (+) new
+ ; v<n> is new reverse bit
+ return
+
+;----------
+polarity_local_init
+ load_perpic_tblptr picno2revmasks, 2
+
+ tblrd_postinc_fixup
+ mov_fw TABLAT
+ mov_wf maska
+
+ tblrd_postinc_fixup
+ mov_fw TABLAT
+ mov_wf maske
+
+ clr_w
+ rcall polarity_local_do
+
+ com_fw maska
+ and_wf TRISA
+
+ com_fw maske
+ and_wf TRISE
+
+ return
+
+;======================================================================
+; MASTER
+
;----------
-polarity_decode_message
+polarity_master_do
; message format
; SS zz zz SS ZZ 2f 2e 2d g is board 2
; MM 2c 0f 0e 0d 0c 0b 0a board 0
pop
return
-
-;----------
-polarity_do_here
-; W here polarity msg SS SS v3 v0 v2 v1 v5 v4
- mov_wf input ; input = SS SS v3 v0 v2 v1 v5 v4
-
- mov_wf LATE ; W = kk kk kk kk kk kk o5 o4
- xor_wfw input ; W = ?? ?? ?? ?? ?? ?? d5 d4
- and_wfw maske ; W = zz zz zz zz zz zz d5 d4
- xor_wff LATE ; LATA = kk kk kk kk kk kk v5 v4
-
- bc_f input,2 ; input = SS SS v3 v0 v2 v1 zz v4
- bt_f_if1 input,4 ; input : .. .. .. v0 .. .. .. ..
- bs_f input,2 ; input = SS SS v3 v0 v2 v1 v0 v4
-
- mov_wf LATA ; W = kk kk r3 kk r2 r1 r0 kk
- xor_wfw input ; W = ?? ?? r3 ?? r2 r1 r0 ??
- and_wfw maska ; W = zz zz r3 zz r2 r1 r0 zz
- xor_wff LATA ; LATE = kk kk r3 kk r2 r1 r0 kk
- return
mov_fw picno
call i2cs_init
call bitnum2bit_init
- call points_init
+ call points_local_init
call det_slave_init
mov_lw (1<<GIEH) | (1<<GIEL)
;----------
slave_interrupt_low
enter_interrupt_low
- call points_interrupt
+ call points_local_intr
return_interrupt_low
include final.inc
return &{"boob2objnum_$kind"}($boardnum,$obj,$type,$mkused);
}
-sub boob_used_bit ($$$) {
+sub boob_used ($$$) {
my ($boardnum,$obj,$kind) = @_;
my ($objnum);
$objnum= boob2objnum($boardnum, $obj, $kind, 0);
- return defined $pin_used{$kind}[$objnum] ? 1 : 0;
+ return $pin_used{$kind}[$objnum];
+}
+
+sub boob_used_bit ($$$) {
+ my ($boardnum,$obj,$kind) = @_;
+ return defined boob_used($boardnum,$obj,$kind) ? 1 : 0;
}
sub so_boob ($$$) {
}
sub writeasm_reverse {
- my ($num,$kc,$bit);
- o_section('picno2revbits',<<END);
-; Table listing which reversers are connected/enabled.
-; Index is pic number. Value is 0xff for non-reversers boards,
-; or bitmap of connected reversers. LSbit is reverse 0, etc.
+ my ($num,$kc,$bit, @portae,$pu);
+ o_section('picno2revmasks',<<END);
+; Table listing which reversers are connected/enabled. Index is pic
+; number. Each entry is 2 bytes: mask for port A followed by mask for
+; port E. A 1 bit is a connected reverser. Both masks are 0 for
+; non-reversers boards.
END
for ($num=0; $num<@boardtype; $num++) {
- o_db($num, 4);
+ @portae= ([],[]);
$kc= $kind_count{$boardtype[$num]}{'reverse'};
- if ($kc) {
- die if $kc > 7;
- o("b'");
- for ($bit= $kc-1; $bit>=0; $bit--) {
- o(boob_used_bit($num, $bit, 'reverse'));
- }
- o("'");
- } else {
- o('0xff');
+ for ($bit= $kc-1; $bit>=0; $bit--) {
+ $pu= boob_used($num, $bit, 'reverse');
+ next unless $pu;
+ $pu->[1] =~ m/^([04])\,\d,(0x\w{2})$/ or die;
+ push @{ $portae[!!$1] }, $2;
}
+ o(' db ');
+ o(join(', ', map { @$_ ? join('|',@$_) : '0' } @portae));
+ o(sprintf " ; %d\n",$num);
}
- o_section_end_fill($num, '0xffff', 1);
+ o_section_end_fill($num, '0xffff', 2);
}
sub writeasm () {