summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--software/ttx/ttx.asm132
1 files changed, 97 insertions, 35 deletions
diff --git a/software/ttx/ttx.asm b/software/ttx/ttx.asm
index 9d209a8..2fe0268 100644
--- a/software/ttx/ttx.asm
+++ b/software/ttx/ttx.asm
@@ -43,7 +43,7 @@ DASH_DEF EQU .256 - .63 ; .87
WSPACE_DEF EQU .256 - .147 ; .203
TUNE_DEF EQU DOT_DEF
BCONINT_DEF EQU .42
-START_CHAR EQU 'A'
+START_CHAR EQU 'N'
ACK_CHAR EQU 'A'
OSC_LOW EQU b'00000000'
OSC_HIGH EQU b'01100000'
@@ -65,12 +65,18 @@ PENTLE0 EQU H'0045'
PENTLE1 EQU H'0046'
PENTLECNT EQU H'0047'
ACK_DATA EQU H'0048'
+TMP1 EQU H'0049'
+TMP2 EQU H'004A'
+
+RX_STATE EQU H'004B'
+RX_FSR_TMP EQU H'004C'
+RX_CSUM EQU H'004D'
+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'005F'
-RX_CNT EQU H'004E'
-RX_BYTE EQU H'004F'
-
-BUF EQU H'0050'
-
;; all pages
BEACON_INT EQU H'0070'
DOT EQU H'0071'
@@ -80,7 +86,6 @@ CSPACE EQU DASH
WSPACE EQU H'0073'
TUNE EQU H'0074'
-STATE EQU H'0079'
NVSTATE EQU H'007A'
BEACONCNTH EQU H'007B'
BEACONCNTL EQU H'007C'
@@ -91,8 +96,8 @@ STATUS_TEMP EQU H'007F'
;; bits NVSTATE
safe EQU .0
- ;; bits STATE
-rx EQU .0
+ ;; bits RX_STATE
+complete EQU .7
;; -------------------------------------
;; Reset Vector
@@ -111,33 +116,45 @@ rx EQU .0
goto tmr1_int
ext_int
bcf INTCON,INTF
- btfsc STATE,rx
+ btfsc RX_STATE,complete
goto interrupt_end
bsf STATUS,RP0
movlw OSC_HIGH
movwf OSCCON
+ ;; we are on high OSC now
bcf STATUS,RP0
- movlw .8
- movwf RX_CNT
-ext_int_clk_high
- btfss GPIO,SCLK
- goto ext_int_clk_high
- btfss GPIO,SDAT
- bcf RX_BYTE,0
- btfsc GPIO,SDAT
- bsf RX_BYTE,0
- decfsz RX_CNT,f
- goto ext_int_rx_next
- bsf STATE,rx
+ clrf RX_CSUM
+ movf FSR,w
+ movwf RX_FSR_TMP
+ movlw RX_CMD
+ movwf FSR
+ call rx_byte
+ movlw b'00001111'
+ andwf RX_CMD,w
+ movwf RX_BYTE_CNT
+ movwf RX_STATE
+ btfsc STATUS,Z
+ goto ext_int_send_csum
+ext_int_next
+ call rx_byte
+ decfsz RX_BYTE_CNT,f
+ goto ext_int_next
+
+ext_int_send_csum
+ ;; TODO: send out csum
+ movf RX_FSR_TMP,w
+ movwf FSR
+ swapf RX_CMD,w
+ andlw b'00001111'
+ movwf RX_CMD
+ bsf RX_STATE,complete
bsf STATUS,RP0
movlw OSC_LOW
movwf OSCCON
+ ;; back on low OSC
goto interrupt_end
-ext_int_rx_next
- rlf RX_BYTE,f
- goto ext_int_clk_high
-
+
tmr1_int
bcf STATUS,RP0
bcf PIR1,TMR1IF
@@ -373,7 +390,7 @@ init
bcf GPIO,CWOUT
bcf GPIO,CWENABLE
- clrf STATE
+ clrf RX_STATE
clrf NVSTATE ; TODO: read State from EEPROM
movlw .42
movwf BEACONCNTL ; TODO: read Beaconcnt from EEPROM
@@ -402,6 +419,29 @@ init
;; -------------------------------------
;; SUBROUTINES
+rx_byte
+ movlw .8
+ movwf RX_BIT_CNT
+rx_byte_clk_high
+ btfss GPIO,SCLK
+ goto rx_byte_clk_high
+ btfss GPIO,SDAT
+ bcf INDF,0
+ btfsc GPIO,SDAT
+ bsf INDF,0
+ decfsz RX_BIT_CNT,f
+ goto rx_byte_next
+
+ movf INDF,w
+ xorwf RX_CSUM,f
+ incf FSR,f
+ return
+
+rx_byte_next
+ rlf INDF,f
+ goto rx_byte_clk_high
+
+ ;; -------------------------------------
dottime
movwf TMR0
bcf INTCON,T0IF
@@ -607,10 +647,10 @@ caseend
;; -------------------------------------
send_cnt
rlf BEACONCNTL,w
- movwf BUF+1
+ movwf TMP2
rlf BEACONCNTH,w
- movwf BUF
- movlw BUF
+ movwf TMP1
+ movlw TMP1
movwf FSR
movlw .3
call send_base32
@@ -674,15 +714,38 @@ send_ack
movlw ACK_CHAR
call send_char
- movf CSPACE,w
+ movf WSPACE,w
call dottime
- movf ACK_DATA,w
+ movf RX_CMD,w
+ addlw 'A'
call send_char
+ movf WSPACE,w
+ call dottime
+
+ movlw RX_CMD
+ movwf FSR
+ movf RX_STATE,w
+ andlw b'00001111'
+ movwf TMP1
+ btfsc STATUS,Z
+ goto ack_parity
+ack_next
+ incf FSR,f
+ movf INDF,w
+ call send_char
+ movf CSPACE,w
+ call dottime
+ decfsz TMP1,f
+ goto ack_next
+
+ ;; movf ACK_DATA,w
+ ;; call send_char
movf CSPACE,w
call dottime
+ack_parity
call send_parity
bcf GPIO,CWENABLE
@@ -696,7 +759,7 @@ main
movf SECCNT,f
btfsc STATUS,Z
goto seccnt_zero
- btfsc STATE,rx
+ btfsc RX_STATE,complete
goto byte_received
goto powerdown
@@ -709,9 +772,8 @@ seccnt_zero
;; this gets called whenver a byte was received from ihu
byte_received
- movf RX_BYTE,w
- bcf STATE,rx
call send_ack
+ clrf RX_STATE
powerdown
sleep