chiark / gitweb /
Send HELLO as a result of all slaves being online. Do not crash if slave is slow...
[trains.git] / detpic / i2clib.asm
index e594532388740b06dd1212936d92ef0f858fb12b..09d995dbe56fcf6b69827b98ec76c71701b68525 100644 (file)
@@ -3,14 +3,14 @@
 ;
 ; See i2clib.asm for documentation of the interface to this file.
 
- include /usr/share/gputils/header/p18f458.inc
- radix dec
- include ../iwjpictest/insn-aliases.inc
 include /usr/share/gputils/header/p18f458.inc
 radix dec
 include ../iwjpictest/insn-aliases.inc
 
- include ../iwjpictest/clockvaries.inc
- include panic.inc
- include morse+auto.inc
- include i2clib.incm
 include ../iwjpictest/clockvaries.inc
 include panic.inc
 include morse+auto.inc
 include i2clib.incm
 
 ;======================================================================
 ; NOTATION
@@ -57,8 +57,8 @@
 
                udata_acs
 
-sspstat                res     1
-sspcon1                res     1
+sspstat                res     1       ; master only
+sspcon1                res     1       ; master only
 sspcon2                res     1       ; master only
 slave          res     1       ; master only
 slave_next     res     1       ; master only
@@ -170,13 +170,20 @@ m_start
 ;      slave                   any                     slave_number
 ; expects to return directly to main program (caller)
                mov_wf  slave
-               bra_z   m_improper_slave
                bs_f    SSPCON2, SEN
 m_start_or_restart
                and_lw  ~31
                bra_nz  m_improper_slave
                bs_f    st, st_starting
+               tst_f_ifnz slave
                return
+               ; oops:
+;...
+
+m_improper_slave
+;      slave                   slave number
+               i2cpanic morse_SN
+
 
 ;----------
 m_event_done_starting
@@ -194,7 +201,7 @@ m_event_done_starting
 ;----------
 m_event_done_addressing
                bt_f_if1 sspcon2, ACKSTAT
-               bra     m_bad_address_ack
+               bra     m_no_address_ack
                ; OK, we got ack.
 
                bc_f    st, st_addressing
@@ -217,13 +224,15 @@ m_event_done_stopping
                goto    i2cmu_done
 
 ;----------
-m_bad_address_ack
-               i2cpanic morse_SK
+m_no_address_ack
+               bt_f_if0 st, st_reading
+               bra     m_bad_no_address_ack_write
+               clr_f   st
+               rcall   m_stop
+               goto    i2cmu_slave_no_ack
 
-;----------
-m_improper_slave
-;      slave                   slave number
-               i2cpanic morse_SN
+m_bad_no_address_ack_write
+               panic   morse_SW
 
 ;========================================
 ; MASTER - WRITING
@@ -295,8 +304,9 @@ m_read_start_busy
 m_address_different
 ; Main program would like to address another slave for reading.
                mov_wf  slave_next
-               bra_z   m_improper_slave
+               tst_f_ifnz slave_next
                bra     i2cm_read_done
+               panic   morse_SO                
 
 ;----------
 m_event_done_addressing_read
@@ -401,8 +411,8 @@ init_enable
                set_f   sspcon1
                set_f   sspcon2
                set_f   st_orig
-               bs_f    TRISB, 0
-               bs_f    TRISB, 1
+               bs_f    TRISC, 3
+               bs_f    TRISC, 4
                bs_f    SSPCON1, SSPEN
                bs_f    PIE1, SSPIE
                return
@@ -423,13 +433,13 @@ init_enable
 ;----------
 ; Macros: chkvals_start and chkval
 
-chkvals_start macro what
-               mov_fw  what
+chkvals_start macro chvals_what
+               mov_fw  chvals_what
                endm
 
-chkval macro lastval, value, label
-               xor_lw  value ^ lastval
-               bra_z   label
+chkval macro chkval_lastval, chkval_value, chkval_label
+               xor_lw  chkval_value ^ chkval_lastval
+               bra_z   chkval_label
                endm
 
 near_i2csu code
@@ -493,7 +503,7 @@ s_event_bad
 
 ;======================================================================
 
include panic.fin
- include i2clib.inc
 include program+externs.fin
 include i2clib.inc
 
- end
 end