chiark / gitweb /
working on reversers
authorian <ian>
Tue, 6 Dec 2005 21:05:57 +0000 (21:05 +0000)
committerian <ian>
Tue, 6 Dec 2005 21:05:57 +0000 (21:05 +0000)
detpic/common.inc
detpic/misc.asm
detpic/pindata.inc
detpic/points.asm
detpic/points.fin
detpic/reverse.asm
detpic/slave.asm
layout/data2safety

index 3150e61992406ad478761ae84db217ac326cd29e..10cfe0a25379b11b040f1acc7c195aa30e70f2e5 100644 (file)
@@ -74,9 +74,31 @@ clock equ -1
 ;  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
@@ -88,6 +110,10 @@ return_interrupt_low macro
        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
@@ -96,6 +122,10 @@ unmask_int_high macro
        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
@@ -106,6 +136,24 @@ tblrd_postdec_fixup macro
        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
 ;
index 04cd2d35b0d7310ebab869c156fa34aa9f7fa9a3..fededfcc8e80fb115bab8c0c6317b59eaa5c136f 100644 (file)
@@ -18,8 +18,7 @@ read_pic_no
        clr_f   TBLPTRH
        clr_f   TBLPTRL
 
-       tblrd   *+
-       dw      0xffff ; silicon errata: B4 issue 4
+       tblrd_postinc_fixup
        mov_fw  TABLAT
        return
 
@@ -33,8 +32,7 @@ idlocs_init
        rcall   read_pic_no
        mov_wf  picno
 
-       tblrd   *+
-       dw      0xffff
+       tblrd_postinc_fixup
        mov_fw  TABLAT
        mov_wf  idloc1
 
index e8ce55ded260070b0aa0dac27f2c1694e1e4a114..e17b8ee13fa2ce7b887eace2fba8838c88e244ee 100644 (file)
@@ -5,7 +5,7 @@
 picno2ptmap            equ     0x6100
 bkptix2portnumbitnum   equ     0x6000
 pic2detinfo            equ     0x6040
-picno2revbits          equ     0x6080
+picno2revmasks         equ     0x6080
 
 maxpic_ln2             equ     5
 maxpic                 equ     1 << maxpic_ln2
index 545d7c7fd045172de0ebce6a76ae730aa81bee90..1e0e78f7596d87db1f38223c600cda465e519187 100644 (file)
@@ -1,42 +1,38 @@
 ;======================================================================
 ; 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
@@ -52,9 +48,7 @@ point_do_here
        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:
@@ -75,11 +69,11 @@ points_interrupt
 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
@@ -125,7 +119,10 @@ point_clash
        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'
 
@@ -142,18 +139,7 @@ points_init
 
        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
@@ -237,7 +223,18 @@ points_init_portbit_endif_used
 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.
 
index 51abd712ee1556a3837b880165822548656b4079..dddeba6c2153a7851316e788fefc1a719ae37e2f 100644 (file)
@@ -1,3 +1,3 @@
- extern points_interrupt
- extern points_init
- extern point_do_here
+ extern point_local_do
+ extern points_local_intr
+ extern points_local_init
index 2e0a5a10e72dc59c257bacda3697a1e8a7a7888a..4f055eba31ac2276c6f1499d668ca128687aaf3e 100644 (file)
@@ -1,21 +1,92 @@
 ;======================================================================
+; 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
@@ -86,23 +157,3 @@ board_next_none
        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
index cad81431e6ebd6ae68445490b443a30739a7d5e7..3b7d6c8151324a6e2eaa8155878e245be9ee5d6e 100644 (file)
@@ -16,7 +16,7 @@ slave
        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)
@@ -39,7 +39,7 @@ i2csu_write_done
 ;----------
 slave_interrupt_low
        enter_interrupt_low
-       call    points_interrupt
+       call    points_local_intr
        return_interrupt_low
 
  include final.inc
index 5943fe727735950cf7640e0bea073405daf26d6a..5ce10affdbe700ca71958a0f3560f8cb00cf4c81 100755 (executable)
@@ -303,11 +303,16 @@ sub boob2objnum ($$$$) {
     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 ($$$) {
@@ -573,27 +578,27 @@ END
 }
 
 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 () {