chiark / gitweb /
Send HELLO as a result of all slaves being online. Do not crash if slave is slow...
[trains.git] / detpic / program.asm
index 1638d7676c6d12b01cd11198e8b76edaa0cc0ea6..48ae077e9effc7e915cebea8baf1e439f95dd93b 100644 (file)
@@ -1,27 +1,14 @@
 ;======================================================================
 ; MAIN PROGRAM AND GLUE
 
- include common.inc
- code
 include common.inc
 code
 
 ;======================================================================
 ; COMMON TO MASTER AND SLAVE
 
 ;----------------------------------------
-vector_reset
-
- set_f qqTRISA
- set_f qqTRISB
- set_f qqTRISC
- set_f qqTRISD
- set_f qqTRISE
- mov_lw 0xaa
- mov_wf qqLATA
- mov_wf qqLATB
- mov_wf qqLATC
- mov_wf qqLATD
- mov_wf qqLATE
-
+vector_reset @
        clr_f   INTCON
        bs_f    RCON, IPEN      ; interrupt priorities
 
@@ -36,6 +23,8 @@ vector_reset
        bs_f    INTCON, GIEH
        bs_f    INTCON, GIEL
 
+       bt_f_if1 idloc1,idloc1_master
+       goto    backgroundloop_master
        bt_f_if1 idloc1,idloc1_boarddet
        goto    backgroundloop_detectors
        goto    backgroundloop_reversers
@@ -52,10 +41,13 @@ common_local_init
        return
 
 ;----------------------------------------
-panic_kill_hook
+panic_kill_hook @
+       call    power_panichook
+       call    cdu_panichook
+       return
 
 ;----------
-intrl_handled_routine
+intrl_handled_routine @
        mov_ff  isr_low_save_stkptr, STKPTR
        intrl_handled_core
 
@@ -65,46 +57,79 @@ intrl_handled_routine
 ;----------------------------------------
 master_init
 ; Master-specific initialisation.
+       call    memory_erase
+       clr_f   flags
+       call    serial_init
        call    i2cm_init
+       call    serialtxbuf_init
+       call    polarity_master_init
+       call    points_master_init
        call    common_local_init
-       call    serial_init
        call    nmra_init
+       call    serialtxfc_init
+       call    mascan_init
+       call    tick_init
+       call    cdu_init
+       call    power_polarising_init
+       call    power_fault_init
+       call    watchdog_init
+       call    i2c_consider_restartread ; sends hello when all slaves ack'd
        return
 
 ;----------------------------------------
-master_interrupt_low
+master_interrupt_low @
        enter_interrupt_low
-       ;call   ticker_intrl
+       Dl 0x80
+       Df      INTCON
+       Df      INTCON2
+       Df      INTCON3
+       Df      PIR1
+       Df      PIR2
+       Df      PIR3
+       Dl 0x8d
+       call    tick_intrl
        call    nmra_serialrx_intrl
-       ;call   serialtx_intrl
-       ;call   points_local_intrl
-       ;call   i2cm_intrl
+       call    power_fault_intrl
+       call    serialtxfc_intrl
+       call    serialtx_intrl
+       call    points_local_intrl
+       call    i2cm_intrl
+       Dl 0x8e
+       Df      INTCON
+       Df      INTCON2
+       Df      INTCON3
+       Df      PIR1
+       Df      PIR2
+       Df      PIR3
+       Dl 0x8f
        panic   morse_IL
 
-;----------
-master_interrupt_high_notnmra
-       panic   morse_IH
-
 ;----------------------------------------------------------------------
 serialrx_table_section code    0x2000
 
 ;--------------------
-serialrx_generalmsg
+command_tellmode
+       mov_lw  0x09
+       goto    serial_addbyte
+
+;--------------------
+serialrx_generalmsg @
 ;command_<something>  has same calling convention:
 ;
 ;  FSR0 ->     start of message                undefined
 ;  *FSR0       message                         undefined
 ;
-;                              ; INDF0=MM ww ww ww ww ii ii ii
-       rlc_fw  INDF0           ; W =   ww ww ww ww ii ii ii ??  C=MM Z=00
-       bra_c   serialrx_if_multibyte
+       mov_fw  INDF0
+       bra_n   serialrx_if_multibyte
        bra_z   command_crashed
-       ; single-byte non-0 command, has to be ON or OFF
-       ;       ie supposedly   ; INDF0=zz zz II zz zz zz zz PP  C=zz
-       rrc_fw  INDF0           ; W =   zz zz zz II zz zz zz zz  C=PP
-       xor_lw  0x10            ; W =   zz zz zz zz zz zz zz zz  C=PP Z=OK
-       bra_n   serialrx_bad
-       goto    command_power
+
+       xor_lw  0x11
+       bra_z   command_power_on
+       xor_lw  0x10 ^ 0x11
+       bra_z   command_power_off
+       xor_lw  0x0a ^ 0x10
+       bra_z   command_tellmode
+       bra     serialrx_bad
 
 ;-----
 serialrx_if_multibyte
@@ -114,10 +139,10 @@ serialrx_if_multibyte
        add_wff PCL
        ; <--- here is zero
 
-               goto    serialrx_bad            ; 1 0000 xxx
+               goto    serialrx_bad            ; 1 0000 xxx
        goto    command_ping            ; 1 0001 xxx
        goto    command_polarity        ; 1 0010 xxx
-       goto    serialrx_bad            ; 1 0011 xxx
+       goto    command_watchdog        ; 1 0011 xxx
        goto    command_point           ; 1 0100 xxx
        goto    serialrx_bad            ; 1 0101 xxx
        goto    serialrx_bad            ; 1 0110 xxx
@@ -131,41 +156,22 @@ serialrx_if_multibyte
        goto    serialrx_bad            ; 1 1110 xxx
        goto    serialrx_bad            ; 1 1111 xxx
 
-       goto    serialrx_bad    ; 0 0000 xxx
-       goto    serialrx_bad    ; 0 0001 xxx
-       goto    serialrx_bad    ; 0 0000 xxx
-
 ;-----
 serialrx_bad
        mov_ff  INDF0, t
        panic   morse_HX
 
-;      bra_z   crashed_master_do
-;      mov_fw  INDF0
-;      bra_z   crashed_master_do
-; 
-;      serialrx_check 0x00, 0x21, command_power_on
-;      serialrx_check 0x21, 0x20, command_power_off
-; 
-;      and_lw  0xf8            ; W^0x20 =      MM ww ww ww  ww zz zz zz
-; 
-;      serialrx_check 0x00, 0xa0, point_master_do
-;      serialrx_check 0xa0, 0x88, ping_master_do
-;      serialrx_check 0x88, 0x90, polarity_master_do
-; 
-;      serialrx_check 0x90, 0x90, polarity_master_do
-; 
-;      mov_wf  t               ; t =           MM ww ww ww  ww zz zz zz
-; 
-;      xor_lw  0x
-; 
-;      and_lw
-
+code2 code
 ;--------------------
 command_ping
-command_point
-command_crashed
-       panic   morse_UC
+       mov_fw  POSTINC0
+       mov_ff  INDF0, t
+       call    serial_addbyte
+       mov_fw  t
+       bra_n   command_ping_bad
+       goto    serial_addbyte_another
+
+command_ping_bad panic morse_HP
 
 ;======================================================================
 ; SLAVE
@@ -173,6 +179,8 @@ command_crashed
 ;----------------------------------------
 slave_init
 ; Slave-specific initialisation.
+       clr_f   flags
+
        mov_fw  picno
        call    i2cs_init
 
@@ -183,7 +191,7 @@ slave_init
        return
 
 ;----------------------------------------
-slave_interrupt_low
+slave_interrupt_low @
        enter_interrupt_low
        call    points_local_intrl
        panic   morse_IL
@@ -197,9 +205,6 @@ near_local_do code
 i2csu_write_data
        call    led_green
 
-       bt_f_if1 picno,picno_panicd
-       goto    i2csu_write_panicd
-
        bt_w_if0 7
        bra     i2csu_write_if_special
        bt_w_if1 6
@@ -215,12 +220,12 @@ i2csu_write_if_special
        bra     i2csu_write_if_bad
        goto    panic_crashread_commanded
 
-code2 code
+code3 code
 ;======================================================================
 ; MASTER/SLAVE deviations
 
 ;----------
-message_for_master
+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
@@ -230,4 +235,4 @@ message_for_master
        goto    loopback_read_byte
 
 ;======================================================================
- include final.inc
 include final.inc