summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2012-01-28 15:44:06 +0000
committerChristian Pointner <equinox@mur.at>2012-01-28 15:44:06 +0000
commit37b5fe39f23067e6a3fc0beb9e40457298bfcba0 (patch)
treee0258f23d934a06c87801caf3877e6ba372011bf
parentcleanup (diff)
added aknowledge pulse to ihu-ttx communication
git-svn-id: https://svn.spreadspace.org/mur.sat@239 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r--doc/protocols/ihu-ttx.txt10
-rw-r--r--software/ihu/ihu.asm72
-rw-r--r--software/ihu/ttx.inc23
-rw-r--r--software/ttx/ttx.asm12
4 files changed, 109 insertions, 8 deletions
diff --git a/doc/protocols/ihu-ttx.txt b/doc/protocols/ihu-ttx.txt
index d4fdcec..c91c479 100644
--- a/doc/protocols/ihu-ttx.txt
+++ b/doc/protocols/ihu-ttx.txt
@@ -14,6 +14,10 @@ The data is transferred MSB first in groups of 8bits (1 Octet). SDA must be
stable before the clock goes high. A Clock pulse must be at least 4µs long and
the data has to stay valid for at least 17µs. After each octet there must be a
break of 50µs.
+After the last octet, which will be a checksum generated by the slave, the master
+has to generate a single bit aknowledge. A logic low on SDA during a SCL pulse
+instructs the slave to process the received frame whereas a logic high tells the
+slave to discard all data and proceed with normal operation.
| wake up | 1st octet | break | 2nd octet
@@ -33,13 +37,16 @@ Frames
Every frame starts with 4 bit command code and a 4 bit length field. After this follow
LEN octets of data. When all the data has been transferred the master (IHU) switches
SDA to input and clocks in on byte as acknowledge. The aknowledge is a one byte XOR
-checksum over all octets (including the CMD/LEN octet).
+checksum over all octets (including the CMD/LEN octet).
Field-length: 1 LEN 1
+---------+----------------+--------+
Name | CMD/LEN | DATA | CS |
+---------+----------------+--------+
+As stated earlier a frame has only to be processed when a positive aknowledge has been
+sent by the master.
+
Commands
--------
@@ -97,3 +104,4 @@ Commands
This transmits a new format string for the standard beacon. The data is a variable
length string containing ASCII characters each standing for a beacon element to send
out.
+
diff --git a/software/ihu/ihu.asm b/software/ihu/ihu.asm
index cec3e51..c213698 100644
--- a/software/ihu/ihu.asm
+++ b/software/ihu/ihu.asm
@@ -369,6 +369,78 @@ uart_rx_fe
main
; sleep
; nop
+ ;; --------------------
+ ;; TTX Test
+ movf TMP,w
+ btfsc STATUS,Z
+ goto main
+
+ movwf BUF
+ clrf TMP
+ movlw BUF+1
+ movwf FSR
+
+ movlw .1
+ movwf TTX_BYTE_CNT
+main_read_bytes
+ movf TMP,w
+ btfsc STATUS,Z
+ goto main_read_bytes
+ movwf INDF
+ incf FSR,f
+ clrf TMP
+ decfsz TTX_BYTE_CNT,f
+ goto main_read_bytes
+
+ movlw BUF
+ movwf FSR
+ movlw 0xA2
+ call ttx_send
+
+ xorlw .0
+ btfss STATUS,Z
+ goto main_error
+
+ movlw 'O'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ movlw 'K'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ movlw '\r'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ movlw '\n'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ goto main
+
+main_error
+ movlw 'E'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ movlw 'R'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ movlw 'R'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ movlw '\r'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ movlw '\n'
+ movwf TXREG
+ movlw .1
+ call wait_ms
+ goto main
;; --------------------
;; ADC Test
diff --git a/software/ihu/ttx.inc b/software/ihu/ttx.inc
index b9f45e7..2098340 100644
--- a/software/ihu/ttx.inc
+++ b/software/ihu/ttx.inc
@@ -108,7 +108,7 @@ ttx_send_frame
movf TTX_BYTE_CNT,f
btfsc STATUS,Z
- return
+ goto ttx_get_csum
ttx_next_byte
call ttx_break
@@ -119,16 +119,31 @@ ttx_next_byte
decfsz TTX_BYTE_CNT,f
goto ttx_next_byte
+ttx_get_csum
call ttx_break
call ttx_recv_byte
movf TTX_BYTE,w
xorwf TTX_CSUM,w
btfss STATUS,Z
goto ttx_csum_error
- return
+ retlw .0
ttx_csum_error
- ;; TODO: react to comm error
- return
+ retlw .1
;; -------------------------------------
+ttx_send
+ call ttx_send_frame
+ movwf TTX_BYTE
+ call ttx_break
+ btfsc TTX_BYTE,0
+ bcf PORTD,TTX_SDA
+ btfss TTX_BYTE,0
+ bsf PORTD,TTX_SDA
+ bsf PORTD,TTX_SCL
+ nop
+ nop
+ nop
+ bcf PORTD,TTX_SCL
+ return
+ ;; -------------------------------------
diff --git a/software/ttx/ttx.asm b/software/ttx/ttx.asm
index 6e974c9..0f75420 100644
--- a/software/ttx/ttx.asm
+++ b/software/ttx/ttx.asm
@@ -76,7 +76,7 @@ RX_BIT_CNT EQU H'004E'
RX_BYTE_CNT EQU H'004F'
RX_CMD EQU H'0050'
RX_D_START EQU H'0051'
-RX_D_END EQU H'0060'
+RX_D_END EQU H'005F'
;; all pages
BEACON_INT EQU H'0070'
@@ -136,7 +136,9 @@ ext_int
movwf RX_STATE
btfsc STATUS,Z
goto ext_int_send_csum
+
ext_int_next
+ incf FSR,f
call rx_byte
decfsz RX_BYTE_CNT,f
goto ext_int_next
@@ -148,6 +150,10 @@ ext_int_send_csum
swapf RX_CMD,w
andlw b'00001111'
movwf RX_CMD
+ext_int_wait_ack
+ btfss GPIO,SCLK
+ goto ext_int_wait_ack
+ btfss GPIO,SDAT
bsf RX_STATE,complete
bsf STATUS,RP0
movlw OSC_LOW
@@ -425,7 +431,6 @@ rx_byte_clk_high
movf INDF,w
xorwf RX_CSUM,f
- incf FSR,f
return
rx_byte_next
@@ -451,7 +456,7 @@ rx_send_clk_high
bsf STATUS,RP0
bsf TRISIO,SDAT
- bcf STATUS,RP0
+ bcf STATUS,RP0
return
rx_send_next
@@ -792,6 +797,7 @@ seccnt_zero
;; this gets called whenever a message was received from ihu
msg_received
call send_ack
+ bcf RX_STATE,complete
clrf RX_STATE
powerdown