chiark / gitweb /
new tickdiv for two speeds of tick; working on energy - polarising finished but not...
authorian <ian>
Tue, 27 Dec 2005 17:15:35 +0000 (17:15 +0000)
committerian <ian>
Tue, 27 Dec 2005 17:15:35 +0000 (17:15 +0000)
12 files changed:
detpic/common.inc
detpic/energy.asm
detpic/make-clocks
detpic/mascan.asm
detpic/nmra-stream.asm
detpic/points.asm
detpic/points.fin
detpic/program.asm
detpic/program.clocks
detpic/reverse.asm
detpic/tick.asm
detpic/variables.asm

index a589da6aa78e2be6160a07aa2698464407e28a82..a41f79178ba6d2f82cc933c514ab0acabd9e2af5 100644 (file)
@@ -16,6 +16,9 @@
        include         program+clocks.inc
        include         i2clib.incm
 
+tickdiv equ 16
+tickdiv_us equ tick_us * tickdiv
+
 ;----------------------------------------------------------------------
 ; Common conventions for function register notation:
 
@@ -75,7 +78,7 @@
 ;
 ;                      Master                  Slave
 ;  Timer 0             nmra                    Disabled
-;  Timer 2             tick: 10ms, int. low    -
+;  Timer 2             tick, int. low          -
 ;  Timer 1             -                       -
 ;  CCP1                        -                       -
 ;  Timer 3             point fire timer        point fire timer
index dbdebd98432256ca20d6bc29131f7ff3e7fcb435..dd82672b790a9c41f0dc0f630a2240da1fa596c5 100644 (file)
@@ -2,11 +2,90 @@
 ; TRACK POWER AND SHORT CIRCUIT
 
  include common.inc
+
+settling_timeout equ 10000 ; us
+
+ udata_acs
+settling       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
+;
+; NMRA is paused by disabling timer 0 intr; when we restart,
+; we restart the current message.
+;
+;----------------------------------------------------------------------
+
+;--------------------
+power_polarising_init
+       clr_f   settling
+       return
+
+;--------------------
+power_polarising_begin
+       pin_l   p0_booster_pwm
+       bc_f    INTCON, TMR0IE
+       bs_f    flags, flags_polarising
+       clr_f   settling
+       return
+
+;--------------------
+power_polarising_settling
+; idempotent
+       tst_f_ifnz settling
+       return
+       mov_lw  settling_timeout / tick_us
+       mov_wf  settling
+       return
+
+;--------------------
+power_polarising_tick
+       tst_f_ifnz settling
+       dec_f_ifnz settling ; decrement if not zero
+       return ; return if not dec'd, or if decrement didn't make zero
+       ; settle timeout complete:
+
+       bc_f    flags, flags_polarising
+       intr_mask
+       call    nmra_restartmessage
+       intr_unmask
+       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
+;                                                      * = when host instructs
+;                                                      + = lost race, only
+
 command_power
+
+
 ;  C           1 iff command is ON             undefined
+ tell on or off
+
+on on:
+ start nmra with empty buffers
+ turn booster on
+ turn cdu on
+
+
+
+
        panic   morse_UEC
 
 ;power_on ???
@@ -16,7 +95,8 @@ command_power
 
        bcf     PORTB,0,0       ; user fault L or Z
 
-power_polarising
+ pause nmra
        panic   morse_UER
 
 power_panichook
index 9d0bc7d620ccaba8fee251d143ff38b69e6c7168..b333e2aab6367d97aee52969732cd2470639df99 100755 (executable)
@@ -101,6 +101,16 @@ sub do_T0ov16 { do_T0ov(16); }
 sub do_T1ov { do_T13ov(1); }
 sub do_T3ov { do_T13ov(3); }
 
+sub provide_interval ($$$$) {
+    my ($iname, $thisval, $unitname, $unitval) = @_;
+    my ($inthisunit, $inthisunitint);
+    $inthisunit= $thisval / $unitval;
+    return if $inthisunit > 256000000.0;
+    $inthisunitint= sprintf "%d", $inthisunit;
+    return if abs(($inthisunitint - $inthisunit) / $inthisunit) > 0.001;
+    p("${iname}_${unitname} equ $inthisunitint\n");
+}
+
 sub doline () {
     my ($orgname,$mswant,$specd,$unit,$how);
     chomp;
@@ -116,13 +126,16 @@ sub doline () {
     if ($unit =~ m/u/) { $interval *= 1.e-6; }
     if ($unit =~ m/n/) { $interval *= 1.e-9; }
     if ($unit =~ s/Hz//) { $interval = 1.0 / $interval; }
+    p(";========== $name ($specd, $interval) ==========\n");
+    provide_interval($orgname, $interval, 'us', 1.e-6);
+    provide_interval($orgname, $interval, 'ms', 1.e-3);
+    provide_interval($orgname, $interval, 's', 1.0);
     foreach $ms (qw(m s)) {
        next unless $mswant =~ m/$ms/i;
        $msclock= "${ms}clock";
        die $msclock unless exists $defs{$msclock};
        $msclock= $defs{$msclock};
        $name = $orgname.'_'.($ms eq 'm' ? 'master' : 'slave');
-       p(";---------- $name ($specd, $interval) ----------\n");
        &{ "do_$how" };
     }
 }
index 32ea43d110ec7ca78444be9c18aec570ac205eac..d59ffdd8b9b9d050f72de019c7ee45b63afd9537 100644 (file)
@@ -206,6 +206,10 @@ i2c_arrange_something
        bra     arrange_write
 nextslave_nowrite
        ; no writing needed, we consider reading:
+       bt_f_if1 flags, flags_polarising
+       return  ; do not scan while booster PWM is off while polarising
+               ; to avoid all trains disappearing and reappearing
+
        neg_fw  outmsg_begin
        add_wfw outmsg_end
        and_lw  outbuf_size - 1
index 259c48435bd1043d61755613194fc488e3261fb7..e82779144c8fe9740dd35483ec97e4c83a36292f 100644 (file)
@@ -172,6 +172,13 @@ nmra_init
        bs_fa   nmractrl,nextaction
        bs_fa   nmractrl,transmitbit
 
+nmra_restartmessage    ; Entrypoint from power_polarising_tick, at end
+                       ;  of settle time.  Goes back to beginning of
+                       ;  current message (if any) and retransmits it.
+                       ;  Also, enables booster PWM and Timer 0 interrupts.
+       mov_lw  0x0f
+       and_wff totrack
+
 ; initialise totrackbit bitmask
        mov_lw  0x80
        mov_wfa totrackbit      ; make bit mask be 1000 0000
index 62527b03e624d58955092e7a727911b983194bec..d2103fc7f1d0b9686818447479cf6b6b919b228b 100644 (file)
@@ -359,7 +359,7 @@ cdu_panichook
 ;...
 ;-----
 cdu_discharged
-       mov_lw  cdu_timeout / 10 ; time in ms, converted to 10ms ticks
+       mov_lw  (cdu_timeout * 1000) / tickdiv_us + 1
        mov_wf  cducharging
        return
 
@@ -369,7 +369,7 @@ cdu_on
        return
 
 ;--------------------
-cdu_tick
+cdu_tickdiv
        bt_f_if0 LATB, p0_cdu_enable >> 4
        return
 
index 33ea40c1005a7fe4620e1d9dc0804be834f23b26..350ea5062fb8e27837b3bd861a4066f0709d2241 100644 (file)
@@ -7,7 +7,7 @@
  extern points_getwritebyte
  extern got_pointed
  extern cdu_init
- extern cdu_tick
+ extern cdu_tickdiv
  extern cdu_on
  extern cdu_off
  extern cdu_panichook
index b11ed6f677c29f47efe621d5182db0ce8989e4db..73b1d1277898ba6fc869b48d5d87fa71ae60217f 100644 (file)
@@ -81,6 +81,7 @@ master_init
        call    serialtxfc_init
        call    mascan_init
        call    tick_init
+       call    power_polarising_init
        return
 
 ;----------------------------------------
index 4e57f2a7af1b1a5bcf91092658f8c67726912802..3dff1624c8cc223ebddb432f3b6d53743733d157 100644 (file)
@@ -10,4 +10,4 @@
 
 #morse         MS      T0ov16          66ms
 points         MS      T3ov            10ms
-tick           MS      T2period        10ms
+tick           MS      T2period        1ms
index 4416c107e985105d9ef6a91fa8e324ab67bbba0d..8dde2f4eb0bdbb9a765667061b60e072be5fecf4 100644 (file)
@@ -162,7 +162,7 @@ board_next_none
 ; now we're exiting from the loop in when_reverse_message_found
        pop      ; that disposes of the call to `board'
 
-       call    power_polarising
+       call    power_polarising_begin
 
        mov_fw  polarity_cmds ; there's always a board 0, us
        call    polarity_local_do
@@ -227,10 +227,15 @@ polarity_needwrite_loop
                                ; W = 0000000? C=0  no existing command
                                ; W = 1000000? C=0  sentinel
        bra_nn  polarity_needwrite_loop
-       bt_f_if0 STATUS, C
-       return ; we found the sentinel
-       ; we found a pic to tell to polarise:
+       bt_f_if1 STATUS, C
+       bra     polarity_needwrite_found
+       ; we found the sentinel:
 
+       bt_f_if0 flags, flags_polarising
+       return
+       goto    power_polarising_alldone
+
+polarity_needwrite_found
        mov_fw  FSR1L
        add_lw  -polarity_cmds
        pop
index 9c35fb073c53f0f6108f8ac7bde31cb845221bcc..9ef474b50b90ac3c323596d77097ca860010d588 100644 (file)
@@ -2,11 +2,14 @@
 ; TICK - REGULAR 10MS TIMER INTERRUPT
 ;
 ; after tick_init, and after interrupts enabled,
-; we call <foo>_tick every 10ms.
+; we call <foo>_tick every 1ms and <foo>_tickdiv every <tickdiv>ms.
 
  include common.inc
- code
 
+udata_acs
+tickdiv_count  res     1
+
+ code
 ;----------------------------------------
 tick_init
 ;  Timer 2             any                     used for tick
@@ -18,6 +21,8 @@ tick_init
        bc_f    IPR1, TMR2IP ; low priority
        bs_f    IPR1, TMR2IE ; enable interrupts
        bs_f    T2CON, TMR2ON ; enable timer
+       mov_lw  tickdiv
+       mov_wf  tickdiv_count
        return
 
 ;----------------------------------------
@@ -29,9 +34,23 @@ tick_intrl
        bc_f    PIR1, TMR2IF
 
        ; add calls to <foo>_tick here:
-       call    cdu_tick
+       call    power_polarising_tick
+       call    power_fault_tick
        ; end of list of calls to <foo>_tick
 
+       dec_f_ifz tickdivcount
+       bra     tickdiv_do
+
+       intrl_handled_nostack
+
+;----------------------------------------
+tickdiv_do
+       ; add calls to <foo>_tickdiv here:
+       call    cdu_tickdiv
+       ; end of list of calls to <foo>_tickdiv
+
+       mov_lw  tickdiv
+       mov_wf  tickdiv_count
        intrl_handled_nostack
 
 ;----------------------------------------------------------------------
index 090d4791d3e140619d33fff7d0d0c870ccf43d40..65df513c81476298f0f52d3922321e1020b0d570 100644 (file)
@@ -6,11 +6,12 @@
 picno          res     1       ; from first idlocs byte
 
 idloc1         res     1       ; from 2nd idlocs byte; bit 7 is master:
-idloc1_master  equ     7
-idloc1_boarddet        equ     6
+idloc1_master          equ 7
+idloc1_boarddet                equ 6
 
 acknmra                res     1       ; must tell host about NMRA buffer state
 flags          res     1       ; miscellaneous state flags
+flags_polarising       equ 6
 
 t              res     1       ; general temporary
 u              res     1       ; general temporary (another)