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 4e278608a21a8094a5bcc3cea5c1e336b2c6cab6..09d995dbe56fcf6b69827b98ec76c71701b68525 100644 (file)
@@ -3,15 +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
 
-clock equ 0
- 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
@@ -58,8 +57,8 @@ clock equ 0
 
                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
@@ -81,13 +80,6 @@ st_stopping  equ 0 ; Stopping
 
                code
 
-;----------
-i2cpanic macro morse_addr
-; Like panic but turns off the I2C controller
-       bc_f    SSPCON1, SSPEN
-       panic   morse_addr
-       endm
-
 ;----------
 slave2addr
 ; computes slave address in form suitable for use in i2c controller
@@ -178,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
@@ -202,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
@@ -225,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
@@ -303,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
@@ -409,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
@@ -431,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
@@ -501,7 +503,7 @@ s_event_bad
 
 ;======================================================================
 
include panic.fin
- include i2clib.inc
 include program+externs.fin
 include i2clib.inc
 
- end
 end