chiark / gitweb /
Finished faults and power in energy.asm (but not yet really compiled); Fault interrup...
authorian <ian>
Wed, 28 Dec 2005 02:57:59 +0000 (02:57 +0000)
committerian <ian>
Wed, 28 Dec 2005 02:57:59 +0000 (02:57 +0000)
detpic/common.inc
detpic/energy.asm
detpic/energy.fin
detpic/nmra-stream.asm
detpic/points.asm
detpic/program.asm
detpic/serout.asm
detpic/tick.asm

index 3d5cedd4481b0ed064c6af98ccd5c4033d236483..b512906a0e13a8c3950080fe83961a3c340805f3 100644 (file)
@@ -35,7 +35,11 @@ tickdiv_us equ tick_us * tickdiv
 ;   PCLATH             Low ISR                 Not used
 ;   t_dolocal          Low ISR                 High ISR
 ;   FSR1               Low ISR                 High ISR (detect[1])
-;   FSR2               High ISR (nmra)         High ISR (detect[1])
+;   FSR2               High ISR (nmra[1])      High ISR (detect[1])
+;
+;   Main loop          detection scan          detection scan
+;   High ISR           NMRA output             I2C service
+;   Low ISRs           everything else         everything else
 ;
 ; Trashed      May be trashed by any routine anywhere.  Saved
 ;              during every ISR entry/exit.
@@ -275,6 +279,10 @@ pin_nz     macro   pinspec
        bc_f    TRISA + (TRISB-TRISA)*((pinspec-0xa) & 15), pinspec >> 4
        endm
 
+pin_znz        macro   pinspec
+       btg_f   TRISA + (TRISB-TRISA)*((pinspec-0xa) & 15), pinspec >> 4
+       endm
+
 pin_vh macro   pinspec
        bs_f    LATA + (LATB-LATA)*((pinspec-0xa) & 15), pinspec >> 4
        endm
index dd82672b790a9c41f0dc0f630a2240da1fa596c5..78c2ea3918b63fc920bc890220eac07fe7696c00 100644 (file)
@@ -3,21 +3,29 @@
 
  include common.inc
 
-settling_timeout equ 10000 ; us
+settling_timeout       equ      10000 ; us
+
+stop_timeout           equ     500000 ; us
+stopflash_timeout      equ      25000 ; us
+retry_timeout          equ      50000 ; us
+persist_timeout                equ      90000 ; us
 
  udata_acs
-settling       res     1
+settling       res     1 ; all counters are 0 if stopped
+stop_wait      res     1 ;  or otherwise count down
+retry_wait     res     1
 
  code
 
 ;======================================================================
+;
 ; POLARISING/SETTLING:
 ;
 ;              NMRA            flag_p. settling        Booster PWM
 ;
-; Normal       running         0       0x00            mark
-; Polarising   paused          1       0x00            space
-; Settling     paused          1       >0, count down  space
+; Normal       running         0       stopped         mark
+; Polarising   paused          1       stopped         space
+; Settling     paused          1       running         space
 ;
 ; NMRA is paused by disabling timer 0 intr; when we restart,
 ; we restart the current message.
@@ -32,7 +40,7 @@ power_polarising_init
 ;--------------------
 power_polarising_begin
        pin_l   p0_booster_pwm
-       bc_f    INTCON, TMR0IE
+       bc_f    INTCON, TMR0IE ; disables NMRA interrupt
        bs_f    flags, flags_polarising
        clr_f   settling
        return
@@ -54,53 +62,155 @@ power_polarising_tick
        ; settle timeout complete:
 
        bc_f    flags, flags_polarising
-       intr_mask
        call    nmra_restartmessage
-       intr_unmask
+       bs_f    INTCON, TMR0IE ; reenables NMRA interrupt
        goto    i2c_consider_restartread
 
 ;======================================================================
 ;
 ; FAULTS AND POWER:
 ;
-;              Shutdown CDU    Fault timeout   User Fault      Next states
-; Off          shutdown off    stopped         off             On*, Fault+
-; On           power-up on     stopped         off             Fault, Off*
-; Fault                shutdown off    500ms           1/2x50ms        Retry
-; Retry                power-up off    50ms            on              Persists, Off
-; Persists     shutdown off    50ms            on              Retry
+;              Shutdown  CDU   Timeout User Fault      Next states
+;
+; Off          shutdown  off   none    off             *On (or +Fault)
+; On           power-up  on    none    off             Fault, or *Off
+; Stopping     shutdown  off   500ms   50% 1/50ms      ->Retry
+; Retry                power-up  off   50ms    off             ->Off, or Persists
+; Persists     shutdown  off   90ms    on              ->Retry
 ;                                                      * = when host instructs
 ;                                                      + = lost race, only
+;                                                      -> = after timeout
+;
+;              shutdown LAT    stop_wait       retry_wait
+;
+; Off          H (shutdown)    stopped         stopped
+; On           L (power-up)    stopped         stopped
+; Stopping     H (shutdown)    before Retry    for LED flash
+; Retry                L (power-up)    stopped         before Off
+; Persists     H (shutdown)    stopped         before retry
+;
+;                              (uses tickdiv)  (uses tick)
 
-command_power
-
-
-;  C           1 iff command is ON             undefined
- tell on or off
+;--------------------
+power_fault_init
+       bs_f    INTCON2, INTEDG1 ; rising edge
+       bc_f    INTCON3, INT1IP
+       bc_f    INTCON3, INT1IF
+       bs_f    INTCON3, INT1IE
+       clr_f   stop_wait
+       clr_f   retry_wait
+       pin_h   booster_shutdown
+       pin_vl  p0_booster_userfault
+       pin_z   p0_booster_userfault
+       ; now we are Off
+       return
 
-on on:
- start nmra with empty buffers
- turn booster on
- turn cdu on
+;--------------------
+command_power
+       bra_nc  command_power_off
+       ; command is ON:
+
+; Off -> On; noop in other states
+       pinlat_ifh p0_booster_shutdown
+       return  ; On or Retry
+       ; might be Off, Stopping or Persists:
+
+       tst_f_ifnz retry_wait
+       return  ; that deals with Stopping or Persists
+       ; must be Off:
+
+       pin_l   p0_booster_shutdown
+       goto    cdu_on
+
+;----------
+command_power_off
+; On -> Off; noop in other states
+       pinlat_ifl p0_booster_shutdown
+       return  ; Off, Stopping or Persists
+       ; might be On or Retry:
+
+       tst_f_ifnz retry_wait
+       return  ; that deals with Retry
+       ; must be On:
+power_off_now
+       pin_h   p0_booster_shutdown
+       goto    cdu_off
 
+;--------------------
+power_fault_intrl
+       bt_f_if1 INTCON3, INT1IF
+       return
+       ; we have a fault:
 
+       tst_f_ifz retry_wait
+       bra     power_stop ; we were Off or On, goto Stopping
+       ; must be Stopping, Retry or Persists:
 
+       tst_f_ifnz stop_wait
+       bra     power_stop ; we were already Stopping; restart timer
+       ; might be Retry or Persists, goto Persists (restarting any timer):
 
-       panic   morse_UEC
+       rcall   power_off_now
+       mov_lw  persist_timeout / tick_us
+       mov_wf  retry_wait
+       return
 
-;power_on ???
-; from cebpic/nmra-stream.asm's setup
-       bcf     PORTB,2,0       ; booster shutdown L
-       bcf     TRISB,2,0       ; booster shutdown not-Z
+;--------------------
+power_fault_tick
+       tst_f_ifnz retry_wait
+       dec_f_ifnz retry_wait
+       return
+       ; retry_wait was running but has just reached zero;
+       ; we were in Stopping, Retry or Persists:
+
+       tst_f_ifnz stop_wait
+       bra     power_stop_doflash ; that was Stopping, just flash the LED
+       ; must be Retry or Persists:
+
+       pinlat_ifl p0_booster_shutdown
+       bra     power_retry ; we were in Persists, now we can try again
+       ; we were in Retry but it didn't work:
+; go to Persists:
+       pin_h   p0_booster_shutdown
+       mov_lw  persist_timeout / tickdiv_us
+       mov_wf  retry_wait
+       pin_nz  p0_booster_userfault
+       return
 
-       bcf     PORTB,0,0       ; user fault L or Z
+;----------
+power_stop
+       rcall   power_off_now
+       mov_lw  stop_timeout / tickdiv_us
+       mov_wf  stop_wait
+       pin_z   p0_booster_userfault
+       mov_lw  b'00000111'
+       call    serial_addbyte
+power_stop_doflash
+       pin_znz p0_booster_userfault
+       mov_lw  stopflash_timeout / tickdiv_us
+       mov_wf  retry_wait
+       return
 
- pause nmra
-       panic   morse_UER
+;--------------------
+power_fault_tickdiv
+       tst_f_ifnz stop_wait
+       dec_f_ifnz stop_wait
+       return
+       ; stop_wait was running but has just reached zero;
+       ; we were in Stopping, now we can Retry:
+power_retry
+       mov_lw  retry_timeout / tickdiv_us
+       mov_wf  retry_wait
+       pin_l   p0_booster_shutdown
+       pin_z   p0_booster_userfault
+       return
 
+;--------------------
 power_panichook
-       panic   morse_UEP
+       pin_h   p0_booster_shutdown
+       pin_l   p0_booster_pwm
+       pin_z   p0_booster_userfault
+       return
 
 ;======================================================================
  include final.inc
index 5fd3c0d00c94e9df32127e2f27dddc3980449caf..3a1c0207cba9e1e10c09208dba1d9ce87fd9144c 100644 (file)
@@ -1,3 +1,9 @@
  extern command_power
  extern power_polarising
+ extern power_polarising_init
+ extern power_polarising_tick
+ extern power_fault_init
+ extern power_fault_intrl
+ extern power_fault_tick
+ extern power_fault_tickdiv
  extern power_panichook
index e82779144c8fe9740dd35483ec97e4c83a36292f..9688c35209c88b8f846a91866527d886ebcc5178 100644 (file)
@@ -287,6 +287,10 @@ not_nmra_message
 ;****************************************************************************
 
 near_interrupt_high code
+
+master_interrupt_high_notnmra
+       panic   morse_IH
+
 master_interrupt_high
        bt_f_if0 INTCON,TMR0IF  ; check whether timer0 interrupt set
        bra     master_interrupt_high_notnmra
index 0e1067612ff7a43fb73e5f98a05416ff2f866849..4ca39087fda7a7cac44d455d29e08a5a715ffa00 100644 (file)
@@ -353,7 +353,7 @@ cdu_init
        clr_f   pointmsg
 ;...
 ;-----
-cdu_offp
+cdu_off
 cdu_panichook
        pin_l   p0_cdu_enable
 ;...
index 73b1d1277898ba6fc869b48d5d87fa71ae60217f..d51fa5387723bf2d93c690c6922c440f290fa263 100644 (file)
@@ -82,6 +82,7 @@ master_init
        call    mascan_init
        call    tick_init
        call    power_polarising_init
+       call    power_fault_init
        return
 
 ;----------------------------------------
@@ -89,16 +90,12 @@ master_interrupt_low
        enter_interrupt_low
        call    tick_intrl
        call    nmra_serialrx_intrl
+       call    power_fault_intrl
        call    serialtx_intrl
        call    points_local_intrl
        call    i2cm_intrl
        panic   morse_IL
 
-;----------
-near_interrupt_high code
-master_interrupt_high_notnmra
-       panic   morse_IH
-
 ;----------------------------------------------------------------------
 serialrx_table_section code    0x2000
 
index 6bf7cdebce42c9b535156bd48bf654f50c2de50a..b7925bc1eb401866dcd4e46bfea7d82bf48e384b 100644 (file)
@@ -100,8 +100,8 @@ tx_fcdisable
 
 ;----------------------------------------------------------------------
 serialtxfc_init
-       bs_f    INTCON, RBIE
        bc_f    INTCON2, RBIP
+       bs_f    INTCON, RBIE
        rcall   portb_read
        return
 
index 9ef474b50b90ac3c323596d77097ca860010d588..f2ba9e6771926ba264fd1e4c098757f9da52ca76 100644 (file)
@@ -34,8 +34,8 @@ tick_intrl
        bc_f    PIR1, TMR2IF
 
        ; add calls to <foo>_tick here:
-       call    power_polarising_tick
        call    power_fault_tick
+       call    power_polarising_tick
        ; end of list of calls to <foo>_tick
 
        dec_f_ifz tickdivcount
@@ -46,6 +46,7 @@ tick_intrl
 ;----------------------------------------
 tickdiv_do
        ; add calls to <foo>_tickdiv here:
+       call    power_fault_tickdiv
        call    cdu_tickdiv
        ; end of list of calls to <foo>_tickdiv