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 ed70623894d8717b6bd8fcbe811697833e4c6b57..09d995dbe56fcf6b69827b98ec76c71701b68525 100644 (file)
@@ -3,16 +3,15 @@
 ;
 ; 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
 
- include common.inc
 ;======================================================================
 ; NOTATION
 
@@ -113,13 +112,11 @@ i2cm_init
 
 ;----------
 i2cm_interrupt
- D 0x50 ;!P
                bt_f_if0 PIR1, SSPIF
                return
                ; We have an interrupt:
 ;...
 i2cm_interrupt_definite
- D 0x51 ;!P
                mov_ff  SSPSTAT, sspstat
                mov_ff  SSPCON1, sspcon1
                mov_ff  SSPCON2, sspcon2
@@ -130,12 +127,8 @@ i2cm_interrupt_definite
                and_wfw sspcon1
                bra_nz  m_event_bad
 
- mov_fw st ;!P
- call debugbyte ;!P
-
                ; No ?  Well, then the I2C should be idle now:
                mov_fw  sspcon2
- call debugbyte ;!P
                and_lw  ~((1<<ACKSTAT) | (1<<ACKDT)) ; those two are ok if set
                bra_nz  m_event_bad
                ; OK...
@@ -208,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
@@ -231,8 +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_bad_no_address_ack_write
+               panic   morse_SW
 
 ;========================================
 ; MASTER - WRITING
@@ -506,6 +506,4 @@ s_event_bad
   include program+externs.fin
   include i2clib.inc
 
- include variables+vars.fin
-
   end