chiark / gitweb /
major overhaul of i2c slave to not watch for end of transactions
authorian <ian>
Tue, 20 Dec 2005 14:10:29 +0000 (14:10 +0000)
committerian <ian>
Tue, 20 Dec 2005 14:10:29 +0000 (14:10 +0000)
detpic/Makefile
detpic/common.inc
detpic/detect.asm
detpic/i2clib.asm
detpic/i2clib.inc
detpic/i2clib.incm [new file with mode: 0644]
detpic/morse.messages
detpic/slave.asm

index 6a05a0a095987844e0084af8759614b35c0e23be..db272fbef0c3069b867aaae3dbd339af35ae35c4 100644 (file)
@@ -9,21 +9,25 @@ OBJS_program=         vectors.o panic.o routines-led.o i2clib.o       \
 XCODEN_program=        morse
 XCODE1_program=        blank2 ours+pindata
 
-INCLUDES=      common.inc                      \
+INCLUDES=                                      \
+               ../iwjpictest/clockvaries.inc   \
+               common.inc                      \
+               detect.inc                      \
                final.inc                       \
                i2clib.inc                      \
+               i2clib.incm                     \
+               master.inc                      \
                misc.fin                        \
+               nmra-stream.fin                 \
                panic.fin                       \
                panic.inc                       \
-               routines-led.fin                \
-               ../iwjpictest/clockvaries.inc   \
-               vectors.fin                     \
-               program+clocks.inc              \
                pindata.inc                     \
-               detect.inc                      \
                points.fin                      \
+               program+clocks.inc              \
                program.fin                     \
-               reverse.fin
+               reverse.fin                     \
+               routines-led.fin                \
+               vectors.fin                     \
 
 VARSFILES=     variables
 
index 9e2dc310470f751dd7c35fc646794e285bb5344b..5deed7520107aad0f8bd05e364580c464fc678fd 100644 (file)
@@ -15,6 +15,7 @@ clock equ -1
        include         variables+vars.inc
        include         pindata.inc
        include         program+clocks.inc
+       include         i2clib.incm
 
 ;----------------------------------------------------------------------
 ; Common conventions for function register notation:
index f3ed1ca41e4f9eed345fda3bec927a01d7f61881..9b28b1641e73d1a4f27c7124cbc4ab09fb8b81f4 100644 (file)
@@ -153,6 +153,21 @@ slave_add_short_message
        intrh_unmask
        return
 
+;----------
+backgroundloop_again macro backgroundloop_whatever
+ local branchposition
+       inc_f_ifnz unattendedl
+       bra     backgroundloop_whatever
+       mov_lw  branchposition - backgroundloop_whatever
+branchposition
+       add_wff unattendedh
+       bra_nc  backgroundloop_whatever
+       inc_f_ifz unattendedu
+       call    led_red
+       bra     backgroundloop_whatever
+       endm
+
+near_i2csu_section code
 ;----------
 i2csu_read_begin
 ; called from High ISR, see i2clib.inc
@@ -168,27 +183,13 @@ i2csu_read_another
        bt_f_if1 picno,picno_panicd
        bra     i2csu_read_another_panicd
        mov_fw  POSTINC2
-       call    i2cs_read_data
+       i2cs_read_data_macro
        mov_fw  outmsg_end
        cmp_fw_ifle FSR2L
        return
        ; oops
        panic   morse_DR
 
-;----------
-backgroundloop_again macro backgroundloop_whatever
- local branchposition
-       inc_f_ifnz unattendedl
-       bra     backgroundloop_whatever
-       mov_lw  branchposition - backgroundloop_whatever
-branchposition
-       add_wff unattendedh
-       bra_nc  backgroundloop_whatever
-       inc_f_ifz unattendedu
-       call    led_red
-       bra     backgroundloop_whatever
-       endm
-
 ;======================================================================
 ; main detection bit-twiddling
 
@@ -277,7 +278,7 @@ i2csu_read_begin_detectors
        and_lw  0x4f    ; W     zz 05 zz zz  10 13 16 08
        ior_wfw buf0    ; W     MM 05 B2 B1  10 13 16 08
 
-       call    i2cs_read_data
+       i2cs_read_data_macro
 
        rcall   new_i2c_outmsg
 
index f8091de5e8c21f583c5381f3b49840c473a35e71..c711bad3747a76374d63ba4e4d9c4d839906cbcd 100644 (file)
@@ -11,6 +11,7 @@ clock equ 0
  include ../iwjpictest/clockvaries.inc
  include panic.inc
  include morse+auto.inc
+ include i2clib.incm
 
 ;======================================================================
 ; NOTATION
@@ -416,19 +417,20 @@ init_enable
                return
 
 ;========================================
-; SLAVE - INTERRUPT HANDLING
-
+; SLAVE
+;
 ; In general, we figure out our state and then see what kind of events
 ; we were expecting.  Bits we want to check:
-;      80    60    20    10            08    04    02    01
+;      80    40    20    10            08    04    02    01
 ;      SMP   CKE   D_A   P             S     R_W   UA    BF
 ;      set   clr   data? stop          start read? clr   full?
 ; (we don't usually mention SMP, CKE and UA below)
-
+;
 ; Labels of the form s_event_* are branches of the interrupt
 ; handler and are supposed to finish with return.
 
-; Some macros:
+;----------
+; Macros: chkvals_start and chkval
 
 chkvals_start macro what
                mov_fw  what
@@ -439,144 +441,64 @@ chkval macro lastval, value, label
                bra_z   label
                endm
 
-chkvals_addrrecv macro lastval
-       chkval  lastval, 0x8c, s_event_idle_addrrecvread ; A,!P, S,R,!BF
-       chkval  0x8c,    0x89, s_event_idle_addrrecvwrite ; A,!P, S,W,BF
-       endm
-chkvals_addrrecv_lastval equ 0x89
+near_i2csu_section code
 
 ;----------
-i2cs_interrupt ; 4cy interrupt latency + 3cy until branch to here
-               bt_f_if0 PIR1, SSPIF
-               bra     s_event_bad_intr
-               ; We have an interrupt:
-
-; Firstly, clear the interrupt flag so that if something else happens
-; while we faff, the interrupt will be regenerated:
-               bc_f    PIR1, SSPIF
-
-               mov_ff  st, st_orig
-
-               mov_lw  (1<<WCOL) | (1<<SSPOV)
-               and_wfw SSPCON1
-               bra_nz  s_event_bad
-
-               ; 8cy from entry to here, so total of 15cy
-               bt_f_if1 st, st_reading
-               bra     s_event_reading ; 18cy to 1st insn of event_reading
-
-               bt_f_if1 st, st_writing
-               bra     s_event_writing
-
-s_event_idle
-               chkvals_start SSPSTAT
-               chkvals_addrrecv 0 ; 23cy to 1st insn of addrrecvread
-s_event_bad
-               i2cpanic morse_SS ; slave, interrupt, controller in bad state
-
-s_event_bad_intr
-               i2cpanic morse_IH ; unknown high-priority interrupt
+s_write_slurpbyte macro
+;      W               any                     byte from master
+;      i2c controller  waiting due to SEN etc  continuing with next byte
+               mov_fw  SSPBUF
+               bs_f    SSPCON1, CKP
+               endm
 
-;========================================
-; SLAVE - READING
+;----------------------------------------
+i2cs_read_data
+               i2cs_read_data_macro
+               return
 
-;----------
-s_event_idle_addrrecvread
-               bs_f    st, st_awaiting
-               goto    i2csu_read_begin ; 26cy until 1st insn of read_begin
+;----------------------------------------
+; branches from the ISR
 
 ;----------
-s_event_reading
-               bs_f    st, st_awaiting ; (probably)
-
-               mov_fw  SSPSTAT
-               xor_lw  0xac ; D,!P, S,R,!BF
-               bra_nz  s_event_reading_not_another
-               goto    i2csu_read_another
-                               ; 24cy until 1st insn of i2csu_read_another
+s_event_addrrecvwrite
+               s_write_slurpbyte
+               goto    i2csu_write_begin
 
 ;----------
 s_event_reading_datanack
                return
 
 ;----------
-s_event_reading_not_another
-               ; Whatever is happening, we're done reading now !
-               clr_f   st
-               call    i2csu_read_done
-
-               chkvals_start SSPSTAT
-               chkval  0, 0xa8, s_event_reading_datanack ; D,!P, S,!R,!BF
-               ; Or, maybe it was nack and then we were reselected:
-               chkvals_addrrecv 0xa8
-
-               bra     s_event_bad
-
-;----------
-i2cs_read_data
-;      W               byte for master         any
-;      State           Transmit-Wait           Transmit-Busy
-               mov_wf  SSPBUF
-               bs_f    SSPCON1, CKP
-               
-               bt_f_if0 st, st_awaiting
-               bra     improper_read_done_data
-               bc_f    st, st_awaiting
-               bs_f    st, st_reading
-               return
-
-;========================================
-; SLAVE - WRITING
-
-;----------
-s_event_idle_addrrecvwrite
-               bs_f    SSPCON1, 3 ; we'll need the Stop interrupt
-               bs_f    st, st_writing
-               ; well, this is all fine so far, so do carry on:
-
-s_write_slurpbyte
-;      W               any                     byte from master
-;      i2c controller  waiting due to SEN etc  continuing with next byte
-               mov_fw  SSPBUF
-               bs_f    SSPCON1, CKP
-               return
+s_event_writing_datarecv
+               s_write_slurpbyte
+               goto    i2csu_write_data
 
 ;----------
-s_event_writing
-               chkvals_start SSPSTAT
-               chkval  0, 0xa9, s_event_writing_datarecv ; D,!P, S,W,BF
-
-               ; Well, we're done writing now in any case
-               clr_f   st
-               bc_f    SSPCON1, 3 ; no Start and Stop interrupts any more
-               call    i2csu_write_done
-
-               ; Who knows what might have happened.  We may have
-               ; missed a number of S and P due to delay between
-               ; clearing SSPIF and SSPM3(s&p-intrs) so we can't be
-               ; too picky.
+s_event_bad_intr
+               i2cpanic morse_IH ; unknown high-priority interrupt
 
-               ; First, the nice cases:
-               chkvals_start SSPSTAT
-               chkvals_addrrecv 0
+;----------------------------------------
+i2cs_interrupt ; 4cy interrupt latency + 3cy until branch to here
+               bt_f_if0 PIR1, SSPIF
+               bra     s_event_bad_intr
+               ; We have an interrupt:
 
-               ; Then random junk:
-               mov_fw  SSPSTAT
-               and_lw  0xc7 ; ?D_A, ?P; ?S
-               xor_lw  0x80 ; SMP, !CKE, !R_W, !UA, !BF
+               mov_lw  (1<<WCOL) | (1<<SSPOV)
+               and_wfw SSPCON1
                bra_nz  s_event_bad
-               return
 
-;----------
-s_event_writing_datarecv
-               rcall   s_write_slurpbyte
-
-               bt_f_if1 st, st_subsequent
-               goto    i2csu_write_another
-
-               bs_f    st, st_subsequent
-               goto    i2csu_write_begin
+; Firstly, clear the interrupt flag so that if something else happens
+; while we faff, the interrupt will be regenerated:
+               bc_f    PIR1, SSPIF
 
+               chkvals_start SSPSTAT
+               chkval  0,   0x8c, i2csu_read_begin             ;A,!P, S,R,!BF
+               chkval  0x8c,0xac, i2csu_read_another           ;D,!P, S,R,!BF
+               chkval  0xac,0x89, s_event_addrrecvwrite        ;A,!P, S,W,BF
+               chkval  0x89,0xa9, s_event_writing_datarecv     ;D,!P, S,W,BF
+               chkval  0xa9,0xa8, s_event_reading_datanack     ;D,!P, S,!R,!BF
+s_event_bad
+               i2cpanic morse_SS
 
 ;======================================================================
 
index b699626e30ba5bed27d9e9c240a207ee1144666d..f05f2e62dfb23659bd1a4351f920a76f132c4869 100644 (file)
 ;                   [Not-in-use]
 ;                       |
 ;                       |init
-;                       v
-;                      [Idle]<-------------------------.
-;           write_begin/    \                          |
-;                    /      \read_begin               |
-;                   V        V                        |
-;        ,->[Receiving]     [Transmit-Wait]<-.         |
-;               `-----'     |        |              |         |
-;    write_another   |        |read_data     |         |
-;                   |        V              |         |
-;                   |      [Transmit-Busy]  |         |
-;                   |        |       `------'         |
-;                   |        |        read_another    |
-;                   |        |                        |
-;                   |        |read_done               |
-;          write_done|        \                        |
-;                   `---------+->---------------------'
+;                       |
+;                       V
+;                      [Idle]
+;                       |
+;                       |<----------------------------.
+;                               +                             |
+;                       / \                           |
+;                      /   \                          |
+;          write_begin/     \read_begin                |
+;                    /       \                         |
+;                   V         V                        |
+;       ,->[Receiving]      [Transmit-Wait]<-.         |
+;       `-----'     |         |              |         |
+;     write_data    |         |read_data     |         |
+;                   |         V              |         |
+;                   |       [Transmit-Busy]  |         |
+;                   |         |       `------'         |
+;                   |         |        read_another    |
+;                   |         \                        |
+;                   `----------+->---------------------'
 
 ;========================================
 ; SLAVE - WRITES (ie, reception of data from the master)
  extern i2csu_write_begin
 ;
 ; Called to notify the main program that the master PIC has selected this
-; slave to talk to, for writing.  Provides the first byte of data
-; we received from the master PIC.
+; slave to talk to, for writing.  There is no data at this stage; when
+; data is received, i2csu_write_data will be called.
 ;
 ;              Beforehand      At call                 On return
 ;   State      Idle            Receiving               Receiving
-;   W                          data from master        any
 
 ;--------------------
- extern i2csu_write_another
+ extern i2csu_write_data
 ;
-; Called to notify the main program that the master PIC has continued
-; by transmitting another byte of data.  Provides the byte we received.
+; Called to notify the main program that the master PIC has
+; transmitted a byte of data.  Provides the byte we received.
 ;
 ;              Beforehand      At call                 On return
 ;   State      Receiving       Receiving               Receiving
 ;   W                          data from master        any
 
-;--------------------
- extern i2csu_write_done
-;
-; Called to notify the main program that the master PIC has stopped
-; transmitting data (ie, finished the i2c conversation).
-;
-;              Beforehand      At call                 On return
-;   State      Receiving       Idle
-
 ;========================================
 ; SLAVE - READS (ie, transmission of data to the master)
 
  extern i2csu_read_begin
 ;
 ; Called to notify the main program that the master PIC has selected
-; this slave to talk to, for reading.  The main program should call
+; this slave to talk to, for reading.  The main program should invoke
 ; i2cs_read_data with first byte of data that we should transmit to
 ; the master.
 ;
 ;              Beforehand      At call
 ;   State      Idle            Transmit-Wait
 
-
 ;--------------------
  extern i2cs_read_data
 ; Transmits the byte of data to the master
 ;              Beforehand      At call                 On return
 ;   State      Transmit-Wait   Transmit-Busy           Transmit-Busy
 ;   W                          byte for master         any
+;
+; There is also a macro  i2cs_read_data_macro
+; in i2clib.incm, which does the same thing.
 
 ;--------------------
  extern i2csu_read_another
 ;
 ; Called to notify the main program that the master PIC has continued
 ; by asking for another byte of data.  The main program should once
-; more call i2cs_read_data.
+; more invoke i2cs_read_data.
 ;
 ;              Beforehand      At call
 ;   State      Transmit-Busy   Transmit-Wait
-
-;--------------------
- extern i2csu_read_done
-;
-; Called to notify the main program that the master PIC has stopped
-; asking for data (ie, finished receiving).
-;
-;              Beforehand      At call                 On return
-;   State      Transmit-Busy   Idle
diff --git a/detpic/i2clib.incm b/detpic/i2clib.incm
new file mode 100644 (file)
index 0000000..344e217
--- /dev/null
@@ -0,0 +1,9 @@
+;======================================================================
+; MACROS FOR I2CLIB USERS
+; see i2clib.inc
+
+;--------------------
+i2cs_read_data_macro macro
+               mov_wf  SSPBUF
+               bs_f    SSPCON1, CKP
+               endm
index 34c15e4cc56df89fc52bf51afa61ec1d088da486..9a23460a3944ec8172e3ece1e904933ec8e9a5a7 100644 (file)
@@ -48,7 +48,7 @@ UE
 
 # Messages for i2clib, S*
 SM     i2clib:st,:sspstat,:sspcon1,:sspcon2 ; m.,i., ctrlr bad state
-SS     i2clib:st,SSPSTAT,SSPCON1,:st_orig ; s.,i., controller bad state
+SS     SSPSTAT,SSPCON1                 ; s.,i., controller bad state
 SK     i2clib:slave                    ; m. couldn't address slave (no ack)
 SN     i2clib:slave                    ; improper slave number
 SW     i2clib:st                       ; improper i2cm_write_start
index 76345f4c8f0716acb7a807d87bdfe7c426267fc5..1614b2c801dff452cec23a77343dd86ea9f92b9f 100644 (file)
@@ -31,7 +31,10 @@ slave
 
 ;----------
 i2csu_write_begin
-i2csu_write_another
+       return
+
+;----------
+i2csu_write_data
        call    led_green
 
        bt_f_if1 picno,picno_panicd
@@ -52,11 +55,6 @@ i2csu_write_if_special
        bra     i2csu_write_if_bad
        goto    panic_crashread_commanded
 
-;----------
-i2csu_read_done
-i2csu_write_done
-       return ; fixme make it not call these any more
-
 ;----------
 slave_interrupt_low
        enter_interrupt_low