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 c83bc2a12b7b46e52e2dcc104bbe6b111aff17aa..48ae077e9effc7e915cebea8baf1e439f95dd93b 100644 (file)
@@ -8,25 +8,11 @@
 ; 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
 
        call    idlocs_init
-       clr_f   flags
 
        bt_f_if0 idloc1,idloc1_master
        call    slave_init
@@ -55,13 +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
 
@@ -71,6 +57,8 @@ intrl_handled_routine
 ;----------------------------------------
 master_init
 ; Master-specific initialisation.
+       call    memory_erase
+       clr_f   flags
        call    serial_init
        call    i2cm_init
        call    serialtxbuf_init
@@ -81,19 +69,24 @@ master_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
- mov_ff INTCON, xdebug+0
- mov_ff INTCON2, xdebug+1
- mov_ff INTCON3, xdebug+2
- mov_ff PIR1, xdebug+3
- mov_ff PIR2, xdebug+4
- mov_ff PIR3, xdebug+5
+       Dl 0x80
+       Df      INTCON
+       Df      INTCON2
+       Df      INTCON3
+       Df      PIR1
+       Df      PIR2
+       Df      PIR3
+       Dl 0x8d
        call    tick_intrl
        call    nmra_serialrx_intrl
        call    power_fault_intrl
@@ -101,28 +94,42 @@ master_interrupt_low
        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
 
 ;----------------------------------------------------------------------
 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
@@ -135,7 +142,7 @@ serialrx_if_multibyte
                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
@@ -149,15 +156,12 @@ 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
 
+code2 code
 ;--------------------
 command_ping
        mov_fw  POSTINC0
@@ -169,13 +173,14 @@ command_ping
 
 command_ping_bad panic morse_HP
 
-code2 code
 ;======================================================================
 ; SLAVE
 
 ;----------------------------------------
 slave_init
 ; Slave-specific initialisation.
+       clr_f   flags
+
        mov_fw  picno
        call    i2cs_init
 
@@ -186,7 +191,7 @@ slave_init
        return
 
 ;----------------------------------------
-slave_interrupt_low
+slave_interrupt_low @
        enter_interrupt_low
        call    points_local_intrl
        panic   morse_IL
@@ -220,7 +225,7 @@ 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