From: ian Date: Tue, 27 Dec 2005 17:15:35 +0000 (+0000) Subject: new tickdiv for two speeds of tick; working on energy - polarising finished but not... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=94eff43808d38df7b7a43aa63ff4622e8ce2a806;p=trains.git new tickdiv for two speeds of tick; working on energy - polarising finished but not compiled; fault just sketched --- diff --git a/detpic/common.inc b/detpic/common.inc index a589da6..a41f791 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -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 diff --git a/detpic/energy.asm b/detpic/energy.asm index dbdebd9..dd82672 100644 --- a/detpic/energy.asm +++ b/detpic/energy.asm @@ -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 diff --git a/detpic/make-clocks b/detpic/make-clocks index 9d0bc7d..b333e2a 100755 --- a/detpic/make-clocks +++ b/detpic/make-clocks @@ -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" }; } } diff --git a/detpic/mascan.asm b/detpic/mascan.asm index 32ea43d..d59ffdd 100644 --- a/detpic/mascan.asm +++ b/detpic/mascan.asm @@ -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 diff --git a/detpic/nmra-stream.asm b/detpic/nmra-stream.asm index 259c484..e827791 100644 --- a/detpic/nmra-stream.asm +++ b/detpic/nmra-stream.asm @@ -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 diff --git a/detpic/points.asm b/detpic/points.asm index 62527b0..d2103fc 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -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 diff --git a/detpic/points.fin b/detpic/points.fin index 33ea40c..350ea50 100644 --- a/detpic/points.fin +++ b/detpic/points.fin @@ -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 diff --git a/detpic/program.asm b/detpic/program.asm index b11ed6f..73b1d12 100644 --- a/detpic/program.asm +++ b/detpic/program.asm @@ -81,6 +81,7 @@ master_init call serialtxfc_init call mascan_init call tick_init + call power_polarising_init return ;---------------------------------------- diff --git a/detpic/program.clocks b/detpic/program.clocks index 4e57f2a..3dff162 100644 --- a/detpic/program.clocks +++ b/detpic/program.clocks @@ -10,4 +10,4 @@ #morse MS T0ov16 66ms points MS T3ov 10ms -tick MS T2period 10ms +tick MS T2period 1ms diff --git a/detpic/reverse.asm b/detpic/reverse.asm index 4416c10..8dde2f4 100644 --- a/detpic/reverse.asm +++ b/detpic/reverse.asm @@ -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 diff --git a/detpic/tick.asm b/detpic/tick.asm index 9c35fb0..9ef474b 100644 --- a/detpic/tick.asm +++ b/detpic/tick.asm @@ -2,11 +2,14 @@ ; TICK - REGULAR 10MS TIMER INTERRUPT ; ; after tick_init, and after interrupts enabled, -; we call _tick every 10ms. +; we call _tick every 1ms and _tickdiv every 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 _tick here: - call cdu_tick + call power_polarising_tick + call power_fault_tick ; end of list of calls to _tick + dec_f_ifz tickdivcount + bra tickdiv_do + + intrl_handled_nostack + +;---------------------------------------- +tickdiv_do + ; add calls to _tickdiv here: + call cdu_tickdiv + ; end of list of calls to _tickdiv + + mov_lw tickdiv + mov_wf tickdiv_count intrl_handled_nostack ;---------------------------------------------------------------------- diff --git a/detpic/variables.asm b/detpic/variables.asm index 090d479..65df513 100644 --- a/detpic/variables.asm +++ b/detpic/variables.asm @@ -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)