;====================================================================== ; MAIN PROGRAM AND GLUE 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 clr_f INTCON bs_f RCON, IPEN ; interrupt priorities call idlocs_init bt_f_if0 idloc1,idloc1_master call slave_init bt_f_if1 idloc1,idloc1_master call master_init bs_f INTCON, GIEH bs_f INTCON, GIEL bt_f_if1 idloc1,idloc1_boarddet goto backgroundloop_detectors goto backgroundloop_reversers ;---------- common_local_init ; called by {master,slave}_init immediately after they've init'd i2c. clr_f PCLATU call bitnum2bit_init call points_local_init call polarity_local_init call detect_local_init return ;---------------------------------------- panic_kill_hook ;---------- intrl_handled_routine mov_ff isr_low_save_stkptr, STKPTR intrl_handled_core ;====================================================================== ; MASTER ;---------------------------------------- master_init ; Master-specific initialisation. call i2cm_init call polarity_master_init call common_local_init call serial_init call nmra_init call mascan_init return ;---------------------------------------- master_interrupt_low enter_interrupt_low ;call ticker_intrl call nmra_serialrx_intrl ;call serialtx_intrl ;call points_local_intrl ;call i2cm_intrl panic morse_IL ;---------- master_interrupt_high_notnmra panic morse_IH ;---------------------------------------------------------------------- serialrx_table_section code 0x2000 ;-------------------- serialrx_generalmsg ;command_ 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 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 ;----- serialrx_if_multibyte rr_fw INDF0 ; W = ii MM ww ww ww ww ii ii and_lw 0x3c ; W = zz zz ww ww ww ww zz zz bt_f_if0 PCL, 0 ; always true, but reads PCL add_wff PCL ; <--- here is zero 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_point ; 1 0100 xxx goto serialrx_bad ; 1 0101 xxx goto serialrx_bad ; 1 0110 xxx goto serialrx_bad ; 1 0111 xxx goto serialrx_bad ; 1 1000 xxx goto serialrx_bad ; 1 1001 xxx goto serialrx_bad ; 1 1010 xxx goto serialrx_bad ; 1 1011 xxx goto serialrx_bad ; 1 1100 xxx goto serialrx_bad ; 1 1101 xxx 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 ;-------------------- command_ping command_point command_crashed panic morse_UC ;====================================================================== ; SLAVE ;---------------------------------------- slave_init ; Slave-specific initialisation. mov_fw picno call i2cs_init bc_f T0CON, TMR0ON call common_local_init call detect_slave_init return ;---------------------------------------- slave_interrupt_low enter_interrupt_low call points_local_intrl panic morse_IL ;---------------------------------------- i2csu_write_begin return near_local_do code ;---------------------------------------- i2csu_write_data call led_green bt_w_if0 7 bra i2csu_write_if_special bt_w_if1 6 bra polarity_local_do bt_w_if0 5 bra point_local_do i2csu_write_if_bad mov_wf t panic morse_DX i2csu_write_if_special tst_w_ifnz bra i2csu_write_if_bad goto panic_crashread_commanded code2 code ;====================================================================== ; MASTER/SLAVE deviations ;---------- 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 ; GIEH set set bt_f_if0 idloc1,idloc1_master goto slave_add_short_message goto loopback_read_byte ;====================================================================== include final.inc