chiark / gitweb /
new detection and points arrangements; builds
authorian <ian>
Mon, 5 Dec 2005 03:29:57 +0000 (03:29 +0000)
committerian <ian>
Mon, 5 Dec 2005 03:29:57 +0000 (03:29 +0000)
14 files changed:
detpic/Makefile
detpic/common.inc
detpic/detect.asm
detpic/detect.inc
detpic/final.inc
detpic/misc.asm
detpic/misc.fin
detpic/morse.messages
detpic/points.asm
detpic/points.fin [new file with mode: 0644]
detpic/slave.asm
detpic/test-sofar.asm
detpic/variables.asm
layout/Makefile

index 6f005e3beab2519bfa6ef3de2070adde26c63cd8..26901368aca08ae7f37045f2db74ca75ed7b216b 100644 (file)
@@ -4,7 +4,7 @@ PICNOS=         0 1 2
 
 PROGRAMS=              test-sofar
 OBJS_test-sofar=       vectors.o panic.o routines-led.o i2clib.o       \
-                       misc.o slave.o detect.o variables.o             \
+                       misc.o slave.o detect.o variables.o points.o    \
                        syncwrite.o
 XCODEN_test-sofar=     morse
 XCODE1_test-sofar=     blank2 ours+pindata
@@ -19,7 +19,8 @@ INCLUDES=     common.inc                      \
                ../iwjpictest/clockvaries.inc   \
                vectors.fin                     \
                pindata.inc                     \
-               detect.inc
+               detect.inc                      \
+               points.fin
 
 VARSFILES=     variables
 
index ebf3de5d649576943786e3aeb480a445c1e1ca62..3150e61992406ad478761ae84db217ac326cd29e 100644 (file)
@@ -13,6 +13,7 @@
 clock equ -1
        include         ../iwjpictest/clockvaries.inc
        include         variables+vars.inc
+       include         pindata.inc
 
 ;----------------------------------------------------------------------
 ; Common conventions for function register notation:
@@ -25,8 +26,8 @@ clock equ -1
 ;   t                  Low ISR                 Low ISR
 ;   TBLPTR*,TABLAT     Low ISR                 Low ISR
 ;   FSR0               Low ISR                 Low ISR
-;   FSR1               Low ISR                 High ISR (detect)
-;   FSR2               Low ISR                 High ISR (detect)
+;   FSR1               Low ISR                 High ISR (detect[1])
+;   FSR2               Low ISR                 High ISR (detect[1])
 ;
 ; Trashed      May be trashed by any routine anywhere.  Saved
 ;              during every ISR entry/exit.
@@ -60,6 +61,9 @@ clock equ -1
 ; A routine which is allowed to trash a register may document that it
 ; saves that register for the benefit of its callers.
 ;
+;  [1] FSR1 and FSR2 on slave pics are reserved exclusively for the
+;      I2C response and detection code (detect.asm), after det_slave_init.
+;
 ; General-purpose hardware allocation:
 ;
 ;                      Master                  Slave
@@ -73,6 +77,35 @@ clock equ -1
 ;----------------------------------------------------------------------
 ; MACROS
 
+enter_interrupt_low macro
+       mov_ff  STATUS, isr_low_save_status
+       mov_wf  isr_low_save_w
+       endm
+
+return_interrupt_low macro
+       mov_fw  isr_low_save_w
+       mov_ff  isr_low_save_status, STATUS
+       retfie
+       endm
+
+mask_int_high macro
+       bc_f    INTCON,GIEH
+       endm
+
+unmask_int_high macro
+       bs_f    INTCON,GIEH
+       endm
+
+tblrd_postinc_fixup macro
+       tblrd   *+
+       dw      0xffff
+       endm
+
+tblrd_postdec_fixup macro
+       tblrd   *-
+       dw      0xffff
+       endm
+
 ;----------------------------------------------------------------------
 ; PINSPECS stuff
 ;
index 7abdf2501852f30e76e4f0ef7b8b11d84d8efe9e..b9d9bcf88b0685e9181a43542a88d47dd594e3c5 100644 (file)
@@ -138,13 +138,23 @@ det_slave_init
        goto    reset_message_buffer
 
 ;----------
+message_for_master
+; Either transmits the message to the master, or if we are the master,
+; handles it as an incoming message from the notional `slave 0'.
+;  W           message         unchanged
+;  GIEH                set             set
+       bt_f_if1 idloc1,idloc1_master
+       goto    loopback_read_byte
+
+;.....
+;----------------------------------------
 slave_add_short_message
 ;  W           message         unchanged
 ;  GIEH                set             set
-       bc_f    INTCON,GIEH
+       mask_int_high
        bs_f    POSTINC1,7
        mov_wf  INDF1
-       bs_f    INTCON,GIEH
+       unmask_int_high
        return
 
 ;----------
index 70f580dd5883b437de98b1825772df0b1c056306..fc56c0de97ade1483990dab189471b7e868b4e15 100644 (file)
@@ -1,3 +1,4 @@
  extern det_slave_init
+ extern message_for_master
  extern backgroundloop_reversers
  extern backgroundloop_detectors
index e7e771a3a4af85648ffd148d97d4739978925373..325852dd697bac6a0e1c3ecbdcfeb4315f2a9046 100644 (file)
@@ -1,10 +1,12 @@
  extern slave
+ extern loopback_read_byte
 
  include vectors.fin
  include i2clib.inc
  include panic.fin
  include routines-led.fin
  include misc.fin
+ include points.fin
  include variables+vars.fin
  include detect.inc
  include ../iwjpictest/syncwrite.inc
index 5eeca037dcab05a0881d62a7d10df33baebbad15..04cd2d35b0d7310ebab869c156fa34aa9f7fa9a3 100644 (file)
@@ -1,9 +1,11 @@
 ;======================================================================
-; GENERALLY USEFUL ROUTINES
 
  include common.inc
  code
 
+;======================================================================
+; GENERALLY USEFUL ROUTINES
+
 ;----------
 read_pic_no
 ; read pic no from ID locations and return it
@@ -22,7 +24,7 @@ read_pic_no
        return
 
 ;----------
-init_read_idlocs
+idlocs_init
 ; read id locations and store in canonical place
 ;      W               undefined               undefined
 ;      picno           undefined               pic number (from 20000)
@@ -39,7 +41,7 @@ init_read_idlocs
        return
 
 ;----------
-init_bitnum2bit
+bitnum2bit_init
 ; populate bitnum2bit
        mov_lw  0x80
        mov_lfsr bitnum2bit,0
@@ -49,10 +51,7 @@ init_bitnum2bit_loop
        bra_nn  init_bitnum2bit_loop
        return
 
-;----------
-common_init
-       call    bitnum2bit_init
-       call    points_init
-       return
+;======================================================================
+; MASTER/SLAVE deviations
 
  include final.inc
index b4da5eed0b2f35e402c99f2133710dc5f97266b6..0679b030ae2e90000adc89ba808d8b0f31697d97 100644 (file)
@@ -1,2 +1,3 @@
  extern read_pic_no
- extern init_read_idlocs
+ extern idlocs_init
+ extern bitnum2bit_init
index e1888f2540d66dacf8af2a41e249c25998ac0b21..256494dfb2a8e57f072b9a52c84121ea51283abc 100644 (file)
@@ -32,6 +32,7 @@ X     test-sofar:ch           ; bad character received from host
 
 # Unimplemented things
 UP             ; unimplemented point timer setting
+UL             ; unimplemented master loopback read
 
 ZM     i2clib:st,:sspstat,:sspcon1,:sspcon2 ; for testing
 ZS     i2clib:st,:sspstat,:sspcon1,:st_orig ; for testing
@@ -57,3 +58,6 @@ RS    FSR0L                           ; POLARITY message too short
 RL     FSR0L                           ; POLARITY message too long
 
 PB     points:pointmsg                 ; Firing point when already busy
+PI     points:pointmsg,T3CON           ; Unexpected Timer 3 interrupt
+PU     points:pointmsg                 ; Firing nonexistent point
+PF     points:t                        ; Flash mentions point not on board
index 51b203cdc5e18ad94ee170a8d88798f042bccb9c..79a7737cf9466a2ba4570a97c209a70c45c00369 100644 (file)
@@ -5,18 +5,26 @@
 ;      Timer 3         Off             On, counting up
 ;      pointmsg        undefined       message from master
 
+ include common.inc
+
  udata_acs
 pointmsg               res     1
 
- udata 0x300
-ptix2latbit    res     maxpoint * 2    ; bit and LAT*
+ptix2bitlat equ 0x300
+ udata ptix2bitlat
+ res maxpoint * 2      ; bit and LAT*
+                       ; for unused point, 0x00 and 0x00
 
  code
 
 pt_timer13_prescale equ 0
 pt_timer13_inithigh equ 0
 
-;----------
+;======================================================================
+; LOCAL POINTS
+; Actually doing points (on slave, or master's own)
+
+;--------------------
 point_timer_init
        mov_lw  (1<<RD16) | (1<<T3ECCP1) | pt_timer13_prescale ; Fcy; !TMR3ON
        mov_wf  T3CON
@@ -27,7 +35,7 @@ point_timer_init
        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
@@ -38,200 +46,197 @@ point_do_here
        mov_wf  pointmsg        ; pointmsg = SS zz zz pp  pp pp pp pp
        rcall   point_set_pin
 
-       set_f   TMR3L
+       set_f   TMR3L           ; also copies TMR3H into actual timer register
        bs_f    T3CON, TMR3ON
        panic   morse_UP
        return
 
+;----------------------------------------
+points_interrupt
+; Low priority; checks for, and clears, any relevant interrupt.
+; Then returns.
+       bt_f_if0 PIR2, TMR3IF
+       return
+       ; OK, we're done:
+
+       bt_f_if0 T3CON, TMR3ON
+       bra     point_spurious_intr
+
+       rcall   point_set_pin
+       mask_int_high
+       bc_f    T3CON, TMR3ON
+       bc_f    PIR2, TMR3IF
+       unmask_int_high
+
+       mov_lw  b'00100000'
+       goto    message_for_master
+
 ;----------
+point_spurious_intr
+       panic   morse_PI
+
+;--------------------
 ; 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_lw  ptix2bitlat >> 8
        mov_wf  FSR0H           ; FSR0H -> table
-       rl_   pointmsg        ; W = point addr, Z iff pt0
-       mov_wf  FSR0L           ; FSR0 -> &LAT*   [Z still iff pt0]
+       rl_fw   pointmsg        ; W = point addr, Z iff pt0
+       mov_wf  FSR0L           ; FSR0 -> &bit   [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*
+       bra_z   point_nonexistent
        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_set_pin_hl
+       tst_f_ifnz FSR0L        ; err, did we just write to 0xf00 ?
+       return                  ; no; good.
+       ; oops, we did:
+ if 0xf00 == RXF0SIDH
+       ; This is actually OK; it's a `receive acceptance filter'
+       ; for the CAN controller, writing to which has no side
+       ; effects.  And anyway the register starts at xxxx xxxx
+       ; so if we don't care about CAN that's fine, and we're about
+       ; to panic, of course.
+       ; See DS p212 (register summary), p228 (description),
+       ; p48 (location, 0xf00), p53 (POR value).
+ else
+  error "must check what 0xf00 is on this processor"
+ endif
+point_nonexistent
+       panic   morse_PU
 
 ;----------
 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
-;              byte 0
-;                      pic number for this point
-;                      ff indicates unassigned point number
-;              byte 1
-;                      index number for this point on relevant pic
-;              byte 2
-;                      address of relevant LAT*
-;              byte 3
-;                      bit in LAT (eg 0x40 for bit 6)
-;              bytes 1-3 are not defined if number is not assigned
-; address of data_points is guaranteed to be multiple of 256
 
+;      We do this in two stages.
+;      Firstly, we scan the bitmap for this pic, setting
+;       ptix2bitlat to 0xff,0x00 for used points and 0x00,0x00
+;       to unused ones.
+;      Secondly, we scan the bkptix2portnumbitnum, adjusting
+;       ptix2bitlat to have actually correct data.
+;      Doing it like this avoids having to constantly recompute
+;       individual TBLPTR*'s.
 
+       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
 
- udata_acs
-
- udata 0x300
-our_point_table_ctln2  equ     6
-our_point_table_count  equ     (1 << our_point_table_ctln2)
-our_point_table                res     our_point_table_count * 2
-;      2 bytes for each point, indexed by index number on this pic
-;              1st byte:       LAT* address, or 0 for unassigned
-;              2nd byte:       bit in LAT
-
- code
-
-;----------------------------------------------------------------------
-points_init
-; Clears TRIS* bits for all points and sets the
-; pin to `not triggering'
-
-       mov_lfsr our_point_table, 0     ; FSR0 points to point lookup table
-       mov_lw  our_point_table_count * 2
-
-points_init_clear_loop
-       clr_f   POSTINC1
-       dec_w_ifnz
-       bra     points_init_clear_loop
-       ; otherwise, done:
-
-                                       ; During this loop:
-       clr_wf  TBLPTRU
-       mov_lw  (data_points >> 8)
+       mov_lw  picno2ptmap >> 8
+       addc_wfw PRODH
        mov_wf  TBLPTRH
-       clr_f   TBLPTRL                 ; TBLPTR* -> to point data
-
-       set_f   FSR1H                   ; FSR1 -> LAT*, TRIS*
-
-       mov_lfsr our_point_table, 0     ; FSR0 -> point lookup table
-
-points_init_loop
-       mov_lw  (data_points_end >> 8)
-       cmp_fw_ifge TBLPTRH
-       bra     points_init_loop_exit
 
-       tblrd   *+
-       dw      0xffff                  ; TABLAT = pic number
+       clr_f   TBLPTRU         ; TBLPTR* -> our point data
+
+       mov_lw  maxpoint/8
+       mov_wf  t               ; t = byte counter
+;...
+points_init_byte_loop
+       mov_lw  8               ; W = bit counter
+       clr_f   INDF0           ; bit[current] := 0
+       tblrd_postinc_fixup     ; TABLAT = bitmap data being processed
+;...
+points_init_bit_loop
+       rrc_f   TABLAT
+       bra_nc  points_init_ifnot_point
+points_init_if_point
+       set_f   POSTINC0        ; bit[current] := 0xff, FSR0 -> LAT*[current]
+points_init_ifnot_point
+       clr_f   POSTINC0        ; LAT*[current] := 0xff, FSR0 -> bit[current+1]
 
-       mov_fw  picno
-       cmp_fw_ifne TABLAT
-       bra     points_init_loop_ifnot_ours
-
-       tblrd   *+
-       dw      0xffff                  ; TABLAT = index number
-
-       mov_lw  0xff << our_point_table_ctln2
-       and_wfw TABLAT
-       bra_nz  bad_pointtable_index
-
-       rl_fw   TABLAT
-       mov_wf  FSR0L                   ; FSR0 -> our table entry
-
-       tst_f_ifnz INDF0
-       bra_nz  bad_pointtable_clash
-
-       tblrd   *+
-       dw      0xffff                  ; TABLAT = LAT* address
-
-       mov_fw  TABLAT
-       mov_wf  POSTINC0                ; store LAT* address; FSR0 -> bit
-       mov_wf  FSR1L                   ; FSR1 -> LAT*
+       dec_w_ifnz
+       bra     points_init_bit_loop
+       dec_f_ifnz t
+       bra     points_init_byte_loop
+;... end of loop:
+
+;      We've scanned for points used on this board;
+;      now find the actual pins.
+
+       mov_lfsr ptix2bitlat, 0 ; FSR0 -> this bit and LAT*
+       mov_lfsr bitnum2bit+7, 1 ; FSR1 -> bitnum2bit+7
+       set_f   FSR2            ; FSR2 -> some SFR, will point to LAT/TRIS
+
+       mov_lw  bkptix2portnumbitnum & 0xff
+       bt_f_if0 idloc1,idloc1_boarddet
+       add_lw  maxpoint
+       mov_wf  TBLPTRL
+
+       mov_lw  bkptix2portnumbitnum >> 8
+       mov_wf  TBLPTRH         ; TBLPTR* -> point port/bit data
+
+       mov_lw  maxpoint
+       mov_wf  t               ; t = loop counter
+;...
+points_init_portbit_loop
+       tblrd_postinc_fixup     ; TABLAT = portnum4 || bitnum4
+
+       bt_f_if0 POSTINC0,7     ; zero?, FSR0 -> LAT*[this]
+       bra     points_init_portbit_endif_used
+;...
+points_init_portbit_if_used
+       mov_wf  TABLAT
+       bra_n   point_initing_bad_point
        
-       tblrd   *+
-       dw      0xffff                  ; TABLAT = bit value
-
-       mov_fw  TABLAT
-       mov_wf  INDF0                   ; store bit value
-
-       com_w                           ; W = ~bit
-       and_wff INDF1                   ; clear the LAT* bit (point inactive)
-       pin_vh  pall_pt0reverse ; except pt0 which is backwards
-
+       and_wff FSR1L           ; FSR1 -> bit value for bit
+
+       swap_fw TABLAT          ; W = bitnum4 || portnum4
+       and_lw  0x0f            ; W = portnum4
+       add_lw  LATA & 0xff     ; W = LAT*
+       mov_wf  POSTDEC0        ; LAT*[this] := LAT, FSR0 -> bit[this]
+       mov_wf  FSR2L           ; FSR2 -> LAT*
+
+       mov_wf  INDF1           ; W = bit
+       mov_fw  POSTINC0        ; bit[this] = bit, FSR0 -> LAT*[this]
+       com_w                   ; W = ~bit
+       and_wff INDF2           ; LAT* &= ~bit, ie pin set to L (still Z)
+       pin_vh  pall_pt0reverse ; but pt0 pin is backwards, set to H
+                               ;  (still Z, unless we've done this already)
        mov_lw  TRISA-LATA
-       add_wf  FSR1L                   ; FSR1 -> TRIS*
-       com_fw  TABLAT                  ; W = ~bit
-       and_wff INDF1                   ; make the pin an output
-
-       bra     points_init_loop
-
-points_init_loop_ifnot_ours
-       tblrd   *+
-       tblrd   *+
-       tblrd   *+
-       bra     points_init_loop
-
+       add_wff FSR2L           ; FSR2 -> TRIS*
+       com_fw  INDF1           ; W = ~bit
+       and_wff INDF2           ; TRIS* &= ~bit, ie pin set to not Z
 
-       
+       set_f   FSR1L           ; FSR1 -> bitnum2bit+7, again
+points_init_portbit_endif_used
+       ; so now we move on to the next one
+       mov_fw  POSTINC0        ; FSR0 -> bit[this+1]
+       dec_f_ifnz t
+       bra     points_init_portbit_loop
 
-       clr_f   INDF1
+       return
 
-       
+;----------
+point_initing_bad_point
+       panic   morse_PF
 
 ;----------------------------------------------------------------------
-cdu_init
+;cdu_init
 ; For master pic only.  Sorts out the CDU's pin.
 
+ include final.inc
diff --git a/detpic/points.fin b/detpic/points.fin
new file mode 100644 (file)
index 0000000..51abd71
--- /dev/null
@@ -0,0 +1,3 @@
+ extern points_interrupt
+ extern points_init
+ extern point_do_here
index ecfcee3ffc1cc33a0baf0defe9d36e3d9bf4f76f..cad81431e6ebd6ae68445490b443a30739a7d5e7 100644 (file)
@@ -15,7 +15,8 @@
 slave
        mov_fw  picno
        call    i2cs_init
-       call    common_init
+       call    bitnum2bit_init
+       call    points_init
        call    det_slave_init
 
        mov_lw  (1<<GIEH) | (1<<GIEL)
@@ -37,6 +38,8 @@ i2csu_write_done
 
 ;----------
 slave_interrupt_low
-       panic   morse_IP
+       enter_interrupt_low
+       call    points_interrupt
+       return_interrupt_low
 
  include final.inc
index f2e722c75fac21f807ff58dbe19c0454fcce48c5..18ffa1af784b6fb569630ca50579f2711142d680 100644 (file)
@@ -80,9 +80,6 @@ delay_countfast               res     1
 delay_countmedium      res     1
 delay_countslow                res     1
 
-save_w         res     1
-save_status    res     1
-
        code
 
 ;----------
@@ -90,7 +87,7 @@ vector_reset
        clr_f   INTCON
        bs_f    RCON, IPEN      ; interrupt priorities
 
-       call    init_read_idlocs
+       call    idlocs_init
 
        tst_f_ifnz picno
        goto    slave
@@ -98,14 +95,10 @@ vector_reset
 
 ;----------
 master_interrupt_low
-       mov_ff  STATUS,save_status
-       mov_wf  save_w
-       ; we assume that none of the ISRs use BSR
+       enter_interrupt_low
        call    i2cm_interrupt
        call    serial_interrupt
-       mov_fw  save_w
-       mov_ff  save_status,STATUS
-       retfie
+       return_interrupt_low
 
 ;----------
 master_interrupt_high
@@ -143,6 +136,10 @@ m_infinite
        call    led_green
        bra     m_infinite
 
+;----------
+loopback_read_byte
+       panic   morse_UL
+
 ;----------
 serialu_read_char
 ;      W       character read          any
index f9f16ce2b84e9f111609bcafd526059377edbd4e..15d7728ebb718e4b18b66f5dd706f2688ebe9413 100644 (file)
@@ -8,6 +8,9 @@ idloc1_boarddet equ     6
 t              res     1       ; general temporary
 outmsg_end     res     1       ; first empty byte in outbuf
 
+isr_low_save_w         res     1
+isr_low_save_status    res     1
+
 outbuf_section udata 0x200
 outbuf_szln2   equ     7
 outbuf_size    equ     (1<<outbuf_szln2)
index 742e6b0940a4fad5cd918059a98d1dda0d70c5b2..c16364f98010f6d4d83d736f41dc6b158ca4fa7b 100644 (file)
@@ -153,6 +153,6 @@ clean:
 .PRECIOUS:     $(OPRINTS)
 .PRECIOUS:     %.segcmap %.segcmapreq %.segenco.ppm %.d4 %.neato %.raw.neato
 .PRECIOUS:     %.redactgraph %.redacted.forsafety %.redacted.neato
-.PRECIOUS:     %.layout-data.c
+.PRECIOUS:     %.layout-data.c %.pin-info
 
 include $(wildcard *.d)